mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Fix camera bugs
This commit is contained in:
@@ -120,11 +120,11 @@ class CameraApp(Activity):
|
|||||||
def onResume(self, screen):
|
def onResume(self, screen):
|
||||||
self.parse_camera_init_preferences()
|
self.parse_camera_init_preferences()
|
||||||
# Init camera:
|
# Init camera:
|
||||||
self.cam = init_internal_cam(self.width, self.height)
|
self.cam = self.init_internal_cam(self.width, self.height)
|
||||||
if self.cam:
|
if self.cam:
|
||||||
self.image.set_rotation(900) # internal camera is rotated 90 degrees
|
self.image.set_rotation(900) # internal camera is rotated 90 degrees
|
||||||
# Apply saved camera settings, only for internal camera for now:
|
# Apply saved camera settings, only for internal camera for now:
|
||||||
apply_camera_settings(self.cam, self.use_webcam) # needs to be done AFTER the camera is initialized
|
self.apply_camera_settings(self.cam, self.use_webcam) # needs to be done AFTER the camera is initialized
|
||||||
else:
|
else:
|
||||||
print("camera app: no internal camera found, trying webcam on /dev/video0")
|
print("camera app: no internal camera found, trying webcam on /dev/video0")
|
||||||
try:
|
try:
|
||||||
@@ -227,8 +227,8 @@ class CameraApp(Activity):
|
|||||||
self.status_label.set_text(self.status_label_text_searching)
|
self.status_label.set_text(self.status_label_text_searching)
|
||||||
else:
|
else:
|
||||||
print(f"SUCCESSFUL QR DECODE TOOK: {after-before}ms")
|
print(f"SUCCESSFUL QR DECODE TOOK: {after-before}ms")
|
||||||
result = remove_bom(result)
|
result = self.remove_bom(result)
|
||||||
result = print_qr_buffer(result)
|
result = self.print_qr_buffer(result)
|
||||||
print(f"QR decoding found: {result}")
|
print(f"QR decoding found: {result}")
|
||||||
if self.scanqr_mode:
|
if self.scanqr_mode:
|
||||||
self.setResult(True, result)
|
self.setResult(True, result)
|
||||||
@@ -336,9 +336,7 @@ class CameraApp(Activity):
|
|||||||
except Exception as qre:
|
except Exception as qre:
|
||||||
print(f"try_capture: qrdecode_one got exception: {qre}")
|
print(f"try_capture: qrdecode_one got exception: {qre}")
|
||||||
|
|
||||||
|
def init_internal_cam(self, width, height):
|
||||||
# Non-class functions:
|
|
||||||
def init_internal_cam(width, height):
|
|
||||||
"""Initialize internal camera with specified resolution.
|
"""Initialize internal camera with specified resolution.
|
||||||
|
|
||||||
Automatically retries once if initialization fails (to handle I2C poweroff issue).
|
Automatically retries once if initialization fails (to handle I2C poweroff issue).
|
||||||
@@ -411,7 +409,7 @@ def init_internal_cam(width, height):
|
|||||||
print(f"init_cam exception: {e}")
|
print(f"init_cam exception: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def print_qr_buffer(buffer):
|
def print_qr_buffer(self, buffer):
|
||||||
try:
|
try:
|
||||||
# Try to decode buffer as a UTF-8 string
|
# Try to decode buffer as a UTF-8 string
|
||||||
result = buffer.decode('utf-8')
|
result = buffer.decode('utf-8')
|
||||||
@@ -425,14 +423,14 @@ def print_qr_buffer(buffer):
|
|||||||
return hex_str.lower()
|
return hex_str.lower()
|
||||||
|
|
||||||
# Byte-Order-Mark is added sometimes
|
# Byte-Order-Mark is added sometimes
|
||||||
def remove_bom(buffer):
|
def remove_bom(self, buffer):
|
||||||
bom = b'\xEF\xBB\xBF'
|
bom = b'\xEF\xBB\xBF'
|
||||||
if buffer.startswith(bom):
|
if buffer.startswith(bom):
|
||||||
return buffer[3:]
|
return buffer[3:]
|
||||||
return buffer
|
return buffer
|
||||||
|
|
||||||
|
|
||||||
def apply_camera_settings(cam, use_webcam):
|
def apply_camera_settings(self, cam, use_webcam):
|
||||||
"""Apply all saved camera settings to the camera.
|
"""Apply all saved camera settings to the camera.
|
||||||
|
|
||||||
Only applies settings when use_webcam is False (ESP32 camera).
|
Only applies settings when use_webcam is False (ESP32 camera).
|
||||||
@@ -531,6 +529,7 @@ def apply_camera_settings(cam, use_webcam):
|
|||||||
cam.set_wpc(wpc)
|
cam.set_wpc(wpc)
|
||||||
|
|
||||||
raw_gma = self.prefs.get_bool("raw_gma", True)
|
raw_gma = self.prefs.get_bool("raw_gma", True)
|
||||||
|
print(f"applying raw_gma: {raw_gma}")
|
||||||
cam.set_raw_gma(raw_gma)
|
cam.set_raw_gma(raw_gma)
|
||||||
|
|
||||||
lenc = self.prefs.get_bool("lenc", True)
|
lenc = self.prefs.get_bool("lenc", True)
|
||||||
@@ -547,3 +546,4 @@ def apply_camera_settings(cam, use_webcam):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error applying camera settings: {e}")
|
print(f"Error applying camera settings: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user