Update camera demos
This commit is contained in:
parent
e0a0722e85
commit
751422b7fe
4 changed files with 221 additions and 0 deletions
70
OV5640_Breakout/CircuitPython_Kaluga-ascii-mirror/code.py
Normal file
70
OV5640_Breakout/CircuitPython_Kaluga-ascii-mirror/code.py
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
"""
|
||||
This demo is designed for the Kaluga development kit version 1.3.
|
||||
|
||||
To fix the MemoryError when creating a Camera object, Place the line
|
||||
```toml
|
||||
CIRCUITPY_RESERVED_PSRAM=1048576
|
||||
```
|
||||
in the file **CIRCUITPY/settings.toml** and restart.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
import board
|
||||
import keypad
|
||||
import displayio
|
||||
import espcamera
|
||||
import espidf
|
||||
|
||||
# The demo runs very slowly if the LCD display is enabled!
|
||||
# It's intended to be viewed on the REPL on a host computer
|
||||
displayio.release_displays()
|
||||
|
||||
if espidf.get_reserved_psram() < 1047586:
|
||||
print("""Place the following line in CIRCUITPY/settings.toml, then hard-reset the board:
|
||||
```
|
||||
CIRCUITPY_RESERVED_PSRAM
|
||||
```
|
||||
""")
|
||||
raise SystemExit
|
||||
|
||||
print("Initializing camera")
|
||||
cam = espcamera.Camera(
|
||||
data_pins=board.CAMERA_DATA,
|
||||
external_clock_pin=board.CAMERA_XCLK,
|
||||
pixel_clock_pin=board.CAMERA_PCLK,
|
||||
vsync_pin=board.CAMERA_VSYNC,
|
||||
href_pin=board.CAMERA_HREF,
|
||||
pixel_format=espcamera.PixelFormat.GRAYSCALE,
|
||||
frame_size=espcamera.FrameSize.QQVGA,
|
||||
i2c=board.I2C(),
|
||||
external_clock_frequency=20_000_000,
|
||||
framebuffer_count=2)
|
||||
print("initialized")
|
||||
|
||||
k = keypad.Keys([board.IO0], value_when_pressed=False)
|
||||
|
||||
chars = b" .:-=+*#%@"
|
||||
remap = [chars[i * (len(chars) - 1) // 255] for i in range(256)]
|
||||
width = cam.width
|
||||
row = bytearray(width//2)
|
||||
|
||||
sys.stdout.write("\033[2J")
|
||||
|
||||
while True:
|
||||
if (e := k.events.get()) is not None and e.pressed:
|
||||
cam.colorbar = not cam.colorbar
|
||||
|
||||
frame = cam.take(1)
|
||||
|
||||
for j in range(0, cam.height, 5):
|
||||
sys.stdout.write(f"\033[{j//5}H")
|
||||
for i in range(cam.width // 2):
|
||||
row[i] = remap[frame[width * j + 2 * i]]
|
||||
sys.stdout.write(row)
|
||||
sys.stdout.write("\033[K")
|
||||
sys.stdout.write("\033[J")
|
||||
72
OV5640_Breakout/CircuitPython_Pico-ascii-mirror/code.py
Normal file
72
OV5640_Breakout/CircuitPython_Pico-ascii-mirror/code.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2023 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
This demo is designed for the Raspberry Pi Pico.
|
||||
|
||||
It shows the camera image as ASCII art on the USB REPL.
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
import time
|
||||
import busio
|
||||
import board
|
||||
import digitalio
|
||||
import adafruit_ov5640
|
||||
|
||||
print("construct bus")
|
||||
bus = busio.I2C(board.GP9, board.GP8)
|
||||
print("construct camera")
|
||||
reset = digitalio.DigitalInOut(board.GP10)
|
||||
cam = adafruit_ov5640.OV5640(
|
||||
bus,
|
||||
data_pins=(
|
||||
board.GP12,
|
||||
board.GP13,
|
||||
board.GP14,
|
||||
board.GP15,
|
||||
board.GP16,
|
||||
board.GP17,
|
||||
board.GP18,
|
||||
board.GP19,
|
||||
),
|
||||
clock=board.GP11,
|
||||
vsync=board.GP7,
|
||||
href=board.GP21,
|
||||
mclk=board.GP20,
|
||||
shutdown=None,
|
||||
reset=reset,
|
||||
size=adafruit_ov5640.OV5640_SIZE_QQVGA,
|
||||
)
|
||||
print("print chip id")
|
||||
print(cam.chip_id)
|
||||
|
||||
|
||||
cam.colorspace = adafruit_ov5640.OV5640_COLOR_YUV
|
||||
cam.flip_y = True
|
||||
cam.flip_x = True
|
||||
cam.test_pattern = False
|
||||
|
||||
buf = bytearray(cam.capture_buffer_size)
|
||||
chars = b" .':-+=*%$#"
|
||||
remap = [chars[i * (len(chars) - 1) // 255] for i in range(256)]
|
||||
|
||||
width = cam.width
|
||||
row = bytearray(width)
|
||||
|
||||
print("capturing")
|
||||
cam.capture(buf)
|
||||
print("capture complete")
|
||||
|
||||
sys.stdout.write("\033[2J")
|
||||
while True:
|
||||
cam.capture(buf)
|
||||
for j in range(0, cam.height, 2):
|
||||
sys.stdout.write(f"\033[{j//2}H")
|
||||
for i in range(cam.width):
|
||||
row[i] = remap[buf[2 * (width * j + i)]]
|
||||
sys.stdout.write(row)
|
||||
sys.stdout.write("\033[K")
|
||||
sys.stdout.write("\033[J")
|
||||
time.sleep(0.1)
|
||||
79
OV5640_Breakout/CircuitPython_Pico-lcd-mirror/code.py
Normal file
79
OV5640_Breakout/CircuitPython_Pico-lcd-mirror/code.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2023 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
This demo is designed for the Raspberry Pi Pico. with 240x240 SPI TFT display
|
||||
|
||||
It shows the camera image on the LCD
|
||||
"""
|
||||
import time
|
||||
import busio
|
||||
import board
|
||||
import digitalio
|
||||
import adafruit_ov5640
|
||||
import adafruit_st7789
|
||||
import displayio
|
||||
|
||||
# Set up the display (You must customize this block for your display!)
|
||||
displayio.release_displays()
|
||||
spi = busio.SPI(clock=board.GP2, MOSI=board.GP3)
|
||||
display_bus = displayio.FourWire(spi, command=board.GP0, chip_select=board.GP1, reset=None)
|
||||
display = adafruit_st7789.ST7789(display_bus, width=240, height=240, rowstart=80, rotation=0)
|
||||
|
||||
print("construct bus")
|
||||
bus = busio.I2C(board.GP9, board.GP8)
|
||||
print("construct camera")
|
||||
reset = digitalio.DigitalInOut(board.GP10)
|
||||
cam = adafruit_ov5640.OV5640(
|
||||
bus,
|
||||
data_pins=(
|
||||
board.GP12,
|
||||
board.GP13,
|
||||
board.GP14,
|
||||
board.GP15,
|
||||
board.GP16,
|
||||
board.GP17,
|
||||
board.GP18,
|
||||
board.GP19,
|
||||
),
|
||||
clock=board.GP11,
|
||||
vsync=board.GP7,
|
||||
href=board.GP21,
|
||||
mclk=board.GP20,
|
||||
shutdown=None,
|
||||
reset=reset,
|
||||
size=adafruit_ov5640.OV5640_SIZE_240X240,
|
||||
)
|
||||
print("print chip id")
|
||||
print(cam.chip_id)
|
||||
|
||||
cam.colorspace = adafruit_ov5640.OV5640_COLOR_RGB
|
||||
cam.flip_y = False
|
||||
cam.flip_x = False
|
||||
cam.test_pattern = False
|
||||
|
||||
width = display.width
|
||||
height = display.height
|
||||
|
||||
#cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE
|
||||
bitmap = displayio.Bitmap(cam.width, cam.height, 65535)
|
||||
print(width, height, cam.width, cam.height)
|
||||
if bitmap is None:
|
||||
raise SystemExit("Could not allocate a bitmap")
|
||||
|
||||
g = displayio.Group(scale=1, x=(width-cam.width)//2, y=(height-cam.height)//2)
|
||||
tg = displayio.TileGrid(bitmap,
|
||||
pixel_shader=displayio.ColorConverter(input_colorspace=displayio.Colorspace.RGB565_SWAPPED)
|
||||
)
|
||||
g.append(tg)
|
||||
display.show(g)
|
||||
|
||||
t0 = time.monotonic_ns()
|
||||
display.auto_refresh = False
|
||||
while True:
|
||||
cam.capture(bitmap)
|
||||
bitmap.dirty()
|
||||
display.refresh(minimum_frames_per_second=0)
|
||||
t1 = time.monotonic_ns()
|
||||
print("fps", 1e9 / (t1 - t0))
|
||||
t0 = t1
|
||||
Loading…
Reference in a new issue