Skip to content

Commit

Permalink
testing mouse roi selection #17
Browse files Browse the repository at this point in the history
  • Loading branch information
arch committed Sep 11, 2022
1 parent 1d2fdd3 commit e480830
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
16 changes: 15 additions & 1 deletion funscript_editor/config/projection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ vr_he_180_ou:


flat_with_parameters:
name: '2D Video with Filters'
name: '2D Video with Keyboard Menu'
video_filter: "pad='max(ih,iw):max(ih,iw):max(ih,iw)/2:max(ih,iw)/2',scale=${width}:${height},rotate='(PI/180)*${rotation}',crop='iw*1/max(1, ${zoom}/5):ih*1/max(1, ${zoom}/5):2*${x}:2*${y}',scale=${width}:${height}"
parameter:
height: 1024
Expand All @@ -128,3 +128,17 @@ flat_with_parameters:
rotation:
increase: "e"
decrease: "q"

# experimental mouse api may change in future version!!!
flat_with_mouse:
name: '2D Video with Mouse Menu'
video_filter: "pad='max(ih,iw):max(ih,iw):max(ih,iw)/2:max(ih,iw)/2',scale=${width}:${height},crop='${w}:${h}:${x}:${y}',scale=${width}:${height}"
parameter:
height: 1024
width: 1024
x: 0
y: 0
w: 1024
h: 1024
mouse: true

21 changes: 13 additions & 8 deletions funscript_editor/data/ffmpegstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,19 @@ def run(self) -> None:
if self.log_queue_overrun:
self.logger.error("FFmpeg Frame Buffer overrun!!!")

if 'zoom' in self.config.keys():
frame = frame[
int(self.config['zoom'][1]):int(self.config['zoom'][1]+self.config['zoom'][3]),
int(self.config['zoom'][0]):int(self.config['zoom'][0]+self.config['zoom'][2])
]

if 'resize' in self.config.keys():
frame = cv2.resize(frame, self.config['resize'])
if 'postParameter' in self.config.keys():
if 'zoom' in self.config['postParameter'].keys():
frame = frame[
int(self.config['zoom'][1]):int(self.config['zoom'][1]+self.config['zoom'][3]),
int(self.config['zoom'][0]):int(self.config['zoom'][0]+self.config['zoom'][2])
]

if 'resize' in self.config['postParameter'].keys():
frame = cv2.resize(frame, self.config['resize'])

# TODO remove this after testing
assert('zoom' not in self.config)
assert('resize' not in self.config)

self.frame_buffer.put(frame)

Expand Down
11 changes: 11 additions & 0 deletions funscript_editor/ui/opencvui.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,17 @@ def get_video_projection_config(self, image :np.ndarray, projection: str) -> dic
if image.shape[0] > 3000 or image.shape[1] > 3000:
image = cv2.resize(image, None, fx=0.5, fy=0.5)

if "mouse" in config and config["mouse"] == True:
self.logger.info("Show Mouse ROI Menu")
preview = FFmpegStream.get_projection(image, config)
selected_bbox = self.bbox_selector(preview, "Select ROI")
config['parameter']['x'] = selected_bbox[0]
config['parameter']['y'] = selected_bbox[1]
config['parameter']['w'] = selected_bbox[2]
config['parameter']['h'] = selected_bbox[3]
self.show_loading_screen()
return config

ui_texte = {}
if "keys" in config.keys():
for param in config['keys'].keys():
Expand Down

0 comments on commit e480830

Please sign in to comment.