obendidi / Tracking-with-darkflow

Real-time people Multitracker using YOLO v2 and deep_sort with tensorflow
GNU General Public License v3.0
523 stars 174 forks source link

Change the video/csv output filename to handle inputs from relative path #36

Open hiankun opened 6 years ago

hiankun commented 6 years ago

I'm totally not familiar with pull request or relevant GitHub functions, so I decided to post my minor modification here.

Several days ago I was trying to run the code with a video as the input, but got some errors about writing the output video. After some tracking, I found the reason was the file name coded in darkflow/darkflow/net/help.py could not handle filenames from relative path.

The original output filename was 'output_{}'.format(file) and it could produce something like output_../..//RELATIVE/PATH/INPUT/VIDEO.avi and therefore caused problems.

So I changed the code as the following:

--- videoWriter = cv2.VideoWriter(
---     'output_{}'.format(file), fourcc, fps, (width, height))

+++ output_vid_file = 'output_{}'.format(os.path.basename(file))
+++ print('Saving output video to {}...'.format(output_vid_file))
+++ videoWriter = cv2.VideoWriter(output_vid_file, fourcc, fps, (width, height))

Also, to be consistent and make all the output files be in the same folder of run.py, I also modified the csv part as follows:

--- f = open('{}.csv'.format(file),'w')

+++ output_csv_file = 'output_{}.csv'.format( os.path.splitext( os.path.basename(file) )[0] )
+++ print('Saving output video to {}...'.format(output_csv_file))
+++ f = open(output_csv_file,'w')

Hope this will help.