• Opencv 简单视频播放器


    1. // C++ header and namespace  
    2. #include <iostream>  
    3. #include <string>  
    4. #include <cstdlib>  
    5. using namespace std;  
    6.   
    7. // Opencv header and namespace  
    8. #include <opencv2/core/core.hpp>  
    9. #include <opencv2/highgui/highgui.hpp>  
    10. #include <opencv2/imgproc/imgproc.hpp>  
    11. #include <opencv2/video/video.hpp>  
    12. using namespace cv;  
    13.   
    14. bool JumpToFrame(false);  
    15.   
    16. int main(int argc, char* argv[])  
    17. {     
    18.     //!< Check out Input video  
    19.     if (argc != 2)  
    20.     {  
    21.         cerr << "Usage: VideoPlayer.exe VideoFilename." << endl;  
    22.         exit(1);  
    23.     }  
    24.   
    25.     //!< Check out Open Video  
    26.     VideoCapture capture(argv[1]);  
    27.     if (!capture.isOpened())  
    28.     {  
    29.         return 1;  
    30.     }  
    31.   
    32. #pragma region InfoOfVideo  
    33.       
    34.     long    NumberOfFrame = static_cast<long>(capture.get(CV_CAP_PROP_FRAME_COUNT));  
    35.     double  HeightOfFrame = capture.get(CV_CAP_PROP_FRAME_HEIGHT);  
    36.     double  WidthOfFrame  = capture.get(CV_CAP_PROP_FRAME_WIDTH);  
    37.     double  FpsOfVideo    = capture.get(CV_CAP_PROP_FPS);     
    38.       
    39.     cout << "The name of the input video is " << argv[1] << "." << endl;  
    40.     cout << "NumberOfFrame : " << NumberOfFrame << endl;  
    41.     cout << "HeightOfFrame : " << HeightOfFrame << endl;  
    42.     cout << "WidthOfFrame  : " << WidthOfFrame << endl;  
    43.     cout << "FpsOfVieo     : " << FpsOfVideo << endl;  
    44.   
    45. #pragma endregion  
    46.   
    47.     // !< JumpToFrame function  
    48.     while (JumpToFrame)  
    49.     {  
    50.         double Position = 0.0;  
    51.         cout << "Please input the number of frame which you want jump to!" << endl;  
    52.         cin >> Position;  
    53.         capture.set(CV_CAP_PROP_POS_FRAMES, Position);  
    54.     }  
    55.   
    56.     // !< Delay between each frame in ms corresponds to video frame rate(fps)  
    57.     Mat frame;  
    58.     bool stop(false);  
    59.     int delay = 1000 / FpsOfVideo;  
    60.     namedWindow("Extracted Frame");  
    61.   
    62.     while (!stop)  
    63.     {  
    64.         //read next frame if any  
    65.         if (!capture.read(frame))  
    66.         {  
    67.             break;  
    68.         }  
    69.         imshow("Extracted Frame", frame);  
    70.         //introduce a delay or press key to stop  
    71.         if (waitKey(delay) >= 0)  
    72.         {  
    73.             stop = true;  
    74.         }  
    75.     }  
    76.   
    77.     // !< Close the video file.  
    78.     // Not required since called by destructor  
    79.     capture.release();  
    80.   
    81.     return 0;  
  • 相关阅读:
    Java实现寻找最小的k个数
    Java实现寻找最小的k个数
    foruok安晓辉的《程序员,你好哇》,都很不错
    DataSnap的如果网络断线,如何恢复?
    配置QSslConfiguration让客户端程序跳过本地SSL验证
    Linux升级OpenSSL版本
    FMX+Win32,窗口无法保持原样,应该是个bug
    [Nhibernate]二级缓存
    EventBus(事件总线)
    elasticsearch集群搭建实例
  • 原文地址:https://www.cnblogs.com/daochong/p/7954214.html
Copyright © 2020-2023  润新知