mirror of
https://github.com/Project-Babble/ProjectBabble.git
synced 2026-11-21 09:31:16 -08:00
Clamp Max Input Resolution
Prevents high resolution camera sources from displaying too large to fit in the app.
This commit is contained in:
1 parent
ddff2e57c0
commit
971f711dcd
2 files changed
+26
-11
No files matched your search
+19
-4
@@ -1,4 +1,5 @@
|
||||
import cv2
|
||||
from cv2.typing import *
|
||||
import numpy as np
|
||||
import queue
|
||||
import serial
|
||||
@@ -12,6 +13,7 @@ from utils.misc_utils import get_camera_index_by_name, list_camera_names
|
||||
from enum import Enum
|
||||
|
||||
WAIT_TIME = 0.1
|
||||
MAX_RESOLUTION: int = 600
|
||||
|
||||
# Serial communication protocol:
|
||||
# header-begin (2 bytes)
|
||||
@@ -24,9 +26,9 @@ ETVR_HEADER_LEN = 6
|
||||
|
||||
|
||||
class CameraState(Enum):
|
||||
CONNECTING = 0
|
||||
CONNECTED = 1
|
||||
DISCONNECTED = 2
|
||||
CONNECTING: int = 0
|
||||
CONNECTED: int = 1
|
||||
DISCONNECTED: int = 2
|
||||
|
||||
|
||||
class Camera:
|
||||
@@ -277,6 +279,19 @@ class Camera:
|
||||
print(f"{Fore.CYAN}[INFO] Failed to connect on {port}{Fore.RESET}")
|
||||
self.camera_status = CameraState.DISCONNECTED
|
||||
|
||||
def clamp_max_res(self, image: MatLike) -> MatLike:
|
||||
shape = image.shape
|
||||
max_value = np.max(shape)
|
||||
if max_value > MAX_RESOLUTION:
|
||||
scale: float = MAX_RESOLUTION/max_value
|
||||
width: int = int(shape[1] * scale)
|
||||
height: int = int(shape[0] * scale)
|
||||
image = cv2.resize(image, (width, height))
|
||||
|
||||
return image
|
||||
else: return image
|
||||
|
||||
|
||||
def push_image_to_queue(self, image, frame_number, fps):
|
||||
# If there's backpressure, just yell. We really shouldn't have this unless we start getting
|
||||
# some sort of capture event conflict though.
|
||||
@@ -284,5 +299,5 @@ class Camera:
|
||||
if qsize > 1:
|
||||
print(
|
||||
f"{Fore.YELLOW}[WARN] CAPTURE QUEUE BACKPRESSURE OF {qsize}. CHECK FOR CRASH OR TIMING ISSUES IN ALGORITHM.{Fore.RESET}")
|
||||
self.camera_output_outgoing.put((image, frame_number, fps))
|
||||
self.camera_output_outgoing.put((self.clamp_max_res(image), frame_number, fps))
|
||||
self.capture_event.clear()
|
||||
@@ -6,7 +6,7 @@ import PySimpleGUI as sg
|
||||
|
||||
import cv2
|
||||
from babble_processor import BabbleProcessor, CamInfoOrigin
|
||||
from camera import Camera, CameraState
|
||||
from camera import Camera, CameraState, MAX_RESOLUTION
|
||||
from config import BabbleConfig
|
||||
from osc import Tab
|
||||
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC, list_camera_names, get_camera_index_by_name
|
||||
@@ -85,9 +85,9 @@ class CameraWidget:
|
||||
],
|
||||
[
|
||||
sg.Graph(
|
||||
(640, 480),
|
||||
(0, 480),
|
||||
(640, 0),
|
||||
(MAX_RESOLUTION, MAX_RESOLUTION),
|
||||
(0, MAX_RESOLUTION),
|
||||
(MAX_RESOLUTION, 0),
|
||||
key=self.gui_roi_selection,
|
||||
drag_submits=True,
|
||||
enable_events=True,
|
||||
@@ -337,11 +337,11 @@ class CameraWidget:
|
||||
|
||||
if event == self.gui_autoroi:
|
||||
print("Set ROI")
|
||||
output = self.babble_cnn.get_framesize()
|
||||
output = self.maybe_image[0].shape
|
||||
self.config.roi_window_x = 0
|
||||
self.config.roi_window_y = 0
|
||||
self.config.roi_window_w = output[0]
|
||||
self.config.roi_window_h = output[1]
|
||||
self.config.roi_window_w = output[1]
|
||||
self.config.roi_window_h = output[0]
|
||||
self.main_config.save()
|
||||
|
||||
if (event == self.gui_refresh_button):
|
||||
|
||||
Reference in new issue
Block a user