Video sequence of the buckle, in the area of the buckle for human eye detection

Source: Internet
Author: User

Code Features:
1. Can turn on the video frame to display, press any key except ESC to display
2. Mouse on the video slide animation rectangle to determine the human eye detection range

3. Press ESC to confirm the rectangle range, destroy the window and perform human eye detection

FindEyeInVideo.cpp: Defines the entry point of the console application. Cxcore.lib cv.lib ml.lib cvaux.lib highgui.lib cvcam.lib#include "stdafx.h" #include "cv.h" #include "highgui.h" # Include "time.h"//mouse drag flag bool Check_line_state = false;iplimage* tmpimg = null;iplimage* grayframe = NULL; Cvrect Roi_rect; Cvpoint p1,p2;//human eye detection sequence cvmemstorage* storage = cvcreatememstorage (0); cvhaarclassifiercascade* cascade = (cvhaarclassifiercascade*) cvload ("Haarcascade_eye.xml", 0, 0, 0); void On_mouse4 ( int event, int x,int y,int flags,void* param) {int thickness = 2;if (event==cv_event_lbuttondown) {//current mouse position (x, y) roi_rect.x = x; Roi_rect.y = Y;check_line_state = true;} else if (check_line_state&&event==cv_event_mousemove)//mouse state {cvcopy (grayframe,tmpimg);p 1=cvpoint (ROI_ RECT.X,ROI_RECT.Y);p 2=cvpoint (x, y); Roi_rect.width = ABS (p1.x-p2.x); Roi_rect.height = ABS (P1.Y-P2.Y), Cvrectangle (Tmpimg,p1,p2,cv_rgb (0,255,150), thickness,cv_aa,0), CvShowImage (" Image ", tmpimg);} else if (check_line_state&&event==cv_event_lbuttonup) {check_line_state= false;}} void Decode (CONST char* filename) {cvcapture * capture = cvcreatefilecapture (filename); iplimage* frame = Cvqueryframe (ca pture); char filepath[200]={0};int n = 0;int iconfirm = 0; cvseq* eye;iplimage* img;clock_t start,finish;tmpimg = Cvcreateimage (Cvsize (Frame->width, Frame->height), Frame->depth, 1); grayframe = Cvcreateimage (Cvsize (Frame->width, Frame->height), frame->depth, 1); while (     FRAME) {//Turn grayscale//Invert picture Cvflip (frame, NULL, 0); Cvcvtcolor (Frame,grayframe,cv_bgr2gray);//Set the good face area after pressing ESC to let the program automatically detect if (0 = = iconfirm) {cvshowimage ("image", Grayframe), if (cvwaitkey (0) = =) {iconfirm = 1;cvdestroywindow ("image"); Start=clock ();}} else{//set face Roicvsetimageroi (Grayframe, roi_rect); img = Cvcreateimage (cvsize (Roi_rect.width, Roi_rect.height), Grayframe->depth, Grayframe->nchannels); Cvcopy (grayframe,img);//sprintf (FilePath, "Faceresult//%d.bmp", N) //cvsaveimage (FilePath, IMG);//Search in the cutout area for the human eye = Cvhaardetectobjects (IMG, cascade, Storage, 1.2, 3, 0, Cvsize (25,25)); 2!= eye->total) goto NEXT; Roi_rect.x + = ((cvrect*) Cvgetseqelem (eye, 0))->x-20; Roi_rect.y + = ((cvrect*) Cvgetseqelem (eye, 0))->y-20; Roi_rect.width = ((cvrect*) Cvgetseqelem (eye, 0))->width + 40; Roi_rect.height = ((cvrect*) Cvgetseqelem (eye, 0))->height + 40;//cvresetimageroi (img);//cvsetimageroi (IMG, * ( cvrect*) Cvgetseqelem (eye, 0));  sprintf (FilePath, "Eyeresult//%d.bmp", N);//cvsaveimage (FilePath, IMG); Cvresetimageroi (IMG); Next:cvresetimageroi (Grayframe), Cvreleaseimage (&img);p rintf ("%d\n", n++);} frame = Cvqueryframe (capture);} finish = Clock ();d ouble totaltime= (double) (Finish-start)/clocks_per_sec/n;printf ("\ nthe run time for this program is%lf\n", totaltime); GetChar (); Cvreleasecapture (&capture); Cvreleaseimage (&tmpimg); Cvreleaseimage (&grayframe);} int main () {Roi_rect.x=roi_rect.y=0;cvnamedwindow ("image", cv_window_autosize), Cvsetmousecallback ("image", On_ MOUSE4);D Ecode (".. \\.. \\DecodeFrame\\ Mobile day. avi ");




Video sequence of the buckle, in the area of the buckle for human eye detection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.