How to play and detect an object using captured video in background subtractor model?

后端 未结 1 1364
予麋鹿
予麋鹿 2021-01-24 20:40

everyone.! I am using opencv2.4.2. actually I am doing project on object detection. I tried using BackgroundSubtractorMOG model. But I am not able to load video file

相关标签:
1条回答
  • 2021-01-24 21:05

    The video loading in opencv works for me. To load a video you can try something like this. Once you have captured frame you either do processing in the loop or can call a separate function.

    std::cout<<"Video File "<<argv[1]<<std::endl;
    
    cv::VideoCapture input_video(argv[1]);
    
    namedWindow("My_Win",1);
    
    Mat cap_img;
    
    while(input_video.grab())
    {
       if(input_video.retrieve(cap_img))
       {
         imshow("My_Win", cap_img);
         /* Once you have the image do all the processing here */
         /* Or Call your image processing function */
         waitKey(1);
    
       }
    }
    

    or You can do something

    int main(int argc, char*argv[])
    {
    
        char *my_file = "C:\\vid_an2\\desp_me.avi";
        std::cout<<"Video File "<<my_file<<std::endl;
        cv::VideoCapture input_video;
    
        if(input_video.open(my_file))
        {
             std::cout<<"Video file open "<<std::endl;
        }
        else
        {
            std::cout<<"Not able to Video file open "<<std::endl;
    
        }
        namedWindow("My_Win",1);
        namedWindow("Segemented", 1);
        Mat cap_img;
        for(;;)
        {
             input_video >> cap_img;
             imshow("My_Win", cap_img);
              waitKey(0);
        }
       return 0;
     }
    
    0 讨论(0)
提交回复
热议问题