Hi sorry for not getting around to this until now. It helps it you remind me on the weekends. Otherwise I forget.
import sensor, image, time, pyb
from pyb import Pin, SPI
cs = Pin("P3", Pin.OUT_PP)
cs.high()
# The hardware SPI bus for your OpenMV Cam is always SPI bus 2.
spi = SPI(2, SPI.MASTER, baudrate=4000000, polarity=0, phase=0)
def send_image_format(img):
cs.low()
# Send width
spi.send((img.width() >> 24) & 0xFF)
spi.send((img.width() >> 16) & 0xFF)
spi.send((img.width() >> 8) & 0xFF)
spi.send((img.width() >> 0) & 0xFF)
# Send height
spi.send((img.height() >> 24) & 0xFF)
spi.send((img.height() >> 16) & 0xFF)
spi.send((img.height() >> 8) & 0xFF)
spi.send((img.height() >> 0) & 0xFF)
# Send size
spi.send((img.size() >> 24) & 0xFF)
spi.send((img.size() >> 16) & 0xFF)
spi.send((img.size() >> 8) & 0xFF)
spi.send((img.size() >> 0) & 0xFF)
cs.high()
def send_image(img):
cs.low()
spi.send(img)
cs.high()
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(10) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
img = img.compressed() # comment out to send uncompressed images...
# you'll have to increase the baud rate however.
send_image_format(img)
send_image(img)
print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
# connected to your computer. The FPS should increase once disconnected.
The code is pretty simple to follow. You can increase the SPI clock rate by much more to make it faster. You can also preform image manipulation, etc. before sending the image.
send_image.py (1.61 KB)