Reputation: 11
I am new to OpenCV and I am trying to show the "panasonic d-imager" 3d camera on screen using OpenCV. With no success so far.
I get DLL file that contains the following functions
// This function connects the personal computer to the 3D Image Sensor, and sets up the system to acquire images from the sensor.
InitImageDriver();
//This function obtains the image data from the camera via the USB driver, and copies the range image data and grayscale image data to the area given by the argument. kdat and ndat=Pointer of the range and grayscale image data acquiring buffer.Always secure the range image storage area using the application program. The size of the range image data storage area should be: 160’ 120 ‘2 = 38400 bytes.
int WINAPI GetImageKN(unsigned short *kdat ,unsigned short *ndat);
Now I just want to show two camera outputs on screen (color and grayscale). I wrote this code:
#include
#include
#include "Dimagerdll.h" //the hader file
#pragma comment(lib,"Dimagerdll.lib") // the lib file of dll
using namespace std;
int main(int argc, char *argv[])
{
IplImage *img;
unsigned short *r= new unsigned short[38400];
unsigned short *t= new unsigned short[38400];
InitImageDriver(); //dll function
GetImageKN(r,t); //dll function
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);//create a window to display the images
cvMoveWindow("mainWin", 5, 5);// position the window
while(1)
{
img=cvQueryFrame(r);// retrieve the captured frame-but here is the problem! r is unsigned short so it cant compile!!!!!
cvShowImage("mainWin", img );// show the image in the window
c=cvWaitKey(10);
if(c == 27)
break;
}
FreeImageDriver();//dll function
return 0;
}
It is obvious that I can't use cvQueryFrame
because the data from camera is not IplImage
.
Could anyone tell me what else I need to do???
thanks
Upvotes: 1
Views: 708
Reputation: 1762
You are correct you can't use cvQueryFrame, that is meant for cameras that have special webcam drivers. So, it looks like you understand the API to interface to the camera and get data out of it; all that is left to do is convert that data to an IplImage, do some processing on it if you wish, display the image if you wish, and loop through the frames that you receive at the desired frame-rate.
So, the images you are getting, are they coded (such as in JPEG format), or are you getting pixel values (0-255 if 8 bit). If the image data is coded, you will have to know what type of coding is used and decode using a type of library. For example LibJPEG Turbo is what I use to decode JPEG data from Nikon and Canon cameras.
Assuming you decoded the image, or the image is not coded, you will have to know some details about the image. The height and width in pixels, the bit depth (8 bits per pixel is usual), and the number of channels (3 for RGB color, 1 for grayscale).
Lets assume the image is is 8 bits per pixel, has height h, width w, and is grayscale.
Begin by allocating memory for a new image IplImage* frame = cvCreateImage(cvSize(w, h), 8, 1);
Then, in your loop:
while(getImages) {
// obtain 1-D array of Row-Wise 8 bit pixel values from camera API and decoding if necessary
frame->imageData = pointer to pixel values
// process if you want
// display if you want
}
cvReleaseImage(&frame)
Make sure you do not reallocate memory in each iteration of the loop, just do it once, and be nice and deallocate the frame before the program ends
Upvotes: 2
Reputation: 96119
In addition to rossb83's excellent answer - if you are getting greyscale data from the camera you will have to convert it to 8UC3 (8bit three channel) to display it with showWindow. See cvtColor or just do it yourself with the raw pixel access.
Upvotes: 1