You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
task_handler needs to be called from the same thread...
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
width=240
|
||||
height=240
|
||||
|
||||
import webcam
|
||||
import time
|
||||
|
||||
cam = webcam.init("/dev/video0") # Initialize webcam with device path
|
||||
memview = webcam.capture_frame(cam) # Returns memoryview
|
||||
time.sleep_ms(1000)
|
||||
static_bytes_obj = bytes(memview)
|
||||
|
||||
|
||||
image = lv.image(lv.screen_active())
|
||||
image.align(lv.ALIGN.LEFT_MID, 0, 0)
|
||||
image.set_rotation(900)
|
||||
# Create image descriptor once
|
||||
image_dsc = lv.image_dsc_t({
|
||||
"header": {
|
||||
"magic": lv.IMAGE_HEADER_MAGIC,
|
||||
"w": width,
|
||||
"h": height,
|
||||
"stride": width ,
|
||||
"cf": lv.COLOR_FORMAT.L8
|
||||
},
|
||||
'data_size': width * height,
|
||||
'data': static_bytes_obj # Will be updated per frame
|
||||
})
|
||||
image.set_src(image_dsc)
|
||||
|
||||
for i in range(300):
|
||||
print(f"iteration {i}")
|
||||
webcam.recapture_frame(cam) #refresh memview
|
||||
bytes_obj = bytes(memview)
|
||||
#print(f"got bytes: {len(bytes_obj)}")
|
||||
#image_dsc.data = static_bytes_obj
|
||||
image_dsc.data = bytes_obj
|
||||
#image.set_src(image_dsc)
|
||||
image.invalidate()
|
||||
time.sleep_ms(10) # seems to need more than 0 or 1 ms
|
||||
|
||||
print("cleanup")
|
||||
webcam.deinit(cam) # Deinitializes webcam
|
||||
Reference in New Issue
Block a user