Skip to content

Commit 5779ae0

Browse files
doesnt hang but stays black
1 parent 12b2145 commit 5779ae0

File tree

1 file changed

+15
-5
lines changed
  • internal_filesystem/apps/com.example.camtest/assets

1 file changed

+15
-5
lines changed

internal_filesystem/apps/com.example.camtest/assets/camtest.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
qr_label = None
1616
use_webcam = False
1717

18+
memview = None
1819

1920
def print_qr_buffer(buffer):
2021
try:
@@ -160,7 +161,6 @@ def build_ui():
160161
image.align(lv.ALIGN.LEFT_MID, 0, 0)
161162
image.set_rotation(900)
162163
# Create image descriptor once
163-
memview = webcam.capture_frame(cam) # Returns memoryview
164164
image_dsc = lv.image_dsc_t({
165165
"header": {
166166
"magic": lv.IMAGE_HEADER_MAGIC,
@@ -171,7 +171,7 @@ def build_ui():
171171
"cf": lv.COLOR_FORMAT.L8
172172
},
173173
'data_size': width * height,
174-
'data': memview # Will be updated per frame
174+
'data': None # Will be updated per frame
175175
})
176176
image.set_src(image_dsc)
177177

@@ -221,17 +221,27 @@ def init_cam():
221221
except Exception as e:
222222
print(f"camtest.py: webcam exception: {e}")
223223

224+
time.sleep_ms(1000)
225+
memview = webcam.capture_frame(cam) # Returns memoryview
226+
time.sleep_ms(1000)
227+
static_bytes_obj = bytes(memview)
228+
224229
if cam or use_webcam:
225230
build_ui()
226231
count=0
227232
while appscreen == lv.screen_active() and keepgoing is True:
228233
print(f"capture nr {count}")
229234
count += 1
230235
#try_capture()
231-
webcam.recapture_frame(cam)
232-
#image.invalidate()
236+
#webcam.recapture_frame(cam)
237+
bytes_obj = bytes(memview)
238+
print(f"got bytes: {len(bytes_obj)}")
239+
image_dsc.data = bytes_obj
240+
#image_dsc.data = static_bytes_obj
241+
time.sleep_ms(200) # Allow for the MicroPython REPL to still work. Reducing it doesn't seem to affect the on-display FPS.
242+
# somehow, everything's fine until I tell LVGL to redraw the image:
243+
image.invalidate()
233244
#image.set_src(image_dsc)
234-
time.sleep_ms(100) # Allow for the MicroPython REPL to still work. Reducing it doesn't seem to affect the on-display FPS.
235245
print("App backgrounded, deinitializing camera...")
236246
if use_webcam:
237247
webcam.deinit(cam) # Deinitializes webcam

0 commit comments

Comments
 (0)