main.cpp ( File view )

  • By marque 2014-03-29
  • View(s):51
  • Download(s):6
  • Point(s): 2
			#include <iostream>

#include "constants.h"
#include "track_eye.h"

/**
 * @function main
 */
int main( int argc, const char** argv ) {

    CvCapture* capture;
    cv::CascadeClassifier face_cascade;
	
	cv::Mat frame;
    cv::Mat debugImage;
    cv::Point rightPupil, leftPupil;

    //-- 1. Load the cascades
    if( !face_cascade.load( face_cascade_name ) ){
 std::cerr << "--(!)Error loading" << std::endl; return -1; 
};
  
    cv::namedWindow(main_window_name,CV_WINDOW_NORMAL);
    cv::moveWindow(main_window_name, 400, 100);
    cv::namedWindow(face_window_name,CV_WINDOW_NORMAL);
    cv::moveWindow(face_window_name, 10, 100);
  
    //-- 2. Read the video stream
    int cameraNumber = 0;
    // Get access to the default camera.
	capture = cvCaptureFromCAM( cameraNumber );
    if ( capture == NULL) {

        std::cerr << "ERROR: Could not access the camera index " << cameraNumber <<  std::endl;
        exit(1);
    
}
    std::cout << "Loaded camera " << cameraNumber << "." << std::endl;
    
	int key_in = 0;
    std::vector<cv::Rect> faces;
	cv::Mat frame_gray;
	do {

        frame = cvQueryFrame( capture );
        if( true == frame.empty() ) {

           printf(" --(!) No captured frame -- Break!");
           break;
        
}
        // std::cout << "Dimensions: " << std::cout << frame.cols << ", " << frame.rows << std::endl;
		
		// mirror it
        cv::flip(frame, frame, 1);
        frame.copyTo(debugImage);
      
        //-- 3. Apply the classifier to the frame
		// If the input image is not grayscale, then convert the BGR or BGRA color image to grayscale.
		if (frame.channels() == 3) {

			cvtColor(frame, frame_gray, CV_BGR2GRAY);
		
}
		else if (frame.channels() == 4) {

			cvtColor(frame, frame_gray, CV_BGRA2GRAY);
		
}
		else {

			// Access the input image directly, since it is already grayscale.
			frame_gray = frame;
		
}
	    //-- Detect faces
	    face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE|CV_HAAR_FIND_BIGGEST_OBJECT, cv::Size(150, 150) );
  
	    for( unsigned int i = 0; i < faces.size(); i++ ) {

		    rectangle(debugImage, faces[i], 1234);
	    
}
	    //-- Show what you got
	    if (faces.size() > 0) {

		    trackEyes(frame_gray, faces[0], rightPupil, leftPupil);
	    
}
        imshow(main_window_name,debugImage);
      
         key_in = cv::waitKey(33);
    
} while (key_in != 27);

	cvDestroyWindow(main_window_name);
	cvDestroyWindow(face_window_name);
	cvReleaseCapture( &capture);
	exit(EXIT_SUCCESS);

}

			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
constants.h685.00 B2014-03-23 00:51
eye_track.sln879.00 B2014-01-12 12:47
eye_track.vcxproj5.52 kB2014-03-22 23:39
eye_track.vcxproj.filters1.49 kB2014-03-22 23:39
main.cpp2.52 kB2014-03-23 01:09
OPENCV_DEBUG.props883.00 B2014-01-14 18:35
OPENCV_RELEASE.props872.00 B2014-01-14 18:36
01.97 kB
haarcascade_frontalface_alt.xml923.86 kB2014-01-12 12:58
haarcascade_frontalface_alt_tree.xml3.48 MB2013-11-13 15:14
lbpcascade_frontalface.xml50.64 kB2013-11-13 15:14
track_eye.cpp6.28 kB2014-03-23 01:22
track_eye.h267.00 B2014-03-22 23:51
...
Sponsored links

main.cpp (550.50 kB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D