Skip to content

Commit

Permalink
Merge branch 'output-dir'
Browse files Browse the repository at this point in the history
* output-dir:
  Document the output-directory parameter.
  Write output to the correct output directory.
  Add an output directory to the output path generator.
  • Loading branch information
hainesr committed Dec 2, 2015
2 parents f3d5f60 + 998cb71 commit 057fc6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ Combine [CppMT][cmt] object tracking data with the original video for verificati
This program takes a video and associated object tracking data output from [CppMT][cmt] (using the `--output-file` switch) and combines the two, overlaying the bounding box outline and centre point in the output video.

```shell
$ cmt-replay <video-input> <data-input>
$ cmt-replay <video-input> <data-input> [output-directory]
```

The output video file is named automatically using the input video filename to ensure that a combination of codec and container that OpenCV can write to is used. For example, an input video file named `video.mp4` will produce an output video file named `video_out.avi`. OpenCV can read the mp4 container but cannot write to it.

If the `output-directory` parameter is supplied the output video file will be written to that directory, otherwise it will be written to the same directory as the input video file.

## Dependencies

CppMT-replay requires [OpenCV][ocv] version 2.4 to build and run. It is built using [CMake][cmk] version 2.6 or later.
Expand Down
15 changes: 12 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ void draw_bbox_centre(Mat frame, vector<float> bbox) {
circle(frame, centre, 2, draw_colour);
}

string output_filename(string input_filename) {
string output_filename(string input_filename, string output_dir="") {
int dot = input_filename.find_last_of('.');
return input_filename.substr(0, dot) + "_out.avi";
int out_len = output_dir.length();

if(out_len > 0 && !(0 == output_dir.compare((out_len - 1), 1, "/"))) {
output_dir += '/';
}

return output_dir + input_filename.substr(0, dot) + "_out.avi";
}

int main(int argc, char **argv) {
Expand All @@ -92,8 +98,11 @@ int main(int argc, char **argv) {
ifstream csv(argv[2]);
get_next_line_tokens(csv);

// Generate the full output filename.
string out_path = (argc == 4) ? output_filename(argv[1], argv[3]) : output_filename(argv[1]);

// Open output video file.
VideoWriter out(output_filename(argv[1]), CV_FOURCC('X', 'V', 'I', 'D'), fps, size, true);
VideoWriter out(out_path, CV_FOURCC('X', 'V', 'I', 'D'), fps, size, true);
if(!out.isOpened()) {
cerr << "Cannot open output video." << endl;
return 1;
Expand Down

0 comments on commit 057fc6d

Please sign in to comment.