文章目录
- 一. Qt搭建海康机器人工业相机开发环境
一. Qt搭建海康机器人工业相机开发环境
-
参考这个链接安装好MVS客户端
-
Qt新建一个c++项目
-
cmakeList中添加海康机器人的库,如下:
cmake_minimum_required(VERSION 3.5)project(HIKRobotCameraTest LANGUAGES CXX)set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON)# 海康机器人库文件设置 set(MVC_DIR "C:\\Program Files (x86)\\MVS\\Development") set(MVC_INCLUDE_DIRS ${MVC_DIR}\\Includes) set(MVC_LIB_DIRS ${MVC_DIR}\\Libraries\\win64) include_directories(${MVC_INCLUDE_DIRS}) link_directories(${MVC_LIB_DIRS})add_executable(HIKRobotCameraTest main.cpp)target_link_libraries(${PROJECT_NAME} PUBLIC MvCameraControl)install(TARGETS HIKRobotCameraTestLIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
-
main.cpp中添加以下代码
#include <iostream> #include "MvCameraControl.h" #include <stdio.h> #include <Windows.h> #include <conio.h>using namespace std;bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo) {if (NULL == pstMVDevInfo){printf("The Pointer of pstMVDevInfo is NULL!\n");return false;}if (pstMVDevInfo->nTLayerType == MV_CAMERALINK_DEVICE){printf("chPortID: [%s]\n", pstMVDevInfo->SpecialInfo.stCamLInfo.chPortID);printf("chModelName: [%s]\n", pstMVDevInfo->SpecialInfo.stCamLInfo.chModelName);printf("chFamilyName: [%s]\n", pstMVDevInfo->SpecialInfo.stCamLInfo.chFamilyName);printf("chDeviceVersion: [%s]\n", pstMVDevInfo->SpecialInfo.stCamLInfo.chDeviceVersion);printf("chManufacturerName: [%s]\n", pstMVDevInfo->SpecialInfo.stCamLInfo.chManufacturerName);printf("Serial Number: [%s]\n", pstMVDevInfo->SpecialInfo.stCamLInfo.chSerialNumber);}else{printf("Not support.\n");}return true; }int main() {int nRet = MV_OK;void* handle = NULL;MV_CC_DEVICE_INFO_LIST stDeviceList;memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));nRet = MV_CC_EnumDevices(MV_CAMERALINK_DEVICE, &stDeviceList);if (MV_OK != nRet){printf("Enum Devices fail! nRet [0x%x]\n", nRet);}if (stDeviceList.nDeviceNum > 0){for (unsigned int i = 0; i < stDeviceList.nDeviceNum; i++){printf("[device %d]:\n", i);MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i];if (NULL == pDeviceInfo){}PrintDeviceInfo(pDeviceInfo);}}else{printf("Find No Devices!\n");}return 0; }
-
运行程序,出现以下内容则说明安装库成功