| RMVL 2.3.0 Robotic Manipulation and Vision Library

载入中...
搜索中...
未找到
samples/camera/hik/sample_hik_multi.cpp

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

#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <MvCameraControl.h>
#include "rmvl/camera/hik_camera.h"
int main()
{
int ret = MV_OK;
MV_CC_DEVICE_INFO_LIST camera_list;
ret = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &camera_list);
if (ret != MV_OK)
INFO_("failed to enum camera devices");
unsigned int nums = camera_list.nDeviceNum;
auto info = camera_list.pDeviceInfo;
INFO_("camera quantity: %u", nums);
printf("┌──────┬──────────────┬────────────────┬─────────────────────┬────────────────┐\n");
printf("│ 索引 │ 相机序列号 │ 型号名字 │ 设备版本号 │ 通信协议 │\n");
printf("├──────┼──────────────┼────────────────┼─────────────────────┼────────────────┤\n");
std::unordered_map<unsigned int, std::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");
printf("\033[33m输入相机序列号, 退出输入 \"q\": \033[0m");
std::string sn;
std::cin >> sn;
if (sn == "q")
return 0;
rm::HikCamera capture(rm::CameraConfig::create(rm::GrabMode::Continuous, rm::RetrieveMode::OpenCV), 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
cv::FileStorage fs("out_para.yml", cv::FileStorage::READ);
if (fs.isOpened())
{
fs["exposure"].isNone() ? void(0) : (fs["exposure"] >> exposure);
fs["gain"].isNone() ? void(0) : (fs["gain"] >> gain);
fs["r_gain"].isNone() ? void(0) : (fs["r_gain"] >> r_gain);
fs["g_gain"].isNone() ? void(0) : (fs["g_gain"] >> g_gain);
fs["b_gain"].isNone() ? void(0) : (fs["b_gain"] >> b_gain);
}
capture.set(rm::CAMERA_MANUAL_EXPOSURE);
capture.set(rm::CAMERA_EXPOSURE, exposure);
capture.set(rm::CAMERA_GAIN, gain);
capture.set(rm::CAMERA_MANUAL_WB);
capture.set(rm::CAMERA_WB_RGAIN, r_gain);
capture.set(rm::CAMERA_WB_GGAIN, g_gain);
capture.set(rm::CAMERA_WB_BGAIN, b_gain);
namedWindow("图像画面", cv::WINDOW_NORMAL);
resizeWindow("图像画面", cv::Size(640, 480));
cv::Mat frame;
while (capture.read(frame))
{
imshow("图像画面", frame);
if (cv::waitKey(1) == 27)
if (cv::waitKey(0) == 27)
break;
}
return 0;
}
hik_camera.h
HikRobot 工业相机库
rm::HikCamera
海康机器人相机库
定义 hik_camera.h:37
rm::HikCamera::read
bool read(cv::OutputArray image)
从相机设备中读取图像
rm::HikCamera::set
bool set(int propId, double value=0.0)
设置相机参数/事件
rm::RetrieveMode::OpenCV
@ OpenCV
使用 OpenCV 的 'cvtColor' 进行处理
定义 camutils.hpp:54
rm::CAMERA_WB_BGAIN
@ CAMERA_WB_BGAIN
白平衡蓝色分量
定义 camutils.hpp:108
rm::CAMERA_WB_GGAIN
@ CAMERA_WB_GGAIN
白平衡绿色分量
定义 camutils.hpp:107
rm::CAMERA_MANUAL_EXPOSURE
@ CAMERA_MANUAL_EXPOSURE
手动曝光
定义 camutils.hpp:99
rm::CAMERA_EXPOSURE
@ CAMERA_EXPOSURE
曝光值
定义 camutils.hpp:103
rm::CAMERA_MANUAL_WB
@ CAMERA_MANUAL_WB
手动白平衡
定义 camutils.hpp:102
rm::CAMERA_WB_RGAIN
@ CAMERA_WB_RGAIN
白平衡红色分量
定义 camutils.hpp:106
rm::CAMERA_GAIN
@ CAMERA_GAIN
模拟增益
定义 camutils.hpp:104
rm::GrabMode::Continuous
@ Continuous
连续采样
定义 camutils.hpp:36
INFO_
#define INFO_(...)
定义 util.hpp:57
rm::CameraConfig::create
static CameraConfig create(Args &&...modes)
创建相机初始化配置模式
定义 camutils.hpp:72