Quick start
===========
.. image:: ../camera.jpg
:class: framed
:alt: OpenMV Cam
:width: 100%
Welcome -- we're excited to introduce you to the OpenMV Cam, a small,
programmable camera that runs Python right on the device. Write a few
lines of code, press run, and the camera starts seeing: detecting
faces, tracking colours, reading tags, following lines -- no PC in the
loop and no heavy setup to wade through first.
This quick start guide will have you up and running in a few minutes:
you'll install the IDE, connect your camera, and run a live face
detector as your very first script.
`Install OpenMV IDE `__
----------------------------------------------------------
OpenMV IDE is the desktop application for writing scripts, running
them on the camera, and watching the results live. Download it for
Windows, macOS, or Linux `here `__,
then install it:
* **Windows** -- run the installer. It installs the IDE along with
the camera's USB drivers; follow the default prompts.
* **macOS** -- open the ``.dmg`` and drag **OpenMV IDE** onto the
Applications folder.
* **Linux** -- run ``chmod +x openmv-ide-*.run && ./openmv-ide-*.run``,
then follow the installer prompts.
.. note::
For automated or headless setups, the installers also run from the
command line with silent-install flags. See the `openmv-ide README
`__
for the exact per-platform commands.
Connect your camera
-------------------
Plug the camera into your computer with a USB data cable. Wait for
its drive to mount and the blue LED to start blinking, then click the
connect button -- the plug icon at the bottom of the toolbar.
The first time you connect, the IDE compares the camera's firmware
against the version it ships with and offers to update it. Accept the
prompt to flash the latest firmware; it takes a few seconds, and the
IDE reconnects on its own when it finishes.
If the camera does not show up, or you want the details of what
connecting and updating do, see :doc:`tools/ide/connecting` and
:doc:`tools/ide/firmware`.
.. note::
Stuck on something? Post on the `OpenMV forums
`__ -- the community and the OpenMV team
are happy to help.
Run your first script
---------------------
Your OpenMV Cam ships with Google's MediaPipe **BlazeFace** face
detector on flash. Paste this script into the editor:
::
import csi
import time
import ml
from ml.postprocessing.mediapipe import BlazeFace
# Set up the camera sensor.
csi0 = csi.CSI()
csi0.reset() # Initialize the sensor to a known state.
csi0.pixformat(csi.RGB565) # Capture 16-bit colour.
csi0.framesize(csi.QVGA) # Set a small, fast frame size.
# BlazeFace was trained on square images, so crop to a centred
# square the size of the sensor's height.
side = csi0.height()
csi0.window((side, side))
# Load the built-in face detector. The post-processor turns the
# network's raw output into a list of detections; threshold sets how
# confident a detection must be to count.
model = ml.Model("/rom/blazeface_front_128.tflite",
postprocess=BlazeFace(threshold=0.4))
clock = time.clock() # For measuring the frame rate.
while True:
clock.tick()
img = csi0.snapshot() # Capture one frame.
# predict() runs the network and returns one
# ((x, y, w, h), score, keypoints) tuple per detected face.
for rect, score, keypoints in model.predict([img]):
# Draw the box around the face...
ml.utils.draw_predictions(img, [rect], ("face",),
((0, 0, 255),), format=None)
# ...and mark the six landmarks: eyes, nose, mouth, ears.
ml.utils.draw_keypoints(img, keypoints, color=(255, 0, 0))
print(clock.fps(), "fps")
Press the green **Run** button and point the camera at a face. The
frame buffer viewer draws a box around each face and marks the eyes,
nose, mouth, and ears, while the serial terminal prints the frame
rate.
This script -- and one for nearly every feature the camera has -- is
also built into the IDE under **File → Examples**, filtered to your
connected board. Open one, press run, and start exploring what the
camera can do.
Where to go next
----------------
Where you jump in depends on what you already know. The tutorial has
three starting points -- new to Python, new to hardware, or ready for
machine vision -- so pick the one that fits. The references and the
IDE guide are here whenever you need them.
.. raw:: html