user2858676
user2858676

Reputation: 1

keyboard input to save image detected from video stream in opencv

I was trying to do facial recognition using opencv and save the image detected in the cvRect when an input from the keyboard(in my case, when "c" on the keyboard is pressed, an image should be created with the detected face in the folder. ) However, I guess the interrupt (cvWaitKey()) is giving me lots of problems and there is no response from the system. Would really appreciate your input in this area!

The code is here:

char d = cvWaitKey(33);

if (d==67) // if the keyboard c is pressed
{   
    // r is the cvRect created for the face detected
    cvSetImageROI(img, cvRect(pt1.x,pt1.y,r->width,r->height));

    //img is the video frame passed in here
    IplImage* img2 = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);

    cvCopy(img, img2, NULL);

    cvResetImageROI(img);

    cvSaveImage("roi.jpg",img2);
}

The code before this will be very standard face detection from webcam. And it works. thanks!

Upvotes: 0

Views: 986

Answers (1)

MSalters
MSalters

Reputation: 179877

67? It's clearer to write 'C'. That would also have shown you the real problem: you probably meant 'c'

Upvotes: 2

Related Questions