From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview + opencv

Hi,

 

I'm working on a project in LV 2009 and I'm trying to use an opencv dll for facetracking. The problem is that I keep getting an error massage (1097), and I can't figure out what the problem is. Here's the C code for the dll and the block diagram. When I start it, it asks for a webcam, but then it shots down. When I run the facedetection on a static image it works well, but it doesn't work with the webcam. I think the easiest solution could b if I could take a snapshot in labview, and then send the static image to the dll, but I couldn't manage to make the webcam snapshot static.

Could anyone help me?

Thanks,

botond

 the C code:

int __stdcall arc_3 (IMAQ_Image *LVImage, char* LVImagePtr,int LVLineWidth,int width, int height, bool key)
{
    CvCapture* capture = cvCaptureFromCAM(0);
    CvMemStorage* storage = cvCreateMemStorage(0);
    CvSeq* faces; CvSeq* eyes; CvSeq* mouth;
    ImageInfo *src;
    IplImage *frame;
    src=(ImageInfo *) LVImage->address;
    frame = cvCreateImageHeader( cvSize(width, height), IPL_DEPTH_8U, 1);
    frame->imageData = LVImagePtr;
    frame->widthStep = LVLineWidth;
    do{
    frame=cvQueryFrame(capture);
    faces = cvHaarDetectObjects( frame, cascade_face, storage,2.0, 3, 0, cvSize(70, 150), cvSize(300, 400)); //arcdetektálás
    CvRect *r = (CvRect*)cvGetSeqElem(faces, 0);
    cvRectangle(frame,cvPoint(r->x, r->y),cvPoint(r->x + r->width, r->y + r->height),CV_RGB(255, 0, 0), 1, 8, 0); //arcrajz
    cvSetImageROI(frame, cvRect(r->x, r->y + (r->height/5.5), r->width, r->height/3.0)); //region of interest
    cvClearMemStorage(storage);
    eyes = cvHaarDetectObjects(frame, cascade_eye, storage, 1.15, 3, 0, cvSize(35, 25), cvSize(60, 40)); //szemdetektálás
    CvRect *b = (CvRect*)cvGetSeqElem(eyes, 0);
    for(int i = 0; i < (eyes ? eyes->total : 0); i++ ) //szemek rajzolása
    {
        CvRect *e = (CvRect*)cvGetSeqElem(eyes, i);
        cvRectangle(frame,cvPoint(e->x, e->y),cvPoint(e->x + e->width, e->y + e->height),CV_RGB(255, 0, 0), 1, 8, 0);
    };
    cvSetImageROI(frame, cvRect(r->x + (r->width/4.0), r->y + (r->height/3.0), width/2.0, height/2.0));
    cvClearMemStorage(storage);
    mouth = cvHaarDetectObjects(frame, cascade_mouth, storage, 1.15, 3, 0, cvSize(25, 15), cvSize(100, 50)); //száj
    CvRect *m = (CvRect*)cvGetSeqElem(mouth, 0);
    cvRectangle(frame,cvPoint(m->x, m->y),cvPoint(m->x + m->width, m->y + m->height),CV_RGB(255, 255, 255), 1, 8, 0);
    *((ImageInfo *) LVImage->address)->imageStart=(ImageInfo *) frame->imageData;
    ((ImageInfo *) LVImage->address)->pixelsPerLine=frame->widthStep;*/
    cvClearMemStorage(storage);
    cvReleaseCapture(&capture);
    cvWaitKey (0);
    }while (key = true);
    cvReleaseCapture(&capture);
    return 0;
}

0 Kudos
Message 1 of 5
(5,220 Views)

Hello spilko botond,

 

If labview is shutting down when you call the dll it means the dll is being improperly called.  Click here for a knowledge base article on how to call dll's in Labview.  Also, the screenshot of the code you posted only shows a small portion of your code.  Could you post a more comprehensive screenshot of your code?

 

Thanks,

 

David A

Applications Engineer 

National Instruments

0 Kudos
Message 2 of 5
(5,177 Views)

Hi,

 

thanks for the help, I already checked and tried every variation of calling the dll... The problem is that this is basically a face detector program with a webcam, which means it should run continuously, but it doesn't. The dll gets data about the webcam picture (size, depth, etc.), because it needs them to create an exactly same kind of image than the webcams. When the dll part "starts", it asks for a camera, I tell it which one to use (obviously the same as for the LV part), but then it sends me the 1097 error code, and the program stops (labview does not shot down, but I have to restart it and I need to replug the camera a well). Th LV part works well, it has no trouble with opening or closeing the webcam session. I attached the hole block diagram. (I think the problem might be with the memory and the storage of the opencv, somehow it maybe use the same as the LV)

 

Thanks,

Botond Spilkó

0 Kudos
Message 3 of 5
(5,130 Views)

Hi,

 

it's me again, apparently it shots down now...

 

Thanks,

Botond Spilkó

0 Kudos
Message 4 of 5
(5,127 Views)

Is there some reason that you are using the IMAQ USB drivers? Those drivers are older, and likely what is causing the problem you are having with the .dll. Try installing Vision Acquisition Software and using the IMAQdx tools. IMAQdx is the modern equivalent of IMAQ USB. Hope that helps!

John B.
Embedded Networks R&D
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 5 of 5
(5,091 Views)