Basler Pylon 4 SDK和OPENCV 2.4.8, Linux简易查看器
Basler Pylon 4 SDK and OPENCV 2.4.8, Linux simple viewer
我正在开发一个简单的相机查看器来测试Basler相机acA1300-30gc。我在Ubuntu 14.04与Basler Pylon 4和OPENCV版本2.4.8中工作,因为我要开发一个机器视觉应用程序,我需要在飞行中分析帧。
基于OpenCV显示图像教程,python文档中的示例代码和这个类似的问题,我编写了以下代码。
代码:int main(int argc, char* argv[]) {
Pylon::PylonAutoInitTerm autoInitTerm;
Mat image(IM_HEIGHT, IM_WIDTH, CV_8UC3);
CGrabResultPtr ptrGrabResult;
//namedWindow(WIN_NAME,CV_WINDOW_AUTOSIZE);
try {
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.StartGrabbing();
while(camera.IsGrabbing()){
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
if (ptrGrabResult->GrabSucceeded()){
memcpy(image.ptr(),ptrGrabResult->GetBuffer(),ptrGrabResult->GetWidth()*ptrGrabResult->GetHeight());
//if(!image.empty())
//imshow(WIN_NAME,image);
//if(waitKey(30)==27){
// camera.StopGrabbing();
//}
}
}
} catch (GenICam::GenericException &e) {
cerr << "An exception occurred." << endl << e.GetDescription() << endl;
}
//destroyWindow(WIN_NAME);
return 0;
}
我不知道为什么取消评论namedWindow(WIN_NAME,CV_WINDOW_AUTOSIZE);
相机不再抓取了。
如果有人能帮助我,我将非常感激。
// Grab.cpp
/*
Note: Before getting started, Basler recommends reading the Programmer's Guide topic
in the pylon C++ API documentation that gets installed with pylon.
If you are upgrading to a higher major version of pylon, Basler also
strongly recommends reading the Migration topic in the pylon C++ API documentation.
This sample illustrates how to grab and process images using the CInstantCamera class.
The images are grabbed and processed asynchronously, i.e.,
while the application is processing a buffer, the acquisition of the next buffer is done
in parallel.
The CInstantCamera class uses a pool of buffers to retrieve image data
from the camera device. Once a buffer is filled and ready,
the buffer can be retrieved from the camera object for processing. The buffer
and additional image data are collected in a grab result. The grab result is
held by a smart pointer after retrieval. The buffer is automatically reused
when explicitly released or when the smart pointer object is destroyed.
*/
#include <pylon/PylonIncludes.h>
#ifdef PYLON_WIN_BUILD
#include <pylon/PylonGUI.h>
#endif
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
using namespace cv;
// Namespace for using pylon objects.
using namespace Pylon;
// Namespace for using cout.
using namespace std;
// Number of images to be grabbed.
static const uint32_t c_countOfImagesToGrab = 100;
int main(int argc, char* argv[])
{
// The exit code of the sample application.
int exitCode = 0;
// Automagically call PylonInitialize and PylonTerminate to ensure
// the pylon runtime system is initialized during the lifetime of this object.
Pylon::PylonAutoInitTerm autoInitTerm;
CGrabResultPtr ptrGrabResult;
namedWindow("CV_Image",WINDOW_AUTOSIZE);
try
{
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
GenApi::CIntegerPtr width(camera.GetNodeMap().GetNode("Width"));
GenApi::CIntegerPtr height(camera.GetNodeMap().GetNode("Height"));
Mat cv_img(width->GetValue(), height->GetValue(), CV_8UC3);
camera.StartGrabbing();
CPylonImage image;
CImageFormatConverter fc;
fc.OutputPixelFormat = PixelType_RGB8packed;
while(camera.IsGrabbing()){
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
if (ptrGrabResult->GrabSucceeded()){
fc.Convert(image, ptrGrabResult);
cv_img = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3,(uint8_t*)image.GetBuffer());
imshow("CV_Image",cv_img);
waitKey(1);
if(waitKey(30)==27){
camera.StopGrabbing();
}
}
}
}
catch (GenICam::GenericException &e)
{
// Error handling.
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
// Comment the following two lines to disable waiting on exit
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != 'n');
return exitCode;
}
获取grab.cpp示例代码,并将以下代码添加到garb.cpp中,它将正常工作。
CImageFormatConverter fc;
fc.OutputPixelFormat = PixelType_BGR8packed;
CPylonImage image;
if (ptrGrabResult->GrabSucceeded())
{
fc.Convert(image, ptrGrabResult);
Mat cv_img = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3, (uint8_t*)image.GetBuffer());
imshow(src_window,cv_img);
waitKey(1);
}
相关文章:
- 在C++/Linux中设置单调时钟的一些技巧
- Linux的Cpp上的计时器
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 内置函数可查看CPP中的成员变量
- 在Linux中哪里可以找到互斥、未来等的源代码
- 如何在linux终端中同时编译和运行c++代码
- 在Linux for Windows上编译C++代码时出错
- 如何找到锁定Linux futex的C++行
- 在linux上调试巨大的C++项目
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- c++方法参数只能在linux的发布模式下自行更改
- 在Linux和C++中的Windows上,散列字符串值会产生不同的输出
- 这里在 Linux 中具有"CreatePipe"和"CreateProcessW"功能吗?
- 函数在Windows或Linux上运行时表现不同
- 在Linux下捕获SIGKILL的C++程序
- 在为LINUX创建共享库时,如何避免STL的私有/弱副本
- GCC C++11无法查看#if windows和#if linux(重新询问)
- Basler Pylon 4 SDK和OPENCV 2.4.8, Linux简易查看器
- 如何查看Linux .so或.a对象的内部并查看它们包含哪些函数
- 如何在linux中查看.o文件的信息和编译器标志