Reading a video with openCV

前端 未结 3 739
清歌不尽
清歌不尽 2020-12-20 16:18

I have a video engine2.avi that I want to read and show with openCV. Here\'s my code:

#include 
#include 

        
3条回答
  •  余生分开走
    2020-12-20 16:48

    If you are just looking out for displaying the video, here's the code that worked for me, Please check if it helps you in any way.

    #include 
    #include 
    int main(){
    CvCapture *camera=cvCaptureFromFile("C:\\test.avi");
    if (camera==NULL)
        printf("camera is null\n");
    else
        printf("camera is not null");
    
    cvNamedWindow("img");
    while (cvWaitKey(10)!=atoi("q")){
        double t1=(double)cvGetTickCount();
        IplImage *img=cvQueryFrame(camera);
        /*if(img){
            cvSaveImage("C:/opencv.jpg",img);
        }*/
        double t2=(double)cvGetTickCount();
        printf("time: %gms  fps: %.2g\n",(t2-t1)/(cvGetTickFrequency()*1000.), 1000./((t2-t1)/(cvGetTickFrequency()*1000.)));
        cvShowImage("img",img);
    }
    cvReleaseCapture(&camera);
    }
    

    Hope this helps you.

提交回复
热议问题