用opencv显示basler采集的图片,程序一直调试不好,求帮忙
void CLiveViewPylonDlg::OnBnClickedButton5()
{
// TODO: 在此添加控件通知处理程序代码
//static const uint32_t c_countOfImagesToGrab = 100;
// Before using any pylon methods, the pylon runtime must be initialized.
if (m_camera.IsPylonDeviceAttached())
// Create an instant camera object with the camera device found first.
{
m_camera.StartGrabbing();
//m_camera.MaxNumBuffer = 5;
CGrabResultPtr ptrGrabResult;
unsigned char* m_pucDataBuffer;
unsigned char* m_puc;//获取GetBuffer()
// Camera.StopGrabbing() is called automatically by the RetrieveResult() method
// when c_countOfImagesToGrab images have been retrieved.
while (m_camera.IsGrabbing())
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
m_camera.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);
// Image grabbed successfully?
if (ptrGrabResult->GrabSucceeded())
{
// Access the image data.
m_puc = (unsigned char*)ptrGrabResult->GetBuffer();//从相机里面得到buffer
int iWidth = ptrGrabResult->GetWidth();
int iHeight = ptrGrabResult->GetHeight();
//pImageBuffer = (unsigned char*)ptrGrabResult->GetBuffer();
//m_pucDataBuffer = (unsigned char*)malloc(m_lSize);
m_pucDataBuffer = (unsigned char*)malloc(sizeof(m_puc));//创建一个m_pucDataBuffer用来复制相机buffer的内容
memcpy(m_pucDataBuffer, m_puc, sizeof(m_puc));//复制
//IplImage* rawImage = cvCreateImage(cvSize(iWidth, iHeight), IPL_DEPTH_8U, 1);
//cvNamedWindow("haha", CV_WINDOW_AUTOSIZE);
cv::Mat mat(iHeight, iWidth, CV_8UC1, m_pucDataBuffer);
//cv::Mat mat(iHeight, iWidth, CV_8UC1, pImageBuffer);//////////////
//imwrite("mat.png", mat);
namedWindow("img");
imshow("img", mat);
}
}
}
}