Beispiel #1
0
def main():
    if len(sys.argv) > 1:

        if sys.argv[1].startswith("--cascade="):
            cascade_name = sys.argv[1][ len("--cascade="): ]
            if len(sys.argv) > 2:
                input_name = sys.argv[2]

        elif sys.argv[1] == "--help" or sys.argv[1] == "-h":
            print "Usage: facedetect --cascade=\"<cascade_path>\" [filename|camera_index]\n" 
            sys.exit(-1)

        else:
            input_name = sys.argv[1]
    
    # Global Variables
    from faceDetect import cascade, input_name

    if not cascade:
        print "ERROR: Could not load classifier cascade"
        sys.exit(-1)
    

    if input_name.isdigit():
        capture = cvCreateCameraCapture( int(input_name) )
    else:
        capture = cvCreateFileCapture( input_name )

    cvNamedWindow( "result", 1 )

    if( capture ):
        frame_copy = None
        while True: 
            frame = cvQueryFrame( capture )
            if( not frame ):
                break;
            if( not frame_copy ):
                frame_copy = cvCreateImage( cvSize(frame.width,frame.height),
                                            IPL_DEPTH_8U, frame.nChannels )
            if( frame.origin == IPL_ORIGIN_TL ):
                cvCopy( frame, frame_copy )
            else:
                cvFlip( frame, frame_copy, 0 )
            
            detect_and_draw( frame_copy )

            if( cvWaitKey( 10 ) >= 0 ):
                break;

    else:
        image = cvLoadImage( input_name, 1 )

        if( image ):
        
            detect_and_draw( image )
            cvWaitKey(0)
        
    cvDestroyWindow("result")
Beispiel #2
0
def main():
    if len(sys.argv) > 1:

        if sys.argv[1].startswith("--cascade="):
            cascade_name = sys.argv[1][ len("--cascade="): ]
            if len(sys.argv) > 2:
                input_name = sys.argv[2]

        elif sys.argv[1] == "--help" or sys.argv[1] == "-h":
            print "Usage: facedetect --cascade=\"<cascade_path>\" [filename|camera_index]\n" 
            sys.exit(-1)

        else:
            input_name = sys.argv[1]
    
    # Global Variables
    from faceDetect import cascade, input_name

    if not cascade:
        print "ERROR: Could not load classifier cascade"
        sys.exit(-1)
    

    if input_name.isdigit():
        capture = CreateCameraCapture( int(input_name) )
    else:
        capture = CreateFileCapture( input_name )

    NamedWindow( "result", 1 )

    if( capture ):
        frame_copy = None
        while True: 
            frame = QueryFrame( capture )
            if( not frame ):
                break;
            if( not frame_copy ):
                frame_copy = CreateImage( GetSize(frame),
                                            IPL_DEPTH_8U, frame.nChannels )
            if( frame.origin == IPL_ORIGIN_TL ):
                Copy( frame, frame_copy )
            else:
                Flip( frame, frame_copy, 0 )
            
            detect_and_draw( frame_copy )

            if( WaitKey( 10 ) >= 0 ):
                break;

    else:
        image = LoadImage( input_name, 1 )

        if( image ):
        
            detect_and_draw( image )
            WaitKey(0)
        
    DestroyWindow("result")