RMVL  1.0.0
RoboMaster Vision Library
samples/camera/hik/sample_hik_multi.cpp

海康机器人工业相机——多相机例程

#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace rm;
using namespace para;
using namespace std;
using namespace cv;
int main()
{
int ret = MV_OK;
MV_CC_DEVICE_INFO_LIST camera_list;
ret = MV_CC_EnumDevices(MV_USB_DEVICE, &camera_list);
if (ret != MV_OK)
CAM_INFO("failed to enum camera devices");
unsigned int nums = camera_list.nDeviceNum;
auto info = camera_list.pDeviceInfo;
CAM_INFO("camera quantity: %u", nums);
printf("┌──────┬──────────────┬────────────────┬─────────────────────┬────────────────┐\n");
printf("│ 索引 │ 相机序列号 │ 型号名字 │ 设备版本号 │ 通信协议 │\n");
printf("├──────┼──────────────┼────────────────┼─────────────────────┼────────────────┤\n");
unordered_map<unsigned int, string> layer_type_t;
layer_type_t[MV_UNKNOW_DEVICE] = "Unknown device";
layer_type_t[MV_GIGE_DEVICE] = "GigE device";
layer_type_t[MV_1394_DEVICE] = "1394 device";
layer_type_t[MV_USB_DEVICE] = "USB device";
layer_type_t[MV_CAMERALINK_DEVICE] = "CameraLink device";
for (unsigned int i = 0; i < nums; ++i)
{
const auto &usb_info = info[i]->SpecialInfo.stUsb3VInfo;
printf("│ %02d │ %-12.12s │ %-14.14s │ %-19.19s │ %-14.14s │\n",
i, usb_info.chSerialNumber, usb_info.chModelName, usb_info.chDeviceVersion,
layer_type_t[info[i]->nTLayerType].c_str());
}
printf("└──────┴──────────────┴────────────────┴─────────────────────┴────────────────┘\n");
cout << "\033[33m输入相机序列号, 退出输入 \"q\": \033[0m";
string sn;
cin >> sn;
if (sn == "q")
return 0;
HikVideoCapture capture(GRAB_CONTINUOUS, RETRIEVE_CV, sn.c_str());
int exposure = 1000;
int gain = 0;
int r_gain = 1200;
int g_gain = 1200;
int b_gain = 1200;
// Load the last parameters
FileStorage fs("out_para.yml", FileStorage::READ);
if (fs.isOpened())
{
readExcludeNone(fs["exposure"], exposure);
readExcludeNone(fs["gain"], gain);
readExcludeNone(fs["r_gain"], r_gain);
readExcludeNone(fs["g_gain"], g_gain);
readExcludeNone(fs["b_gain"], b_gain);
}
capture.set(CAP_PROP_RM_EXPOSURE, exposure);
capture.set(CAP_PROP_RM_GAIN, gain);
capture.set(CAP_PROP_RM_MANUAL_WB);
capture.set(CAP_PROP_RM_WB_RGAIN, r_gain);
capture.set(CAP_PROP_RM_WB_GGAIN, g_gain);
capture.set(CAP_PROP_RM_WB_BGAIN, b_gain);
namedWindow("图像画面", WINDOW_NORMAL);
resizeWindow("图像画面", Size(640, 480));
Mat frame;
while (capture.read(frame))
{
imshow("图像画面", frame);
if (waitKey(1) == 27)
if (waitKey(0) == 27)
break;
}
return 0;
}
#define CAM_INFO(msg...)
Definition: camera_logging.h:38
@ CAP_PROP_RM_WB_BGAIN
白平衡蓝色分量 Blue channel gain of white balance
Definition: camera_define.h:63
@ CAP_PROP_RM_WB_RGAIN
白平衡红色分量 Red channel gain of white balance
Definition: camera_define.h:61
@ CAP_PROP_RM_EXPOSURE
曝光值 Expusure
Definition: camera_define.h:58
@ CAP_PROP_RM_MANUAL_EXPOSURE
手动曝光 Manual exposure
Definition: camera_define.h:56
@ CAP_PROP_RM_GAIN
模拟增益 Analog gain
Definition: camera_define.h:59
@ CAP_PROP_RM_MANUAL_WB
手动白平衡 Manual white balance
Definition: camera_define.h:57
@ CAP_PROP_RM_WB_GGAIN
白平衡绿色分量 Green channel gain of white balance
Definition: camera_define.h:62
@ RETRIEVE_CV
使用 OpenCV 的 'cvtColor' 进行处理 Retrieve using cvtColor function in OpenCV
Definition: camera_define.h:39
@ GRAB_CONTINUOUS
连续采样 Continuous grabbing
Definition: camera_define.h:29
void readExcludeNone(const _FileNode &n, Tp &t)
参数读取,忽略为空的节点
Definition: loader.hpp:41
Hik Robot 工业相机库
Definition: uty_math.hpp:63
Definition: camera.hpp:23
Definition: camera_define.h:19