博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PointGrey相机同步采集中使用boost::barrier
阅读量:3593 次
发布时间:2019-05-20

本文共 3915 字,大约阅读时间需要 13 分钟。

#include 
#include
#include
//#include
#include "FlyCapture2.h"#include
#include
#include
boost::mutex io_mutex;using namespace FlyCapture2;unsigned long getThreadId(){ std::string threadId = boost::lexical_cast
(boost::this_thread::get_id()); unsigned long threadNumber = 0; sscanf(threadId.c_str(), "%lx", &threadNumber); return threadNumber;}void PrintCameraInfo( CameraInfo* pCamInfo ){ printf( "\n*** CAMERA INFORMATION ***\n" "Serial number - %u\n" "Camera model - %s\n" "Camera vendor - %s\n" "Sensor - %s\n" "Resolution - %s\n" "Firmware version - %s\n" "Firmware build time - %s\n\n", pCamInfo->serialNumber, pCamInfo->modelName, pCamInfo->vendorName, pCamInfo->sensorInfo, pCamInfo->sensorResolution, pCamInfo->firmwareVersion, pCamInfo->firmwareBuildTime );}void PrintError( Error error ){ error.PrintErrorTrace();}/*void thread_fun(boost::barrier& cur_barier, boost::atomic
& current){ ++current; cur_barier.wait(); //boost::lock_guard
locker( ); std::cout << current << std::endl;}*/void capture_images(boost::barrier& cur_barier, Camera* c){ Error error; //CameraInfo camInfo; //c->GetCameraInfo( &camInfo ); //boost::lock_guard
locker( ); //PrintCameraInfo(&camInfo); int threadID = (int)getThreadId(); Image rawImage, convertedImage; unsigned int numImages = 50; std::vector
vecImages; vecImages.resize(numImages); for (unsigned int j=0; j < numImages; j++ ) { cur_barier.wait(); error = c->RetrieveBuffer( &rawImage ); if (error != PGRERROR_OK) { PrintError( error ); continue; //For threads, all the other threads have to continue ------------- } // We'll also print out a timestamp TimeStamp timestamp = rawImage.GetTimeStamp(); printf("Cam %d - Frame %d - TimeStamp [%u %u]\n",threadID,j,timestamp.cycleSeconds,timestamp.cycleCount); vecImages[j].DeepCopy(&rawImage); } //Process and store the images captured for (unsigned int j=0; j < numImages; j++) { error = vecImages[j].Convert( PIXEL_FORMAT_RGB, &convertedImage ); if (error != PGRERROR_OK){ PrintError( error ); return; } // Create a unique filename char filename[512]; sprintf( filename, "./images/cam--%d-%d.tiff", threadID, j); // Save the image. If a file format is not passed in, then the file // extension is parsed to attempt to determine the file format. error = convertedImage.Save( filename ); if (error != PGRERROR_OK){ PrintError( error ); return; } } c->StopCapture(); c->Disconnect();}int main(){ Error error; CameraInfo camInfo; BusManager busMgr; unsigned int numCameras; error = busMgr.GetNumOfCameras(&numCameras); if (error != PGRERROR_OK) { PrintError( error ); return -1; } printf("cameras: %u\n", numCameras); Camera* pcam[numCameras] ; // now we do the formalities needed to establish a connection for (unsigned int i=0; i
Connect(&guid); if (error != PGRERROR_OK) { PrintError( error ); return -1; } // Get the camera information error = pcam[i]->GetCameraInfo( &camInfo ); if (error != PGRERROR_OK) { PrintError( error ); return -1; } // uncomment the following line if you really care about the camera info // PrintCameraInfo(&camInfo); // Next we turn isochronous images capture ON for both cameras error = pcam[i]->StartCapture(); if (error != PGRERROR_OK) { PrintError( error ); return -1; } }//call the threads to capture images, convert and save to file------------------------------ boost::barrier bar(2); // boost::atomic
current(0); boost::thread thr1(boost::bind(&capture_images, boost::ref(bar), boost::ref(pcam[0]))); boost::thread thr2(boost::bind(&capture_images, boost::ref(bar), boost::ref(pcam[1]))); //boost::thread thr2(boost::bind(&thread_fun, boost::ref(bar), boost::ref(current))); thr1.join(); thr2.join(); printf( "Do not press any key till images are captured and written...\n" ); getchar(); for ( unsigned int i = 0; i < numCameras; i++ ) { delete pcam[i]; } printf( "Done! Press Enter to exit...\n" ); getchar(); return 0;}

转载地址:http://piown.baihongyu.com/

你可能感兴趣的文章
解决vue工程报错Uncaught (in promise) Error: Request failed with status code 404
查看>>
vue+element-ui多选和按钮绑定并将值传往后端
查看>>
springboot+mybatis按条件查询分页问题
查看>>
springboot+vue+element-ui实现图文上传(表单文字和图片一起入库)
查看>>
springboot+vue+element-ui下载excel模板(静态文件)
查看>>
vue项目打包部署后二级页面刷新变成404问题
查看>>
springboot在Windows服务器部署做成服务
查看>>
vue的页面刷新和单独组件的销毁重建
查看>>
vue+ckplayer+rtmp
查看>>
vue+pg库+openlayer5+geoserver+离线地图瓦片构建gis地图+地图撒点+点击点出现地图弹框(***完整流程***)
查看>>
openlayer5实现地图撒点,点击弹框效果
查看>>
vscode炫酷写代码插件Power Mode
查看>>
实现字符串倒叙
查看>>
node中引入其他ejs文件,并给引入文件传参,类似iframe
查看>>
ejs中在页面上使用if-else
查看>>
moment中时间为12小时制,dayjs中时间为12小时制
查看>>
vue解决打包后文件过大的问题-使用压缩插件打包后压缩文件-compression-webpack-plugin
查看>>
爆料称字节跳动实习生删库
查看>>
无缝滚动lunbot
查看>>
如何将Map集合写入txt文件中
查看>>