Skip to content

Commit b44dc28

Browse files
author
arch
committed
draw center tracking box point
1 parent f83e978 commit b44dc28

File tree

3 files changed

+66
-9
lines changed

3 files changed

+66
-9
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,20 +407,21 @@ def init_trackers(self, ffmpeg_stream: FFmpegStream) -> tuple:
407407
for tracker_number in range(self.params.number_of_trackers):
408408
bbox_woman = self.ui.bbox_selector(
409409
preview_frame,
410-
"Select {} Feature #{}".format(self.get_target_name(0), tracker_number+1)
410+
"Select {} Feature #{}".format(self.get_target_name(0), tracker_number+1),
411+
add_center = True
411412
)
412413

413414
preview_frame = self.ui.draw_box_to_image(
414-
preview_frame,
415-
bbox_woman,
415+
preview_frame,
416+
bbox_woman,
416417
color=(255,0,255)
417418
)
418419

419420
if self.params.supervised_tracking:
420421
while True:
421422
tracking_areas_woman[tracker_number] = self.ui.bbox_selector(
422423
preview_frame,
423-
"Select the Supervised Tracking Area for the {} Feature #{}".format(self.get_target_name(0), tracker_number+1)
424+
"Select the Supervised Tracking Area for the {} Feature #{}".format(self.get_target_name(0), tracker_number+1),
424425
)
425426

426427
if StaticVideoTracker.is_bbox_in_tracking_area(bbox_woman, tracking_areas_woman[tracker_number]):
@@ -456,7 +457,8 @@ def init_trackers(self, ffmpeg_stream: FFmpegStream) -> tuple:
456457
if self.params.track_men:
457458
bbox_men = self.ui.bbox_selector(
458459
preview_frame,
459-
"Select {} Feature #{}".format(self.get_target_name(1), tracker_number+1)
460+
"Select {} Feature #{}".format(self.get_target_name(1), tracker_number+1),
461+
add_center = True
460462
)
461463
preview_frame = self.ui.draw_box_to_image(preview_frame, bbox_men, color=(255,0,255))
462464
if self.params.supervised_tracking:

funscript_editor/algorithms/videotracker.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ def get_center(box: tuple) -> tuple:
205205
return ( round(box[0] + box[2]/2), round(box[1] + box[3]/2) )
206206

207207

208+
@staticmethod
209+
def create_tracking_box(box: tuple):
210+
""" Create an tracking box (x, y, h, w, x_center, y_center)
211+
212+
Args:
213+
box (tuple): the predicted bounding box
214+
215+
Returns:
216+
tuble: tracking box
217+
"""
218+
if box is None:
219+
return None
220+
221+
if len(box) < 4:
222+
return None
223+
224+
center = StaticVideoTracker.get_center(box)
225+
return (box[0], box[1], box[2], box[3], center[0], center[1])
226+
227+
208228
def run(self) -> None:
209229
""" The Video Tracker Thread Function """
210230
self.__setup_tracker()
@@ -241,6 +261,7 @@ def run(self) -> None:
241261
frame = self.queue_in.get()
242262
frame_roi = frame[y0:y1, x0:x1]
243263
success, bbox = self.tracker.update(frame_roi)
264+
bbox = self.create_tracking_box(bbox)
244265
self.last_detected_tracking_box = self.current_detected_tracking_box
245266
self.current_detected_tracking_box = copy.deepcopy(bbox)
246267
self.tracking_counter += 1
@@ -249,7 +270,7 @@ def run(self) -> None:
249270
bbox = None
250271
else:
251272
status = StaticVideoTracker.Status.OK
252-
bbox = (int(bbox[0] + x0), int(bbox[1] + y0), int(bbox[2]), int(bbox[3]))
273+
bbox = (int(bbox[0] + x0), int(bbox[1] + y0), int(bbox[2]), int(bbox[3]), int(bbox[4] + x0), int(bbox[5] + y0))
253274
if self.params.tracking_plausibility_check:
254275
if not self.__is_plausible(bbox):
255276
status = StaticVideoTracker.Status.IMPLAUSIBLE

funscript_editor/ui/opencvui.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def draw_box(self, bbox, color: tuple = (255, 0, 255)) -> None:
200200
bbox = [bbox]
201201

202202
for box in bbox:
203-
if box and len(box) == 4:
203+
if box and len(box) >= 4:
204204
cv2.rectangle(
205205
self.preview_image,
206206
(box[0], box[1]),
@@ -209,6 +209,15 @@ def draw_box(self, bbox, color: tuple = (255, 0, 255)) -> None:
209209
3,
210210
1
211211
)
212+
if len(box) >= 6:
213+
cv2.circle(
214+
self.preview_image,
215+
(box[4], box[5]),
216+
5,
217+
color,
218+
2
219+
)
220+
212221

213222
@staticmethod
214223
def draw_box_to_image(image: np.ndarray, bbox, color: tuple = (255, 0, 255)) -> np.ndarray:
@@ -226,7 +235,7 @@ def draw_box_to_image(image: np.ndarray, bbox, color: tuple = (255, 0, 255)) ->
226235
bbox = [bbox]
227236

228237
for box in bbox:
229-
if box and len(box) == 4:
238+
if box and len(box) >= 4:
230239
cv2.rectangle(
231240
image,
232241
(box[0], box[1]),
@@ -235,6 +244,14 @@ def draw_box_to_image(image: np.ndarray, bbox, color: tuple = (255, 0, 255)) ->
235244
3,
236245
1
237246
)
247+
if len(box) >= 6:
248+
cv2.circle(
249+
image,
250+
(box[4], box[5]),
251+
5,
252+
color,
253+
2
254+
)
238255

239256
return image
240257

@@ -473,13 +490,26 @@ def min_max_selector(self,
473490
else (trackbarValueMax, trackbarValueMin)
474491

475492

493+
@staticmethod
494+
def get_center(box: tuple) -> tuple:
495+
""" Get the cencter point of an box
476496
477-
def bbox_selector(self, image: np.ndarray, txt: str) -> tuple:
497+
Args:
498+
box (tuple): the predicted bounding box
499+
500+
Returns:
501+
tuple (x,y) of the current point
502+
"""
503+
return ( round(box[0] + box[2]/2), round(box[1] + box[3]/2) )
504+
505+
506+
def bbox_selector(self, image: np.ndarray, txt: str, add_center: bool = False) -> tuple:
478507
""" Window to get an bounding box from user input
479508
480509
Args:
481510
image (np.ndarray): opencv image e.g. the first frame to determine the bounding box
482511
txt (str): additional text to display on the selection window
512+
add_center (bool): add center cordinates to the box
483513
484514
Returns:
485515
tuple: user input bounding box tuple (x,y,w,h)
@@ -542,6 +572,10 @@ def bbox_selector(self, image: np.ndarray, txt: str) -> tuple:
542572
round(bbox[3]/self.params.zoom_factor)
543573
)
544574

575+
if add_center:
576+
center = self.get_center(bbox)
577+
bbox = (bbox[0], bbox[1], bbox[2], bbox[3], center[0], center[1])
578+
545579
self.logger.info("User Input: %s", str(bbox))
546580
return bbox
547581

0 commit comments

Comments
 (0)