學習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;
}