You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
camtest: adapt to new api
This commit is contained in:
@@ -95,7 +95,7 @@ def qr_button_click(e):
|
||||
def try_capture():
|
||||
global current_cam_buffer, image_dsc, image, use_webcam
|
||||
if use_webcam:
|
||||
new_cam_buffer = webcam.capture_grayscale()
|
||||
new_cam_buffer = cam.capture_grayscale()
|
||||
elif cam.frame_available():
|
||||
new_cam_buffer = cam.capture() # Returns memoryview
|
||||
if len(new_cam_buffer):
|
||||
@@ -193,12 +193,23 @@ def init_cam():
|
||||
return None
|
||||
|
||||
|
||||
import webcam
|
||||
|
||||
class Webcam:
|
||||
def __init__(self):
|
||||
# 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)
|
||||
def deinit(self):
|
||||
return self._deinit(self.obj)
|
||||
|
||||
|
||||
cam = init_cam()
|
||||
if not cam:
|
||||
print("init cam failed, retrying with webcam...")
|
||||
try:
|
||||
import webcam
|
||||
current_cam_buffer = webcam.capture_grayscale()
|
||||
cam = Webcam()
|
||||
use_webcam = True
|
||||
except Exception as e:
|
||||
print(f"camtest.py: webcam exception: {e}")
|
||||
|
||||
Reference in New Issue
Block a user