C++主函數參數

學習C++主函數的參數輸入,用於從command line中讀取參數,下面以讀取視頻文件爲例進行說明

#include <iostream>
#include <fstream>
#include <string>
#include <opencv2/opencv.hpp>

int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr << "usage: play_video <video_path>" << std::endl;
        return -1;
    }

    std::string video_path = argv[1];
    // check video file exist or not
    std::ifstream image_file(video_path);
    if (!image_file.is_open()) {
        std::cerr << "Video file not exist!" << std::endl;
        return -1;
    }

    // VideoCapture
    cv::VideoCapture cap(video_path);
    if (!cap.isOpened()) {
        std::cerr << "Open Video Failed!" << std::endl;
        return -1;
    }

    // Video Processing code here
    // TODO

    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章