本文主要介绍使用大恒工业水星139相机搭建双目相机的软件过程.以下主要介绍相机采集图像以及保存的过程。

#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <queue>
#include <thread>
#include <mutex>
#include <unistd.h>
#include "opencv2/opencv.hpp"
#include "camera_api.h"
#include "tic_toc.h"bool time_flag_0 = false;
std::chrono::time_point<std::chrono::system_clock> start_0, end_0;bool time_flag_1 = false;
std::chrono::time_point<std::chrono::system_clock> start_1, end_1;std::queue<cv::Mat> img0_buf;
std::queue<unsigned int> frame0_ID_buf;
std::queue<double> time0_buf;
std::mutex m0_buf;std::queue<cv::Mat> img1_buf;
std::queue<unsigned int> frame1_ID_buf;
std::queue<double> time1_buf;
std::mutex m1_buf;#define image_width 640
#define image_height 480char *pRGB24Buf_0 = new char[image_width * image_height * 3];
char *pRGB24Buf_1 = new char[image_width * image_height * 3];void Frame_0_ProcessRGB(GX_FRAME_CALLBACK_PARAM* pFrame)
{if (pFrame->status == GX_FRAME_STATUS_SUCCESS){std::chrono::time_point<std::chrono::system_clock,std::chrono::microseconds> tp =std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now());//获取当前时间点double time_now =  tp.time_since_epoch().count();start_0 = std::chrono::system_clock::now();//double time_now = start_0.time_since_epoch().count();if(!time_flag_0){end_0 = start_0;time_flag_0 = true;}else{std::chrono::duration<double> elapsed_seconds = start_0 - end_0;std::cout << "the CAM_0 frame frequency is: " << 1/elapsed_seconds.count() << std::endl;end_0 = start_0;}//缓冲区初始化*/memset(pRGB24Buf_0,0,pFrame->nWidth * pFrame->nHeight * 3 * sizeof(char));    //缓冲区初始化*/DX_BAYER_CONVERT_TYPE cvtype    = RAW2RGB_NEIGHBOUR;           //选择插值算法DX_PIXEL_COLOR_FILTER nBayerType = BAYERRG;                   //选择图像Bayer格式bool bFlip = false;VxInt32 DxStatus = DxRaw8toRGB24(const_cast<void *>(pFrame->pImgBuf),pRGB24Buf_0,pFrame->nWidth,pFrame->nHeight,cvtype,nBayerType,bFlip);if (DxStatus != DX_OK){return ;}cv::Mat image_rgb24(pFrame->nHeight, pFrame->nWidth, CV_8UC3);memcpy(image_rgb24.data, pRGB24Buf_0, pFrame->nHeight * pFrame->nWidth * 3);unsigned int frame_id = pFrame->nFrameID;m0_buf.lock();img0_buf.push(image_rgb24);frame0_ID_buf.push(frame_id);time0_buf.push(time_now);m0_buf.unlock()}return ;
}void Frame_1_ProcessRGB(GX_FRAME_CALLBACK_PARAM* pFrame)
{if (pFrame->status == GX_FRAME_STATUS_SUCCESS){std::chrono::time_point<std::chrono::system_clock,std::chrono::microseconds> tp =std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now());//获取当前时间点double time_now =  tp.time_since_epoch().count();start_1 = std::chrono::system_clock::now();if(!time_flag_1){end_1 = start_1;time_flag_1 = true;}else{std::chrono::duration<double> elapsed_seconds = start_1 - end_1;std::cout << "the CAM_1 frame frequency is: " << 1/elapsed_seconds.count() << std::endl;end_1 = start_1;}//缓冲区初始化*/memset(pRGB24Buf_1,0,pFrame->nWidth * pFrame->nHeight * 3 * sizeof(char));    //缓冲区初始化*/DX_BAYER_CONVERT_TYPE cvtype    = RAW2RGB_NEIGHBOUR;           //选择插值算法DX_PIXEL_COLOR_FILTER nBayerType = BAYERRG;                   //选择图像Bayer格式bool bFlip = false;VxInt32 DxStatus = DxRaw8toRGB24(const_cast<void *>(pFrame->pImgBuf),pRGB24Buf_1,pFrame->nWidth,pFrame->nHeight,cvtype,nBayerType,bFlip);if (DxStatus != DX_OK){return ;}cv::Mat image_rgb24(pFrame->nHeight, pFrame->nWidth, CV_8UC3);memcpy(image_rgb24.data, pRGB24Buf_1, pFrame->nHeight * pFrame->nWidth * 3);unsigned int frame_id = pFrame->nFrameID;m1_buf.lock();img1_buf.push(image_rgb24);frame1_ID_buf.push(frame_id);time1_buf.push(time_now);m1_buf.unlock();}return ;
}void cam0_process()
{int cam0_num = 0;while(1){cv::Mat img_frame;unsigned int id = 0;double time = 0;m0_buf.lock();if(!img0_buf.empty()){std::cout << "the img0_buf size is: " << img0_buf.size() << std::endl;img_frame = img0_buf.front().clone();id = frame0_ID_buf.front();time = time0_buf.front();img0_buf.pop();frame0_ID_buf.pop();time0_buf.pop();}m0_buf.unlock();if(img_frame.data){cvtColor(img_frame, img_frame, CV_BGR2RGB);//cv::imshow("img0:",img_frame);std::string img0_path = "/home/h1/CODE/stereo_img_record/build/img0/" + std::to_string(cam0_num++) + ".jpg";std::cout << img0_path << std::endl;cv::imwrite(img0_path, img_frame);//cv::imwrite("/home/h1/CODE/stereo_img_record/capture_image/2021.7.30.jpg", img_frame);cv::waitKey(1);}else{return;}std::chrono::milliseconds dura(1);std::this_thread::sleep_for(dura);}}void cam1_process()
{int cam1_num = 1;while(1){cv::Mat img_frame;unsigned int id = 0;double time = 0;m1_buf.lock();if(!img1_buf.empty()){//std::cout << "the img0_buf size is: " << img0_buf.size() << std::endl;img_frame = img1_buf.front().clone();id = frame1_ID_buf.front();time = time1_buf.front();img1_buf.pop();frame1_ID_buf.pop();time1_buf.pop();}m1_buf.unlock();if(img_frame.data){cvtColor(img_frame, img_frame, CV_BGR2RGB);std::string img1_path = "/home/h1/CODE/stereo_img_record/build/img1/" + std::to_string(cam1_num++) + ".jpg";std::cout << img1_path << std::endl;cv::imwrite(img1_path, img_frame);cv::imshow("img1:",img_frame);}else{return;}std::chrono::milliseconds dura(1);std::this_thread::sleep_for(dura);}}int main()
{GX_STATUS status = Config();if(status != GX_STATUS_SUCCESS){std::cout << "config Camera Faile ..." << std::endl;return  0;}camera_config cam0_info;cam0_info.sn_str = "KE0200100061";cam0_info.SN = &cam0_info.sn_str[0];camera_config cam1_info;cam1_info.sn_str = "KE0200120158";cam1_info.SN = &cam1_info.sn_str[0];MercureDriver* cam0 = new MercureDriver(cam0_info);MercureDriver* cam1 = new MercureDriver(cam1_info);cam0->InitCamera();cam1->InitCamera();if(cam0->status != GX_STATUS_SUCCESS || cam1->status != GX_STATUS_SUCCESS){std::cout << "Initial Stereo Camera Faile ..." << std::endl;return 0;}status = GXRegisterCaptureCallback(cam0->hDevice_, NULL, Frame_0_ProcessRGB);status = GXSendCommand(cam0->hDevice_, GX_COMMAND_ACQUISITION_START);if(status != GX_STATUS_SUCCESS){std::cout << "Cam0 Start Read Faile ..." << std::endl;return  0;}status = GXRegisterCaptureCallback(cam1->hDevice_, NULL, Frame_1_ProcessRGB);status = GXSendCommand(cam1->hDevice_, GX_COMMAND_ACQUISITION_START);if(status != GX_STATUS_SUCCESS){std::cout << "Cam1 Start Read Faile ..." << std::endl;return  0;}std::thread cam0_thread{cam0_process};std::thread cam1_thread{cam1_process};while(1){std::chrono::milliseconds dura(5);std::this_thread::sleep_for(dura);}return 0;
}

大恒工业相机搭建双目相机(软件)相关推荐

  1. 基于Qt大恒工业相机二次开发demo-C++

    目录 1.新建工程 2.文件及属性配置 2.1文件拷贝 2.2VS项目属性配置 2.2.1包含目录和库目录添加 2.2.2附加依赖项添加 3.添加基于官方mfc代码改写的CGXBitmap类 3.1添 ...

  2. 大恒工业相机C#语言winform平台开发例程

    大恒工业相机winform快速开发 例程一.连续采集,返回bitmap格式图像 例程二.软触发采集,返回bitmap格式图像 例程三.硬触发采集,返回bitmap格式图像 例程四.作为TCP客户端接收 ...

  3. 大恒水晶相机_大恒工业相机多实例使用

    工作环境比较恶劣并且有较多干扰源的环境做视觉识别一般都使用工业相机,大恒水晶相机是比较常用的一种.比起来进口相机,虽然用起来会更麻烦,但好在价格便宜,各项指标也不低. 大恒水晶相机是提供SDK的方式跟 ...

  4. 大恒工业相机多实例使用

    工作环境比较恶劣并且有较多干扰源的环境做视觉识别一般都使用工业相机,大恒水晶相机是比较常用的一种.比起来进口相机,虽然用起来会更麻烦,但好在价格便宜,各项指标也不低. 大恒水晶相机是提供SDK的方式跟 ...

  5. 大恒工业相机实例使用

    工作环境比较恶劣并且有较多干扰源的环境做视觉识别一般都使用工业相机,大恒水晶相机是比较常用的一种.比起来进口相机,虽然用起来会更麻烦,但好在价格便宜,各项指标也不低. 大恒水晶相机是提供SDK的方式跟 ...

  6. 工业相机,大恒,面振相机8脚电源线和I/O触发接口线,颜色和接法说明和触发软件设定

    上图: 说明一下,工业相机有TTL逻辑电平触发,也有光耦触发等. 这里一般我们用电路板驱动,就用GPIO触发模式, 这里,准备了两个GPIO触发模式,为LINE2,LINE3都可以选择,然后有一个GP ...

  7. 大恒相机-水星(MERCURY)系列 | 软件启动

    型号名称说明 我使用的型号是MER-139-210U3C,关于大恒水星系列的型号说明如下: 驱动安装 在 大恒官网--下载中心--软件下载可以找到对应的相机驱动: 之后一路 next 傻瓜式安装即可 ...

  8. win10+大恒相机驱动软件的问题

    win10+大恒相机驱动软件的问题 首先根据大恒相机自带的安装包安装软件,然后打开软件,出现 无法打开GCBase_MD_VC120_v3_0:或者 无法打开GenApi_MD_VC120_v3_0: ...

  9. Matlab 图像采集工具的使用 - Image Acquisition Toolbox【IAT】 + 大恒相机的应用【1】+多个摄像头支持

    前言: Matlab 中设定图像采集的时候,是要提前知道相机的各个参数. IAT工具提供了一个可视化的方法,协作从操作系统中获取相机的底层可操作的一些参数,从而,协作你进行创作. 本案在开发的时候,遇 ...

最新文章

  1. Google学术分析公司科研实力:谷歌1161,华为110,为何差10倍?
  2. vue修改代码同步页面_vue修改数组中对象属性值页面不同步更新渲染问题处理
  3. unity3d EasyTouch滑动屏幕移动相机观看场景
  4. Centos7 安装redis
  5. 120所国家重点建设大学(211工程和教育部直属)[国家一类本科大学]详细情况一览表...
  6. [提示]使用普通用户,通过sealos安装ks,默认还是要通过root用户才能正常使用kubectl等命令
  7. Partition分析
  8. Tomcat下使用 telnet命令连接
  9. amaze ui使用简介
  10. CAD迷你画图2020 R11 中文绿色版,详细使用教程
  11. ZipEntry压缩时中文文件名乱码解决办法
  12. windows双系统完全删除ubuntu
  13. java导出带图片excel
  14. 单片机c语言编写一个时钟程序,单片机基于c语言编写时钟.doc
  15. lsa ospf的opaque_OSPF LSA类型详解
  16. 同一个PDF如何同时在两个窗口并排显示?
  17. contactform7 ajax,Wordpress contact_form_7_v5.0.3 插件 权限提升、任意文件读取漏洞分析...
  18. 深度学习框架之争:TensorFlow退守工业界,PyTorch主导学术界?
  19. CF 1646C Factorials and Powers of Two
  20. 58同城android客户端手机号码解密方法

热门文章

  1. java 对应sql驱动版本_有关sqlserver的 jdbc驱动版本整理
  2. 【英语四六级-必背单词】高中英语单词 (I) - MP3试听与下载
  3. PHP之高并发解决方案
  4. STM32调试诊断工具 | STM32CubeMonitor介绍、下载、安装和使用教程
  5. 【机器学习|数学基础】Mathematics for Machine Learning系列之矩阵理论(25):幂级数(补充知识)
  6. Back to Back vs Drop Shipment
  7. element 时间转时间戳
  8. 取色器(Snipaste) 截图 贴图 取色
  9. 【数学】方差/标准差的各种估计辨析
  10. 钉钉实现ISV特殊接口调用