Skip to content

Commit d788c8a

Browse files
author
arch
committed
add test code for delayed tracking lost
1 parent 0a92dae commit d788c8a

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

docs/app/docs/user-guide/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ conda activate funscript-editor
5252
python3 funscript-editor.py
5353
```
5454

55-
By default the latest code is used which may contain bugs. So you maybe want to switch to the latest release version with `` git checkout $(git describe --tags `git rev-list --tags --max-count=1`) ``.
55+
By default the latest code is used which may contain bugs. So you maybe want to switch to the latest release version with `` git checkout $(git describe --tags `git rev-list --tags --max-count=1`)``.
5656

5757
You can always update the application to the latest version with `git checkout main && git pull` inside the repository directory.

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ class FunscriptGeneratorParameter:
4848
zoom_factor: float = max((1.0, float(SETTINGS['zoom_factor'])))
4949
preview_scaling: float = float(SETTINGS['preview_scaling'])
5050
use_kalman_filter: bool = SETTINGS['use_kalman_filter']
51+
tracking_lost_time: int = max((0, SETTINGS['tracking_lost_time']))
5152

52-
# General
53+
# General Hyperparameter
5354
skip_frames: int = max((0, int(HYPERPARAMETER['skip_frames'])))
5455

5556
# VR Movement in y Direction
@@ -701,6 +702,8 @@ def tracking(self) -> str:
701702
else:
702703
cycle_time_in_ms = 0
703704

705+
tracking_lost_frames = round(self.video_info.fps * self.params.tracking_lost_time / 1000.0)
706+
704707
status = "End of video reached"
705708
self.clear_keypress_queue()
706709
last_frame, frame_num = None, 1 # first frame is init frame
@@ -751,18 +754,30 @@ def tracking(self) -> str:
751754
break
752755

753756
(woman_tracker_status, bbox_woman) = tracker_woman.result()
754-
if woman_tracker_status != "OK":
757+
if woman_tracker_status == StaticVideoTracker.Status.FEATURE_OUTSIDE:
755758
status = 'Woman ' + woman_tracker_status
756-
bboxes = self.delete_last_tracking_predictions(bboxes, (self.params.skip_frames+1)*3)
759+
bboxes = self.delete_last_tracking_predictions(bboxes, (self.params.skip_frames+1)*2)
757760
break
758761

762+
if woman_tracker_status == StaticVideoTracker.Status.TRACKING_LOST:
763+
if len(bboxes['Woman']) == 0 or max([x for x in bboxes['Woman'].keys()]) < tracking_lost_frames:
764+
status = 'Woman ' + woman_tracker_status
765+
bboxes = self.delete_last_tracking_predictions(bboxes, (self.params.skip_frames+1)*2)
766+
break
767+
759768
if self.params.track_men:
760769
(men_tracker_status, bbox_men) = tracker_men.result()
761-
if men_tracker_status != "OK":
770+
if men_tracker_status == StaticVideoTracker.Status.FEATURE_OUTSIDE:
762771
status = 'Men ' + men_tracker_status
763-
bboxes = self.delete_last_tracking_predictions(bboxes, (self.params.skip_frames+1)*3)
772+
bboxes = self.delete_last_tracking_predictions(bboxes, (self.params.skip_frames+1)*2)
764773
break
765774

775+
if men_tracker_status == StaticVideoTracker.Status.TRACKING_LOST:
776+
if len(bboxes['Men']) == 0 or max([x for x in bboxes['Men'].keys()]) < tracking_lost_frames:
777+
status = 'Men ' + men_tracker_status
778+
bboxes = self.delete_last_tracking_predictions(bboxes, (self.params.skip_frames+1)*2)
779+
break
780+
766781
last_frame = frame
767782

768783
if cycle_time_in_ms > 0:

funscript_editor/algorithms/videotracker.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
import logging
77

8+
from dataclasses import dataclass
89
from threading import Thread
910
from queue import Queue
1011
from funscript_editor.utils.config import SETTINGS
@@ -47,6 +48,13 @@ def __init__(self,
4748
__logger = logging.getLogger(__name__)
4849

4950

51+
@dataclass
52+
class Status:
53+
OK :str = "OK"
54+
TRACKING_LOST :str = "Tracking Lost"
55+
FEATURE_OUTSIDE :str = "Feature outside the specified area"
56+
57+
5058
@staticmethod
5159
def is_bbox_in_tracking_area(bbox: tuple, supervised_tracking_area: tuple = None) -> bool:
5260
""" Check if tracking box is inside the supervised tracking area
@@ -145,12 +153,12 @@ def run(self) -> None:
145153
frame = self.queue_in.get()
146154
frame_roi = frame[y0:y1, x0:x1]
147155
success, bbox = self.tracker.update(frame_roi)
148-
status = "Tracking Lost"
156+
status = StaticVideoTracker.Status.TRACKING_LOST
149157
if success:
150-
status = "OK"
158+
status = StaticVideoTracker.Status.OK
151159
bbox = (int(bbox[0] + x0), int(bbox[1] + y0), int(bbox[2]), int(bbox[3]))
152160
if not StaticVideoTracker.is_bbox_in_tracking_area(bbox, self.supervised_tracking_area):
153-
status = "Feature outside the specified area"
161+
status = StaticVideoTracker.Status.FEATURE_OUTSIDE
154162

155163
self.queue_out.put((status, bbox))
156164

funscript_editor/config/settings.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ tracker: 'CSRT'
2222

2323
# Specify the wav file to play when tracking finished (write 'off' to disable the sound notification)
2424
notification_sound: 'sound_notification.wav'
25+
26+
# Time in milliseconds at which the tracking is stopped if the selected feature is not found
27+
tracking_lost_time: 0

0 commit comments

Comments
 (0)