Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- under c/c++-->general-->additional include directories-->C:OpenCV2.3buildinclude;C:OpenCV2.3buildincludeopencv2;C:OpenCV2.3buildincludeopencv;C:OpenCV2.3opencvdatahaarcascades
- under linker-->general-->additional library directories-->C:OpenCV2.3buildx86vc9lib;C:OpenCV2.3opencvdatahaarcascades;%(AdditionalLibraryDirectories)
- under linker-->input-->additional dependencies--> added opencv_core230.lib;opencv_highgui230.lib;opencv_objdetect230.lib
- under debugging-->command arguments -->added --cascade="C:/Program Files/OpenCV/data/haarcascades/haarcascade_frontalface_alt.xml"testimg.jpg
- #include <cv.h>
- #include <highgui.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- #include <math.h>
- #include <float.h>
- #include <limits.h>
- #include <time.h>
- #include <ctype.h>
- // Create memory for calculations
- static CvMemStorage* storage = 0;
- // Create a new Haar classifier
- static CvHaarClassifierCascade* cascade = 0;
- // Function prototype for detecting and drawing an object from an image
- void detect_and_draw( IplImage* image );
- // Create a string that contains the cascade name
- const char* cascade_name = "haarcascade_frontalface_alt.xml";
- /* "haarcascade_profileface.xml";*/
- // Main function, defines the entry point for the program.
- int main( int argc, char** argv )
- {
- // Structure for getting video from camera or avi
- CvCapture* capture = 0;
- // Images to capture the frame from video or camera or from file
- IplImage *frame, *frame_copy = 0;
- /* IplImage* img = cvLoadImage( "testimg.jpg" );
- cvNamedWindow( "MyJPG", CV_WINDOW_AUTOSIZE );
- cvShowImage("MyJPG", img);
- cvWaitKey(0);
- cvReleaseImage( &img );
- cvDestroyWindow( "MyJPG" );
- */
- // Used for calculations
- int optlen = strlen("--cascade=");
- // Input file name for avi or image file.
- const char* input_name;
- // Check for the correct usage of the command line
- if( argc > 1 && strncmp( argv[1], "--cascade=", optlen ) == 0 )
- {
- cascade_name = argv[1] + optlen;
- input_name = argc > 2 ? argv[2] : 0;
- }
- else
- {
- fprintf( stderr,
- "Usage: facedetect --cascade="<cascade_path>" [filename|camera_index]n" );
- return -1;
- /*input_name = argc > 1 ? argv[1] : 0;*/
- }
- // Load the HaarClassifierCascade
- cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
- // Check whether the cascade has loaded successfully. Else report and error and quit
- if( !cascade )
- {
- fprintf( stderr, "ERROR: Could not load classifier cascaden" );
- return -1;
- }
- // Allocate the memory storage
- storage = cvCreateMemStorage(0);
- // Find whether to detect the object from file or from camera.
- if( !input_name || (isdigit(input_name[0]) && input_name[1] == '