Commit 9fce2aa2 authored by Timothy Callemein's avatar Timothy Callemein

Add video output option

parent db12cff8
......@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
Json::Value json_data = Json::Value();
if (argc < 6) {
std::cerr << "Usage: " << argv[0] << " <input_names_file> <input_cfg_file> <input_weights_file> <videofile> <detections_out_file>" << std::endl;
std::cerr << "Usage: " << argv[0] << " <input_names_file> <input_cfg_file> <input_weights_file> <videofile> <detections_out_file> [<video_out_file>]" << std::endl;
return -1;
}
......@@ -113,6 +113,7 @@ int main(int argc, char *argv[])
std::string videofile(argv[4]);
std::string detections_out_file(argv[5]);
if (!cap.open(videofile, cv::CAP_FFMPEG)) {
std::cerr << "Could not open video file: " << videofile << std::endl;
return -1;
......@@ -120,6 +121,19 @@ int main(int argc, char *argv[])
int image_width = cap.get(cv::CAP_PROP_FRAME_WIDTH);
int image_height = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
float image_fps = cap.get(cv::CAP_PROP_FPS);
cv::VideoWriter writer;
if (argc == 7) {
std::string videofile_out(argv[6]);
int codec = cv::VideoWriter::fourcc('X', '2', '6', '4');
writer.open(videofile_out, codec, image_fps, cv::Size(image_width, image_height));
if (!cap.open(videofile)) {
std::cerr << "Could not open video file" << std::endl;
return -1;
}
}
if (!detector.setup(input_names_file,
input_cfg_file,
......@@ -162,6 +176,14 @@ int main(int argc, char *argv[])
detector.get_detections(detections);
// draw bounding boxes
Darknet::image_overlay(detections, cvimage);
// Write to file if output is set
if (argc == 7){
writer.write(cvimage);
}
if (detections.size() > 0 ){
json_data[std::to_string(i)] = detections_to_json(detections);
}
......@@ -174,6 +196,12 @@ int main(int argc, char *argv[])
i++;
}
// Write to file if output is set
if (argc == 7){
writer.release();
}
write_json(json_data, detections_out_file);
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment