PointGrey相机同步采集中使用boost::barrier
来源:互联网 发布:商家给淘宝开消费积分 编辑:程序博客网 时间:2024/05/19 00:09
#include <boost/thread.hpp>#include <boost/thread/barrier.hpp>#include <boost/bind.hpp>//#include <boost/atomic.hpp>#include "FlyCapture2.h"#include <vector>#include <sstream>#include <boost/lexical_cast.hpp>boost::mutex io_mutex;using namespace FlyCapture2;unsigned long getThreadId(){ std::string threadId = boost::lexical_cast<std::string>(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<int>& current){ ++current; cur_barier.wait(); //boost::lock_guard<boost::mutex> 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<boost::mutex> locker( ); //PrintCameraInfo(&camInfo); int threadID = (int)getThreadId(); Image rawImage, convertedImage; unsigned int numImages = 50; std::vector<Image> 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<numCameras; i++) { // connect to a camera PGRGuid guid; pcam[i] = new Camera(); error = busMgr.GetCameraFromIndex( i, &guid ); if (error != PGRERROR_OK) { PrintError( error ); return -1; } error = pcam[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<int> 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;}
2 0
- PointGrey相机同步采集中使用boost::barrier
- boost::barrier同步原理
- PointGrey相机的安装配置使用
- Halcon 连接 pointgrey 双目相机
- Pointgrey相机代码和资料
- 使用Barrier来控制线程同步
- boost::thread (barrier)
- barrier使用
- 障碍同步Barrier Synchronization
- 障碍同步Barrier Synchronization
- 线程同步之 barrier
- barrier synchronization 障碍同步
- Linux pthread 障碍同步barrier
- C#多线程同步(七)【Barrier】
- Barrier的使用
- 多线程:barrier的使用
- OpenThreads使用-Barrier
- 关于多线程同步的初步教程--Barrier的设计及使用
- IDEA基于maven多模块框架搭建
- 如何在Python 2.7上安装PyGraphviz
- 百度地图api 自定义驾车线路规划 车辆实时定位
- Linux 软件下载安装个人经验
- 京东2016笔试编程题
- PointGrey相机同步采集中使用boost::barrier
- make[1]: *** No rule to make target `modules'. Stop.
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
- socket 知识点
- SQL进行字符的拼接与拆分
- Qt Creator5.8调用大漠插件
- C++继承详解三 ----菱形继承、虚继承
- sh/bash/csh/Tcsh/ksh/pdksh等shell的区别
- 计算机视觉方面的数据集收藏(CV Datasets on the web)