|
| 1 | +# This works with copy-paste |
| 2 | +# It also works like this: |
| 3 | +# import mpos |
| 4 | +# mpos.apps.execute_script("apps/com.example.camtestnew/assets/camtestnew.py", True, False, True) |
| 5 | +# import mpos |
| 6 | +# mpos.apps.execute_script_new_thread("apps/com.example.camtestnew/assets/camtestnew.py", True, False, True) |
| 7 | + |
| 8 | + |
| 9 | +width=240 |
| 10 | +height=240 |
| 11 | + |
| 12 | +import time |
| 13 | + |
| 14 | +th.disable() |
| 15 | + |
| 16 | + |
| 17 | +from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling |
| 18 | +cam = Camera( |
| 19 | + data_pins=[12,13,15,11,14,10,7,2], |
| 20 | + vsync_pin=6, |
| 21 | + href_pin=4, |
| 22 | + sda_pin=21, |
| 23 | + scl_pin=16, |
| 24 | + pclk_pin=9, |
| 25 | + xclk_pin=8, |
| 26 | + xclk_freq=20000000, |
| 27 | + powerdown_pin=-1, |
| 28 | + reset_pin=-1, |
| 29 | + #pixel_format=PixelFormat.RGB565, |
| 30 | + #pixel_format=PixelFormat.GRAYSCALE, |
| 31 | + #pixel_format=PixelFormat.YUV420, |
| 32 | + pixel_format=PixelFormat.YUV422, # works |
| 33 | + frame_size=FrameSize.R240X240, |
| 34 | + grab_mode=GrabMode.LATEST |
| 35 | +) |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +image = lv.image(lv.screen_active()) |
| 40 | +image.align(lv.ALIGN.LEFT_MID, 0, 0) |
| 41 | +image.set_rotation(900) |
| 42 | + |
| 43 | +# Create image descriptor once |
| 44 | +image_dsc = lv.image_dsc_t({ |
| 45 | + "header": { |
| 46 | + "magic": lv.IMAGE_HEADER_MAGIC, |
| 47 | + "w": width, |
| 48 | + "h": height, |
| 49 | + "stride": width, |
| 50 | + "cf": lv.COLOR_FORMAT.I422 |
| 51 | + }, |
| 52 | + 'data_size': width * height, |
| 53 | + 'data': None # Will be updated per frame |
| 54 | +}) |
| 55 | +image.set_src(image_dsc) |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +for i in range(100): |
| 60 | + print(f"iteration {i}") |
| 61 | + image_dsc.data = cam.capture() # Returns memoryview |
| 62 | + image.set_src(image_dsc) |
| 63 | + #image.invalidate() |
| 64 | + lv.task_handler() |
| 65 | + time.sleep_ms(5) # seems to need more than 0 or 1 ms, otherwise there's almost never a new image... |
| 66 | + lv.tick_inc(5) |
| 67 | + |
| 68 | + |
| 69 | +print("cleanup") |
| 70 | +cam.deinit() |
| 71 | + |
| 72 | + |
| 73 | +th.enable() |
0 commit comments