2
votes

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))<200) {                                                           
                iPtr=(unsigned char*)Fg_getImagePtrEx(fg,lastPicNr,0,_memoryAllc);                  
                ::DrawBuffer(nId,iPtr,lastPicNr,"testing");                                         }

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?

2
Is your Camera not supported or why are you trying to mess with pointers?Stephan Dollberg
hi bamboon, im not sure about this, does it mean that if it supports my camera then I dont need to use the framegrabber interface, and I can use the OpenCV directly to get the images?user261002
Thank you so much. Im going to try it now.user261002
im trying to use the sample from this link : opencv.willowgarage.com/wiki/CameraCapture but it keep giving me this message : Error:capture is NULL, do you know how can I find out if the opencv is supporting my camera. ??user261002
there is a list here which I assume is probably not complete though. opencv.willowgarage.com/wiki/…Stephan Dollberg

2 Answers

5
votes

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
votes

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.