Skip to content

Commit

Permalink
correction module enhanced with better navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ekincanufuktepe committed Oct 4, 2020
1 parent a0bf57f commit 7a73b3b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 9 deletions.
121 changes: 121 additions & 0 deletions correctionFeature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import cv2
import sys

#do not forget to change the three variables below
video_source = "/video/%04d.png"
groundtruth_report_dir = "/foo1/bar1.txt"
reviewed_GT_report_dir = "/foo1/bar2.txt"

def report_reviewedGT(ground_truth_data):
reviewed_GT_file = open(reviewed_GT_report_dir, "w")

for key in sorted(ground_truth_data.keys()):
reviewed_GT_file.write(str(ground_truth_data[key][0])+" "+str(ground_truth_data[key][1])+" "+str(ground_truth_data[key][2])+" "+str(ground_truth_data[key][3])+"\n")

reviewed_GT_file.close()


if __name__ == '__main__':
frameNumber = 0
editCount = 0
#set Ground truth bounding box coordinate text file
ground_truth_file = open(groundtruth_report_dir, "r")

#set Tracker bounding box coordinate text file
ground_truth_data = {}
tracker_data = {}
gtf_line = ground_truth_file.readline()

counter = 0
# Parse ground truth and tracker bounding box files
while gtf_line:
ground_truth_data[counter] = gtf_line.split()[0:]
counter = counter + 1
gtf_line = ground_truth_file.readline()

# Read video
video = cv2.VideoCapture(video_source)
n_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))

while True:
ok, frame = video.read()
if (frameNumber) < counter:
p1_g = (int(ground_truth_data[frameNumber][0]), int(ground_truth_data[frameNumber][1]))
p2_g = (int(ground_truth_data[frameNumber][0]) + int(ground_truth_data[frameNumber][2]), int(ground_truth_data[frameNumber][1]) + int(ground_truth_data[frameNumber][3]))
cv2.putText(frame, "Frame number: " + str('{0:04}'.format(frameNumber)), (100,80),cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2 )
cv2.rectangle(frame, p1_g, p2_g, (0,255,0), 2, 1)
print('#' + str('{0:04}'.format(frameNumber)))
if not ok:
break

# Start timer
timer = cv2.getTickCount()

# Update tracker
# Calculate Frames per second (FPS)
fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer);
# Display result
cv2.imshow("pyTAG", frame)
# Exit if ESC pressed
k = cv2.waitKey(1) & 0xff
if k == 32 :
restart = True
#ok, frame = video.read()

while video.isOpened():
cv2.putText(frame, "Frame number: " + str('{0:04}'.format(frameNumber)), (100,80),cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2 )
# Read video capture
#ret, frame = video.read()

# show one frame at a time
key = cv2.waitKey(0)
while key not in [32, ord('n'), ord('b'), ord('a'), ord('e')]:
key = cv2.waitKey(0)

