Exemplo n.º 1
0
	MyClass(int width,int height) {pGMM=cvCreatePixelBackgroundGMM(width,height); mexPrintf("MyClass created.\n"); }
Exemplo n.º 2
0
// 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;

    // Input file name for avi or image file.
    const char* input_name;

    // Check for the correct usage of the command line
    if( argc <= 2 )
        input_name = argv[1];
    else
    {
        fprintf( stderr,
        "Usage: BSubtraction Filename\n" );
        system ("pause"); // MS-DOS pause command
        return -1;
        /*input_name = argc > 1 ? argv[1] : 0;*/
    }

    // Configure output file
    OutFile = fopen("svgout.svg", "w+");
    
    
    // Initialize Face detection
    // Load the HaarClassifierCascade
    cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
    
    
    // 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] == '\0') )
        capture = cvCaptureFromCAM( !input_name ? 0 : input_name[0] - '0' );
    else
        capture = cvCaptureFromAVI( input_name ); 

    // Create a new named window with title: result
    cvNamedWindow( "result", 1 );
    cvNamedWindow("original", 1);

    // Find if the capture is loaded successfully or not.

    // If loaded succesfully, then:
    if( capture )
    {
        
        // Capture from the camera.
        for(;;)
        {
            // Capture the frame and load it in IplImage
            if( !cvGrabFrame( capture ))
                break;
            frame = cvRetrieveFrame( capture );

            // If the frame does not exist, quit the loop
            if( !frame )
                break;

            // Allocate framecopy as the same size of the frame
            if( !frame_copy )
                frame_copy = cvCreateImage( cvSize(frame->width,frame->height),
                                            IPL_DEPTH_8U, frame->nChannels );

            // Reserve Memory for background subtraction if you haven't already
            pGMM = (pGMM==0) ? cvCreatePixelBackgroundGMM(frame->width,frame->height)
                           : pGMM;
            pGMM->fAlphaT = .005f;

            // Check the origin of image. If top left, copy the image frame to frame_copy. 
            if( frame->origin == IPL_ORIGIN_TL )
                cvCopy( frame, frame_copy, 0 );
            // Else flip and copy the image
            else
                cvFlip( frame, frame_copy, 0 );
            
            // Call the function to detect and draw the facees
            detect_and_draw( frame_copy );
            
            //system ("pause"); // MS-DOS pause command
            
            // Wait for a while before proceeding to the next frame
            if( cvWaitKey( 10 ) >= 0 )
                break;
        }

        // Release the images, and capture memory
        cvReleaseImage( &frame_copy );
        cvReleaseCapture( &capture );
    }else{// Assume the image to be lena.jpg, or the input_name specified
        const char* filename = input_name ? input_name : (char*)"test.jpg";
        singleframe = true;
        // Load the image from that filename
        IplImage* image = cvLoadImage( filename, 1 );
        // If Image is loaded succesfully, then:
        if( image ){
            pGMM = (pGMM==0) ? cvCreatePixelBackgroundGMM(image->width,image->height)
                           : pGMM;
            pGMM->fAlphaT = .005f;
            // Detect and draw the face
            detect_and_draw( image );

            // Release the image memory
            cvReleaseImage( &image );
        }
    }      

    
    // Destroy the window previously created with filename: "result"
    cvDestroyWindow("result");
    cvDestroyWindow("original");
    
    // release the background subtraction structure
    //cvReleasePixelBackgroundGMM(&pGMM);
    
    // write out terminal data and close your svg file
    page_svg_close(OutFile);    
    fclose(OutFile);    

    // return 0 to indicate successfull execution of the program
    return 0;
}