1515qr_label = None
1616use_webcam = False
1717
18+ memview = None
1819
1920def 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+
224229if 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