Skip to content
Snippets Groups Projects
Commit 7354ab80 authored by Schrödter, Tobias's avatar Schrödter, Tobias
Browse files

Best for comparison

parent e047d10d
No related branches found
No related tags found
1 merge request!146Update video-compare script
This commit is part of merge request !146. Comments created here will be created in the context of that merge request.
import argparse import argparse
from typing import Callable, List, Set, Tuple from typing import Callable, List, Set, Tuple
try: try:
import cv2 import cv2
except ImportError: except ImportError:
...@@ -99,8 +100,8 @@ class ComparisonVideoPlayer: ...@@ -99,8 +100,8 @@ class ComparisonVideoPlayer:
nearby_people_truth: List[int] = [] nearby_people_truth: List[int] = []
for person in self.test_trajectories: for person in self.test_trajectories:
if ( if (
seed_person.last_frame < person.first_frame seed_person.last_frame < person.first_frame
or seed_person.first_frame > person.last_frame or seed_person.first_frame > person.last_frame
): ):
continue continue
if seed_person.first_frame > person.first_frame: if seed_person.first_frame > person.first_frame:
...@@ -117,8 +118,8 @@ class ComparisonVideoPlayer: ...@@ -117,8 +118,8 @@ class ComparisonVideoPlayer:
nearby_people_test.append(person.id + 1) nearby_people_test.append(person.id + 1)
for person in self.truth_trajectories: for person in self.truth_trajectories:
if ( if (
seed_person.last_frame < person.first_frame seed_person.last_frame < person.first_frame
or seed_person.first_frame > person.last_frame or seed_person.first_frame > person.last_frame
): ):
continue continue
if seed_person.first_frame > person.first_frame: if seed_person.first_frame > person.first_frame:
...@@ -136,7 +137,7 @@ class ComparisonVideoPlayer: ...@@ -136,7 +137,7 @@ class ComparisonVideoPlayer:
return nearby_people_truth, nearby_people_test return nearby_people_truth, nearby_people_test
def play_video( def play_video(
self, start: int, end: int, draw_callback: Callable[[np.ndarray, int], None] self, start: int, end: int, draw_callback: Callable[[np.ndarray, int], None]
): ):
"""Plays the video from frame start to frame end, calling the draw_callback each frame """Plays the video from frame start to frame end, calling the draw_callback each frame
...@@ -155,57 +156,92 @@ class ComparisonVideoPlayer: ...@@ -155,57 +156,92 @@ class ComparisonVideoPlayer:
currFrame = start currFrame = start
self.stream.set(cv2.CAP_PROP_POS_FRAMES, start) self.stream.set(cv2.CAP_PROP_POS_FRAMES, start)
playing = True
while (k := cv2.waitKey(20)) != 110: while (k := cv2.waitKey(20)) != 110:
grabbed, frame = self.stream.read()
if not grabbed or currFrame > end:
self.stream.set(cv2.CAP_PROP_POS_FRAMES, start)
currFrame = start
_, frame = self.stream.read()
frame = cv2.copyMakeBorder( if not playing:
frame, if k == ord('a') or k == ord('d'):
self.border,
self.border,
self.border,
self.border,
cv2.BORDER_CONSTANT,
)
frame = cv2.remap(
frame,
self.map1,
self.map2,
cv2.INTER_LINEAR,
borderMode=cv2.BORDER_CONSTANT,
)
draw_callback(frame, currFrame) if k == ord('a'):
cv2.putText(frame, "Frame: {:7d}".format(currFrame), (50,100), cv2.FONT_HERSHEY_DUPLEX, 3, (0,0,255), 5, cv2.LINE_8) newFrame = max(currFrame - 1, start)
if k == ord('d'):
newFrame = min(currFrame + 1, end)
cv2.imshow("Comparison", frame) if newFrame <= currFrame:
self.stream.set(cv2.CAP_PROP_POS_FRAMES, newFrame)
currFrame += 1 currFrame = newFrame
_, frame = self.stream.read()
if k == ord('p'): frame = cv2.copyMakeBorder(
while cv2.waitKey(-1) != ord('p'): frame,
if k == ord('w'): self.border,
currFrame = currFrame+1 self.border,
if k == ord('s'): self.border,
currFrame = currFrame-1 self.border,
pass cv2.BORDER_CONSTANT,
)
frame = cv2.remap(
frame,
self.map1,
self.map2,
cv2.INTER_LINEAR,
borderMode=cv2.BORDER_CONSTANT,
)
draw_callback(frame, currFrame)
cv2.putText(frame, "Frame: {:7d}".format(currFrame), (50, 100), cv2.FONT_HERSHEY_DUPLEX, 3,
(0, 0, 255), 5, cv2.LINE_8)
cv2.imshow("Comparison", frame)
else:
grabbed, frame = self.stream.read()
if not grabbed or currFrame > end:
self.stream.set(cv2.CAP_PROP_POS_FRAMES, start)
currFrame = start
_, frame = self.stream.read()
frame = cv2.copyMakeBorder(
frame,
self.border,
self.border,
self.border,
self.border,
cv2.BORDER_CONSTANT,
)
frame = cv2.remap(
frame,
self.map1,
self.map2,
cv2.INTER_LINEAR,
borderMode=cv2.BORDER_CONSTANT,
)
draw_callback(frame, currFrame)
cv2.putText(frame, "Frame: {:7d}".format(currFrame), (50, 100), cv2.FONT_HERSHEY_DUPLEX, 3, (0, 0, 255),
5, cv2.LINE_8)
cv2.imshow("Comparison", frame)
currFrame += 1
if k == ord('p'):
playing = not playing
def drawPoints( def drawPoints(
self, self,
person: Person, person: Person,
currFrame: int, currFrame: int,
frame: np.ndarray, frame: np.ndarray,
color: Tuple[int], color: Tuple[int],
thickness: int, thickness: int,
): ):
if person.first_frame <= currFrame <= person.last_frame: if person.first_frame <= currFrame <= person.last_frame:
points = person.points points = person.points
for i in range(min(10, currFrame - person.first_frame)): for i in range(min(10, currFrame - person.first_frame)):
if i == 0:
continue
frame = cv2.circle( frame = cv2.circle(
frame, frame,
( (
...@@ -214,9 +250,13 @@ class ComparisonVideoPlayer: ...@@ -214,9 +250,13 @@ class ComparisonVideoPlayer:
), ),
thickness, thickness,
color, color,
-1, 1,
) )
for i in range(min(10, person.last_frame - currFrame)): for i in range(min(10, person.last_frame - currFrame)):
if i == 0:
continue
frame = cv2.circle( frame = cv2.circle(
frame, frame,
( (
...@@ -225,9 +265,27 @@ class ComparisonVideoPlayer: ...@@ -225,9 +265,27 @@ class ComparisonVideoPlayer:
), ),
thickness, thickness,
color, color,
-1, 1,
) )
marker = cv2.MARKER_CROSS
if color == (255, 0, 0):
marker = cv2.MARKER_TILTED_CROSS
frame = cv2.drawMarker(
frame,
(
int(points[currFrame].x + self.border),
int(points[currFrame].y + self.border),
),
color,
marker,
thickness=2,
line_type=cv2.LINE_AA
)
def visualize_people(self, idx_truth: int, idx_test: int): def visualize_people(self, idx_truth: int, idx_test: int):
tr = self.truth_trajectories[idx_truth - 1] tr = self.truth_trajectories[idx_truth - 1]
te = self.test_trajectories[idx_test - 1] te = self.test_trajectories[idx_test - 1]
...@@ -244,17 +302,18 @@ class ComparisonVideoPlayer: ...@@ -244,17 +302,18 @@ class ComparisonVideoPlayer:
truth = self.truth_trajectories[idx_truth - 1].points[currFrame] truth = self.truth_trajectories[idx_truth - 1].points[currFrame]
test = self.test_trajectories[idx_test - 1].points[currFrame] test = self.test_trajectories[idx_test - 1].points[currFrame]
diff = math.sqrt((truth.x - test.x)**2 + (truth.y - test.y)**2) diff = math.sqrt((truth.x - test.x) ** 2 + (truth.y - test.y) ** 2)
frame = cv2.putText(frame, "Diff: {:7.3f}".format(diff), (4100,100), cv2.FONT_HERSHEY_DUPLEX, 3, (0,0,255), 5, cv2.LINE_8) frame = cv2.putText(frame, "Diff: {:7.3f}".format(diff), (4100, 100), cv2.FONT_HERSHEY_DUPLEX, 3,
(0, 0, 255), 5, cv2.LINE_8)
self.play_video(start, end, draw) self.play_video(start, end, draw)
def visualize_many( def visualize_many(
self, self,
idxs_truth: List[int], idxs_truth: List[int],
idxs_test: List[int], idxs_test: List[int],
idx_seed: int, idx_seed: int,
is_seed_test: bool, is_seed_test: bool,
): ):
# Idea: Try out taking the first first and last last frame, as in two people? # Idea: Try out taking the first first and last last frame, as in two people?
if is_seed_test: if is_seed_test:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment