Video files in opencv

前端 未结 4 840
南方客
南方客 2021-02-04 22:37

I want to read video file(.avi or .mov) and detect motion and edges using Opencv.Can u help me with code?I want to create a GUI in which we can select the video file,then we can

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 23:21

    This works for me, I'm using AVIfiles. Call video withe filename, in your main-loop get the next frame and shutdown before terminating or changing to another video.

    IplImage  *videoframe;
    int videoFps;    
    CvCapture *videoCapture=NULL;
    
    int video(char *videoFile) {
        int       key;
        /* load the AVI file */
        videoCapture = cvCaptureFromAVI( videoFile );
        /* always check */
        if( !videoCapture )
            return 0;    
        /* get fps, needed to set the delay */
        videoFps = ( int )cvGetCaptureProperty( videoCapture, CV_CAP_PROP_FPS );
        /* display video */
        cvNamedWindow( "video", 0 );
    }
    
    void videoNext() {
            if ( ! videoCapture ) return;
            videoframe = cvQueryFrame( videoCapture );
            if( !videoframe ) return;
            cvShowImage( "video", videoframe );
            /* quit if user press 'q' */
            int key = cvWaitKey( 1000 / videoFps );
    }
    
    void videoShutdown() {
        /* free memory */
        cvReleaseCapture( &videoCapture );
        cvDestroyWindow( "video" );
        return;
    }
    

    Note: Opencv doesn't support audio playback On how to use ffmmpeg with opencv see audio-output-with-video-processing-with-opencv

提交回复
热议问题