Getting started with OpenMV Cam M7

OpenMV Cam M7 PinOut (source : openmv.io)

Simply put OpenMV wants to be Arduino of computer vision community. Easy to setup and simple to use. It comes with an embedded camera and runs on 32 bit Cortex – M7 CPU. In this post will try to read a QR code using OpenMV and print the contents on serial monitor.

Reading QR code using OpenMV

There isn’t lot of memory (RAM) available on this board, so we can’t keep many images in buffer . The board also comes with SD card slot. There is support for many machine vision related algorithms. All these algorithms will be ran locally on the controller and produces results. We can take actions based on these results.

Controller features

M7 version comes with a STM32F765VI controller, that can run at 216 MHz.

512 KB of ram (128KB of heap, 384KB of FrameBuffer)
2MB flash
runs at 216 MHz

OpenMV Camera capabilities

The OpenMV Cam board comes with a OV7725 camera.
The camera supports taking grayscale pictures at 640 * 480 and RGB pictures at 320 * 240 (can support 640 * 480 if we use JPEG)

Setting up environment

To interact with OpenMV cam, we need to setup OpenMV IDE. Download executable for windows, for other platforms see this page.

Remove the cap on top camera and connect the OpenMV board to computer using provided micro USB cable. Click connect in OpenMV IDE, the IDE will automatically detect the board and connect to it.

Running QR Code reader example

Go to files and load QR code example

loading QR code example

Once the example code is loaded, you can see the live stream in frame buffer. If a QR code is present in the center of the frame, OpenMV will detect it and draws a rectangle around it. It will also print the QR code content to serial monitor.

Running QR Code example

OpenMV QR Code reader example

import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must turn this off to prevent image washout…
clock = time.clock()
while(True):
     clock.tick()
     img = sensor.snapshot()
     img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
     for code in img.find_qrcodes():
         img.draw_rectangle(code.rect(), color = (255, 0, 0))
         print(code)
     print(clock.fps())

we set the format to RGB and then set the resolution to 320 * 240 (QVGA). skip_frames will skip the frames for given number of milliseconds.

Then we will start a for-ever while loop. In loop we will capture a frame using snapshot method. The snapshot method will return the captured frame and we can run the find_qrcodes method to detect QR codes present in the frame. find_qrcodes will return a QR code list, we can loop over the list and draw rectangle around the detected QR code.

Add a Comment

Your email address will not be published. Required fields are marked *