可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a grabber which can get the images and show them on the screen with the following code
while((lastPicNr = Fg_getLastPicNumberBlockingEx(fg,lastPicNr+1,0,10,_memoryAllc))
but I want to use the pointer to the image data and display them with OpenCV, cause I need to do the processing on the pixels. my camera is a CCD mono camera and the depth of the pixels is 8bits. I am new to OpenCV, is there any option in opencv that can get the return of the (unsigned char*)Fg_getImagePtrEx(fg,lastPicNr,0,_memoryAllc); and disply it on the screen? or get the data from the iPtr pointer an allow me to use the image data?
回答1:
Creating an IplImage
from unsigned char* raw_data
takes 2 important instructions: cvCreateImageHeader()
and cvSetData()
:
// 1 channel for mono camera, and for RGB would be 3 int channels = 1; IplImage* cv_image = cvCreateImageHeader(cvSize(width,height), IPL_DEPTH_8U, channels); if (!cv_image) { // print error, failed to allocate image! } cvSetData(cv_image, raw_data, cv_image->widthStep); cvNamedWindow("win1", CV_WINDOW_AUTOSIZE); cvShowImage("win1", cv_image); cvWaitKey(10); // release resources cvReleaseImageHeader(&cv_image); cvDestroyWindow("win1");
I haven't tested the code, but the roadmap for the code you are looking for is there.
回答2:
If you are using C++, I don't understand why your are not doing it the simple way like this:
If your camera is supported, I would do it this way:
cv::VideoCapture capture(0); if(!capture.isOpened()) { // print error return -1; } cv::namedWindow("viewer"); cv::Mat frame; while( true ) { capture >> frame; // ... processing here cv::imshow("viewer", frame); int c = cv::waitKey(10); if( (char)c == 'c' ) { break; } // press c to quit }
I would recommend starting to read the docs and tutorials which you can find here.