if key == ord('n'):
print(key)
if frameNumber < n_frames-1:
frameID = frameNumber
frameNumber = frameNumber + 1
p1_g = (int(ground_truth_data[frameNumber][0]), int(ground_truth_data[frameNumber][1]))
p2_g = (int(ground_truth_data[frameNumber][0]) + int(ground_truth_data[frameNumber][2]), int(ground_truth_data[frameNumber][1]) + int(ground_truth_data[frameNumber][3]))
video.set(1,frameNumber)
ret, frame = video.read()
cv2.putText(frame, "Frame number: " + str('{0:04}'.format(frameNumber)), (100,80),cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2 )
cv2.rectangle(frame, p1_g, p2_g, (0,255,0), 2, 1)
else:
break
if key == ord('b'):
print(key)
if n_frames >= frameNumber and frameNumber != 0:
frameID = frameNumber
frameNumber = frameNumber - 1
p1_g = (int(ground_truth_data[frameNumber][0]), int(ground_truth_data[frameNumber][1]))
p2_g = (int(ground_truth_data[frameNumber][0]) + int(ground_truth_data[frameNumber][2]), int(ground_truth_data[frameNumber][1]) + int(ground_truth_data[frameNumber][3]))
video.set(1,frameNumber)
ret, frame = video.read()
cv2.putText(frame, "Frame number: " + str('{0:04}'.format(frameNumber)), (100,80),cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2 )
cv2.rectangle(frame, p1_g, p2_g, (0,255,0), 2, 1)
if key == ord('e'):
break
if key == 32:
editCount = editCount + 1
bbox = cv2.selectROI(frame, False)
coordinate = '{0} {1} {2} {3}'.format(int(bbox[0]),int(bbox[1]),int(bbox[2]),int(bbox[3]))
if(str(coordinate) != "0 0 0 0"):
ground_truth_data[frameNumber] = (str(coordinate)+"\n").split()[0:]
else:
coordinate = "0 0 0 0"
ground_truth_data[frameNumber] = (str(coordinate)+"\n").split()[0:]
print(str(ground_truth_data[frameNumber]))
cv2.destroyWindow("ROI selector")
p1_g = (int(ground_truth_data[frameNumber][0]), int(ground_truth_data[frameNumber][1]))
p2_g = (int(ground_truth_data[frameNumber][0]) + int(ground_truth_data[frameNumber][2]), int(ground_truth_data[frameNumber][1]) + int(ground_truth_data[frameNumber][3]))
video.set(1,frameNumber)
cv2.putText(frame, "Frame number: " + str('{0:04}'.format(frameNumber)), (100,80),cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2 )
cv2.rectangle(frame, p1_g, p2_g, (0,255,0), 2, 1)
# Display each frame
cv2.imshow("pyTAG", frame)
frameNumber = frameNumber + 1
print("Total corrections: "+str(editCount))
report_reviewedGT(ground_truth_data)
6 changes: 3 additions & 3 deletions pyTAG.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def reinit_tracker(restart,frameNumber,video):
# Tracking failure
cv2.putText(frame, "The tracker has failed, please reinitialise", (100,80), cv2.FONT_HERSHEY_SIMPLEX, 0.75,(0,0,255),2)
restart = True
cv2.destroyWindow("ITAGGen")
cv2.destroyWindow("pyTAG")
print ("The tracker failed on frame number: " + str('{0:04}'.format(frameNumber)))
ok, frame = video.read()
reinit_tracker(restart,frameNumber,video)
Expand All @@ -98,7 +98,7 @@ def reinit_tracker(restart,frameNumber,video):
cv2.putText(frame, "Frame number: " + str('{0:04}'.format(frameNumber)), (100,80),cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2 )

# Display result
cv2.imshow("ITAGGen", frame)
cv2.imshow("pyTAG", frame)

# Exit if ESC pressed
k = cv2.waitKey(1) & 0xff
Expand Down Expand Up @@ -184,7 +184,7 @@ def reinit_tracker(restart,frameNumber,video):
#traker_bounding_box_dictionary[frameID] = "0 0 0 0"
break
# Display each frame
cv2.imshow("ITAGGen", frame)
cv2.imshow("pyTAG", frame)

#cv2.destroyWindow("ROI selector")
reinit_tracker(restart,frameNumber,video)
Expand Down
8 changes: 4 additions & 4 deletions reviewGT.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import sys

#do not forget to change the three variables below
video_source = '/myVideoSource/highview2_frame%05d.jpg'
groundtruth_report_dir = '/myGTReport/Desktop/gt_reportx.txt'
reviewed_GT_report_dir = '/myReviewedGTReports/reviewed_gt_report.txt'
video_source = "/video/%04d.png"
groundtruth_report_dir = "/foo1/bar1.txt"
reviewed_GT_report_dir = "/foo1/bar2.txt"

ground_truth_data = {}
tmp_ground_truth_data = {}
Expand Down Expand Up @@ -55,7 +55,7 @@ def report_reviewedGT():

cv2.putText(frame, "Frame number: " + str('{0:04}'.format(frameNumber)), (100,80),cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2 )
cv2.imshow("Tracking",frame)
k = cv2.waitKey(500) & 0xff
k = cv2.waitKey(1000) & 0xff
if k == 32:
bbox = cv2.selectROI(frame, False)
coordinate = '{0} {1} {2} {3}'.format(int(bbox[0]),int(bbox[1]),int(bbox[2]),int(bbox[3]))
Expand Down
4 changes: 2 additions & 2 deletions trackerEvaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#do not forget to change the three variables below
video_source = "/video/%04d.png"
groundtruth_report_dir = "/foo1/bar1.txt"
tracker_report_dir = "/foo2/bar2.txt"
tracker_report_dir = "/foo1/bar2.txt"

if __name__ == '__main__':
frameNumber = 0
Expand Down Expand Up @@ -62,7 +62,7 @@

cv2.putText(frame, "Frame number: " + str('{0:04}'.format(frameNumber)), (100,80),cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2 )
cv2.imshow("Tracking",frame)
k = cv2.waitKey(50) & 0xff
k = cv2.waitKey(250) & 0xff
if k == 32:
bbox = cv2.selectROI(frame, False)
cv2.destroyWindow("ROI selector")
Expand Down

0 comments on commit 7a73b3b

Please sign in to comment.