| RMVL 2.4.0 Robotic Manipulation and Vision Library

载入中...
搜索中...
未找到
samples/camera/mv/sample_mv_multi.cpp

迈德威视多相机例程

#include <iostream>
#include <opencv2/highgui.hpp>
#include "rmvl/camera/camutils.hpp"
#include "rmvl/camera/mv_camera.h"
#ifdef _WIN32
#include <Windows.h>
#endif // _WIN32
#include <CameraApi.h>
int main() {
int camera_counts = 8;
std::vector<tSdkCameraDevInfo> camera_list(camera_counts);
auto status = CameraEnumerateDevice(camera_list.data(), &camera_counts);
if (status != CAMERA_STATUS_SUCCESS) {
printf("Failed to enumerate the camera decive!\n");
return 0;
}
printf("┌──────┬──────────────┬────────────────┬─────────────────────┬────────────────┐\n");
printf("│ 索引 │ 相机序列号 │ 产品型号 │ 传感器类型 │ 通信协议 │\n");
printf("├──────┼──────────────┼────────────────┼─────────────────────┼────────────────┤\n");
for (int i = 0; i < camera_counts; ++i)
printf("│ %02d │ %-12.12s │ %-14.14s │ %-19.19s │ %-14.14s │\n",
i, camera_list[i].acSn, camera_list[i].acProductName,
camera_list[i].acSensorType, camera_list[i].acPortType);
printf("└──────┴──────────────┴────────────────┴─────────────────────┴────────────────┘\n");
std::cout << "\033[33m输入相机序列号, 退出输入 \"q\": \033[0m";
std::string sn;
std::cin >> sn;
if (sn == "q")
return 0;
rm::MvCamera capture(rm::CameraConfig::create(rm::GrabMode::Continuous, rm::RetrieveMode::OpenCV), sn.c_str());
int exposure = 1000;
int gain = 64;
int r_gain = 100;
int g_gain = 100;
int b_gain = 100;
// 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::CameraProperties::auto_exposure, false);
capture.set(rm::CameraProperties::exposure, static_cast<double>(exposure));
capture.set(rm::CameraProperties::gain, gain);
capture.set(rm::CameraProperties::auto_wb, false);
capture.set(rm::CameraProperties::wb_rgain, r_gain);
capture.set(rm::CameraProperties::wb_ggain, g_gain);
capture.set(rm::CameraProperties::wb_bgain, b_gain);
namedWindow("frame", cv::WINDOW_NORMAL);
cv::Mat frame;
if (!capture.read(frame))
return -1;
resizeWindow("frame", cv::Size(static_cast<int>(frame.cols * 0.8),
static_cast<int>(frame.rows * 0.8)));
while (capture.read(frame)) {
cv::imshow("frame", frame);
if (cv::waitKey(1) == 27)
if (cv::waitKey(0) == 27)
break;
}
return 0;
}
rm::MvCamera
迈德威视相机库
定义 mv_camera.h:37
rm::MvCamera::read
bool read(cv::OutputArray image)
从相机设备中读取图像
rm::MvCamera::set
bool set(CameraProperties propId, Tp value) noexcept
设置相机参数
rm::RetrieveMode::OpenCV
@ OpenCV
使用 OpenCV 的 'cvtColor' 进行处理
定义 camutils.hpp:49
rm::GrabMode::Continuous
@ Continuous
连续采样
定义 camutils.hpp:33
rm::CameraProperties::wb_bgain
@ wb_bgain
白平衡蓝色分量
定义 camutils.hpp:97
rm::CameraProperties::auto_wb
@ auto_wb
自动白平衡
定义 camutils.hpp:91
rm::CameraProperties::auto_exposure
@ auto_exposure
自动曝光
定义 camutils.hpp:90
rm::CameraProperties::wb_ggain
@ wb_ggain
白平衡绿色分量
定义 camutils.hpp:96
rm::CameraProperties::exposure
@ exposure
曝光值
定义 camutils.hpp:92
rm::CameraProperties::wb_rgain
@ wb_rgain
白平衡红色分量
定义 camutils.hpp:95
rm::CameraProperties::gain
@ gain
模拟增益
定义 camutils.hpp:93
rm::CameraConfig::create
static CameraConfig create(Args &&...modes)
创建相机初始化配置模式
定义 camutils.hpp:66