| RMVL 2.3.0 Robotic Manipulation and Vision Library

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

迈德威视单相机例程

#include <opencv2/highgui.hpp>
#include "rmvl/camera/mv_camera.h"
#include "rmvl/core/timer.hpp"
using namespace std::chrono_literals;
static int exposure = 1000;
static int gain = 64;
static int r_gain = 100;
static int g_gain = 100;
static int b_gain = 100;
rm::MvCamera cap(rm::CameraConfig::create(rm::GrabMode::Continuous, rm::RetrieveMode::OpenCV));
void exposureCallBack(int pos, void *)
{
exposure = pos;
cap.set(rm::CAMERA_EXPOSURE, exposure);
}
void gainCallBack(int pos, void *)
{
gain = pos;
cap.set(rm::CAMERA_GAIN, gain);
}
void rGainCallBack(int pos, void *)
{
r_gain = pos;
cap.set(rm::CAMERA_WB_RGAIN, r_gain);
}
void gGainCallBack(int pos, void *)
{
g_gain = pos;
cap.set(rm::CAMERA_WB_GGAIN, g_gain);
}
void bGainCallBack(int pos, void *)
{
b_gain = pos;
cap.set(rm::CAMERA_WB_BGAIN, b_gain);
}
int main()
{
// 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);
}
cap.set(rm::CAMERA_MANUAL_EXPOSURE);
cap.set(rm::CAMERA_EXPOSURE, exposure);
cap.set(rm::CAMERA_GAIN, gain);
cap.set(rm::CAMERA_MANUAL_WB);
cap.set(rm::CAMERA_WB_RGAIN, r_gain);
cap.set(rm::CAMERA_WB_GGAIN, g_gain);
cap.set(rm::CAMERA_WB_BGAIN, b_gain);
namedWindow("图像画面", cv::WINDOW_NORMAL);
namedWindow("控制面板", cv::WINDOW_AUTOSIZE);
cv::Mat track_bar_img(cv::Size(750, 1), CV_8UC1, cv::Scalar(60, 60, 60));
cv::createTrackbar("曝光值", "控制面板", nullptr, 10000, exposureCallBack, nullptr);
cv::setTrackbarPos("曝光值", "控制面板", exposure);
cv::createTrackbar("增益值", "控制面板", nullptr, 256, gainCallBack, nullptr);
cv::setTrackbarPos("增益值", "控制面板", gain);
cv::createTrackbar("红通道", "控制面板", nullptr, 200, rGainCallBack, nullptr);
cv::setTrackbarPos("红通道", "控制面板", r_gain);
cv::createTrackbar("绿通道", "控制面板", nullptr, 200, gGainCallBack, nullptr);
cv::setTrackbarPos("绿通道", "控制面板", g_gain);
cv::createTrackbar("蓝通道", "控制面板", nullptr, 200, bGainCallBack, nullptr);
cv::setTrackbarPos("蓝通道", "控制面板", b_gain);
rm::Timer::sleep_for(1000);
const char *file_name = "out_para.yml";
printf("Press the 's' key to save the parameters to the yaml file: \033[33m%s\033[0m\n", file_name);
cv::Mat frame;
if (!cap.read(frame))
return -1;
resizeWindow("图像画面", cv::Size(static_cast<int>(frame.cols * 0.8), static_cast<int>(frame.rows * 0.8)));
while (true)
{
if (!cap.read(frame))
continue;
imshow("图像画面", frame);
imshow("控制面板", track_bar_img);
char c = cv::waitKey(1);
if (c == 27)
{
if (cv::waitKey(0) == 27)
break;
}
else if (c == 's')
{
cv::FileStorage fs(file_name, cv::FileStorage::WRITE);
fs.write("exposure", exposure);
fs.write("gain", gain);
fs.write("r_gain", r_gain);
fs.write("g_gain", g_gain);
fs.write("b_gain", b_gain);
printf("\033[32mSuccess to write the parameters into \"%s\"\033[0m\n", file_name);
printf(" -- exposure: %d\n", exposure);
printf(" -- gain: %d\n", gain);
printf(" -- r_gain: %d\n", r_gain);
printf(" -- g_gain: %d\n", g_gain);
printf(" -- b_gain: %d\n", b_gain);
}
}
return 0;
}
mv_camera.h
迈德威视相机库
rm::MvCamera
迈德威视相机库
定义 mv_camera.h:38
rm::Timer::sleep_for
static void sleep_for(double t)
当前线程休眠指定时间
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
rm::CameraConfig::create
static CameraConfig create(Args &&...modes)
创建相机初始化配置模式
定义 camutils.hpp:72
timer.hpp
定时、计时模块