Fixed Auto ROI not getting an image when no ROI set.

Auto ROI can now run without an roi being set initially. Also fixed a bug with the osc receiver that prevented it from initializing.
This commit is contained in:
Rames The Generic committed 2024-01-20 15:55:31 -05:00
1 parent 1cc5e5feb7
commit 015253fda0
4 files changed
+21 -18

No files matched your search

+10 -10
View File
@@ -44,6 +44,7 @@ class CameraWidget:
self.settings_config = main_config.settings
self.config = main_config.cam
self.settings = main_config.settings
self.maybe_image = None
if self.cam_id == Tab.CAM:
self.config = main_config.cam
else:
@@ -255,7 +256,7 @@ class CameraWidget:
changed = True
if self.config.rotation_angle != values[self.gui_rotation_slider]:
self.config.rotation_angle = int(values[self.gui_rotation_slider])
changed = True
@@ -310,19 +311,17 @@ class CameraWidget:
if event == self.gui_autoroi:
print("Auto ROI")
#image = self.image_queue.get()
#image = self.babble_landmark.get_frame() # Get image for pfld
#print(image)
#print(len(image))
#print(image)
#cv2.imwrite("yeah.png", image)
self.babble_landmark.infer_frame()
output = self.babble_landmark.output
#needs_roi_set = self.config.roi_window_h <= 0 or self.config.roi_window_w <= 0
self.babble_landmark.infer_frame(image = self.maybe_image[0])
output = self.babble_landmark.output[0]
rotation = self.babble_landmark.output[1]
print(f'Rotation: {rotation}')
print(f"Output: {output}")
self.x1 = output[2]
self.y1 = output[3]
self.x0 = output[0]
self.y0 = output[1]
window[self.gui_rotation_slider].update(value = rotation)
self.config.roi_window_x = min([self.x0, self.x1])
self.config.roi_window_y = min([self.y0, self.y1])
self.config.roi_window_w = abs(self.x0 - self.x1)
@@ -370,6 +369,7 @@ class CameraWidget:
if self.roi_queue.empty():
self.capture_event.set()
maybe_image = self.roi_queue.get(block=False)
self.maybe_image = maybe_image
imgbytes = cv2.imencode(".ppm", maybe_image[0])[1].tobytes()
graph = window[self.gui_roi_selection]
if self.figure:
@@ -400,4 +400,4 @@ class CameraWidget:
if cam_info.info_type != CamInfoOrigin.FAILURE:
self.osc_queue.put((self.cam_id, cam_info))
except Empty:
pass
pass
+4 -4
View File
@@ -28,8 +28,8 @@ def run_model(self): # Replace transforms n shit for the pfld model
self.output = output
def write_image(self): # Debug function for development, remove once pfld is implemented.
frame = cv2.resize(self.current_image_gray, (256, 256))
cv2.imwrite("yeah.png", frame)
def write_image(self, image): # Placeholder function for development, replace all instances with run_model() once pfld is implemented.
frame = cv2.resize(image, (256, 256))
cv2.imwrite("yeah.png", frame) # Write the clean, untransformed frame to show that the frame is clean for pfld
print("Image Wrote")
self.output = (0, 0, 100, 100)
self.output = ((0, 0, 100, 100), 25) # Return ROI box and Rotation information.
+2 -2
View File
@@ -115,8 +115,8 @@ class LandmarkProcessor:
def get_frame(self):
return self.current_image_gray_clean
def infer_frame(self):
return write_image(self)
def infer_frame(self, image):
return write_image(self, image)
def output_images_and_update(self, output_information: CamInfo):
try:
+5 -2
View File
@@ -5,6 +5,7 @@ import threading
from enum import IntEnum
import time
from config import BabbleConfig
import traceback
class Tab(IntEnum):
CAM = 0
@@ -90,6 +91,7 @@ class VRChatOSCReceiver:
self.cancellation_event = cancellation_event
self.dispatcher = dispatcher.Dispatcher()
self.cams = cams # we cant import CameraWidget so any type it is
print("OSC_INIT")
try:
self.server = osc_server.OSCUDPServer((self.config.gui_osc_address, int(self.config.gui_osc_receiver_port)), self.dispatcher)
except:
@@ -106,17 +108,18 @@ class VRChatOSCReceiver:
if type(osc_value) != bool: return # just incase we get anything other than bool
if osc_value:
for cam in self.cams:
cam.ransac.calibration_frame_counter = 300
cam.babble_cnn.calibration_frame_counter = 300
PlaySound('Audio/start.wav', SND_FILENAME | SND_ASYNC)
def run(self):
# bind what function to run when specified OSC message is received
try:
self.dispatcher.map(self.config.gui_osc_recalibrate_address, self.recalibrate_cams)
self.dispatcher.map(self.config.gui_osc_recalibrate_address, self.recalibrate_mouth)
# start the server
print("\033[92m[INFO] VRChatOSCReceiver serving on {}\033[0m".format(self.server.server_address))
self.server.serve_forever()
except:
traceback.print_exc()
print(f"\033[91m[ERROR] OSC Receive port: {self.config.gui_osc_receiver_port} occupied.\033[0m")