开发者

OpenCV how can i detect webcam and compare the local file to match face

The highlighted code demonstrate openCV framework is loaded in my C code and it render Police watching. Which is just to demonstrate it works very smooth and very clean code to write.

Target: My webCAM is connected in to the USB port. I would like to capture the live webcam image and match from a local file (/tmp/myface.png), if live webcam match with local file myface.png, it will show the text "Police watching"

My Questions to fix: 1) How can i now, capture my webCAM on this following cod开发者_JAVA百科e? 2) When the webCAM is captured, how can i load the file and find if it match, on match it shows that text only.

#include "cv.h"
#include "highgui.h"

int main() 
{
    CvPoint pt   = cvPoint( 620/4, 440/2 ); // width, height
    IplImage* hw = cvCreateImage(cvSize(620, 440), 8,3);  // width, height             
    CvFont font; // cvSet(hw,cvScalar(0,0,0)); // optional
    cvInitFont (&font, CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0, 0, 1, CV_AA);
    cvPutText  (hw, "Police watching", pt, &font, CV_RGB(150, 0, 150));        
    cvShowImage("Police watching", hw);     //cvNamedWindow("Police watching", 0); // optional
    cvWaitKey  (0);
}

Note: When this model will work i will practice this to convert in to JNI java model.


Capturing a video frame is simple just follow this example. The essential part is:

IplImage *img = cvLoadImage( argv[1], CV_LOAD_IMAGE_COLOR );
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
while ( 1 ) {
    IplImage* frame = cvQueryFrame( capture );
    //match(img,frame);
}
cvReleaseCapture( &capture );

The second part is probably much harder and depends on what exactly are you trying to do. If you want to simply compare images, you can use cvNorm. If you want face detection or face recognition you really need to know what are you doing.


This is how I get a webcam feed... (the code is in Python but is easily translated)

# create capture device
device = 0 # assume we want first device
capture = cv.CreateCameraCapture(0)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480)    

# check if capture device is OK
if not capture:
    print "Error opening capture device"
    sys.exit(1)

# capture the current frame
frame = cv.QueryFrame(capture)

if frame is None:
    break
    # mirror

cv.Flip(frame, None, 1)   

#Do face detection here

I think you'll have an incredibly hard time trying to match a face from a single file to a live video stream. Look into cv.HaarDetectObjects for some cool feature detection algorithms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