basler 相机取图超时_Basler|基于OpenCV的Basler相机采集图像程序

本文介绍如何使用Basler 4.0 SDK结合OpenCV进行图像采集。通过回调函数生成灰度图像,转换CCD数据到Mat类型并显示。同时,设置了相机参数如AOI、像素格式、曝光时间和缓冲区数量,并实现连续抓取图像。
摘要由CSDN通过智能技术生成

采用Basler4.0SDK编写,利用Event机制在回调函数中生成灰度图像

回调函数中图像生成代码,利用CCD中获取的无符号字符型数组转变成

Mat类型

Mat grab( siz, CV_8UC1, ptrGrabResult->GetBuffer(), siz.width*1 ); namedWindow( "test" ); imshow( "test", grab ); cvWaitKey(300);

生成的IplImage类型

IplImage* src = cvCreateImage( siz,IPL_DEPTH_8U, 1 ); cvSetData( src, ptrGrabResult->GetBuffer(), siz.width*1 ); cvNamedWindow("test"); cvShowImage( "test", src );

设置Basler相机的内部参数以及图像获取

// Create an instant camera object with the camera device found first. CBaslerGigEInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice()); // Print the model name of the camera. cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl; // For demonstration purposes only, register another image event handler. camera.RegisterImageEventHandler( new CSampleImageEventHandler, RegistrationMode_Append, Cleanup_Delete); // Camera event processing must be activated first, the default is off. camera.GrabCameraEvents = true; camera.Open(); // Set the AOI: // On some cameras the Offsets are read-only, // so we check whether we can write a value. Otherwise, we would get an exception. // GenApi has some convenience predicates to check this easily. camera.OffsetX.SetValue(0); camera.OffsetY.SetValue(0); camera.Width.SetValue(1280); camera.Height.SetValue(960); //Disable acquisition start trigger if available { GenApi::IEnumEntry* acquisitionStart = camera.TriggerSelector.GetEntry( TriggerSelector_AcquisitionStart); if ( acquisitionStart && GenApi::IsAvailable( acquisitionStart)) { camera.TriggerSelector.SetValue( TriggerSelector_AcquisitionStart); camera.TriggerMode.SetValue( TriggerMode_Off); } } // Set pixel format to Mono8 if available. if ( GenApi::IsAvailable( camera.PixelFormat.GetEntry(PixelFormat_Mono8))) { camera.PixelFormat.SetValue(PixelFormat_Mono8); } //Set exposure settings camera.ExposureMode.SetValue(ExposureMode_Timed); camera.ExposureTimeRaw.SetValue(1500); //100 by default // The parameter MaxNumBuffer can be used to control the count of buffers // allocated for grabbing. The default value of this parameter is 10. camera.MaxNumBuffer = 5; // Start the grabbing of c_countOfImagesToGrab images. // The camera device is parameterized with a default configuration which // sets up free-running continuous acquisition. camera.StartGrabbing(); // This smart pointer will receive the grab result data. CGrabResultPtr ptrGrabResult; // Camera.StopGrabbing() is called automatically by the RetrieveResult() method // when c_countOfImagesToGrab images have been retrieved. while ( camera.IsGrabbing()) { camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException); }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值