You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Improve webcam
This commit is contained in:
+2
-2
@@ -23,8 +23,8 @@
|
||||
#define CAPTURE_HEIGHT 480
|
||||
#define OUTPUT_WIDTH 240 // Resize to 240x240
|
||||
#define OUTPUT_HEIGHT 240
|
||||
#define NUM_BUFFERS 2 // Revert to 2 buffers, as it achieved 2 captures
|
||||
#define QUEUE_RETRIES 10 // Increase retries for robustness
|
||||
#define NUM_BUFFERS 10 // Revert to 2 buffers, as it achieved 2 captures
|
||||
#define QUEUE_RETRIES 5 // Increase retries for robustness
|
||||
#define QUEUE_RETRY_DELAY_US 200000 // 200ms delay between retries
|
||||
|
||||
// Webcam object type
|
||||
|
||||
@@ -98,7 +98,7 @@ def try_capture():
|
||||
new_cam_buffer = cam.capture_grayscale()
|
||||
elif cam.frame_available():
|
||||
new_cam_buffer = cam.capture() # Returns memoryview
|
||||
if len(new_cam_buffer):
|
||||
if new_cam_buffer and len(new_cam_buffer):
|
||||
# print("Invalid buffer size:", len(new_cam_buffer))
|
||||
# cam.free_buffer()
|
||||
# return
|
||||
@@ -200,7 +200,11 @@ class Webcam:
|
||||
# webcam.init() returns (obj, capture_grayscale, deinit)
|
||||
self.obj, self._capture_grayscale, self._deinit = webcam.init()
|
||||
def capture_grayscale(self):
|
||||
return self._capture_grayscale(self.obj)
|
||||
try:
|
||||
return self._capture_grayscale(self.obj)
|
||||
except Exception as e:
|
||||
print(f"capture got exception {e}")
|
||||
self.deinit()
|
||||
def deinit(self):
|
||||
return self._deinit(self.obj)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user