Orange (Armbian) Pi: control the camera in Python with OpenCV [Exclusive Guide]

2:34 pm March 1, 20178276

in tutorial previous , we saw how to fly (view the live image, save a cliché and a video clip using the keyboard) on a Raspberry Pi under Raspbian. In this tutorial, we will do the same thing but on a Orange Pi Lite (WiFi version). Unfortunately it is not possible to use the library Picamera , which is designed to work exclusively for the Raspberry Pi. We therefore have to use OpenCV which is a very powerful Open Source Library.

as we have seen in this article, the CSI of the Orange Pi connector is different from that of the Raspberry Pi. I bought the camera 2MP sold by Orange Pi ( £ 6 on Aliexpress ). The quality of the image is nowhere near that of the v2.1 Raspberry Pi 8MP camera, but for beginners, the price/quality ratio is unbeatable.

Let’s start by preparing the environment.

update of the system Armbian

unless you just do it, the best is to always start with a small update of the system

Installation of python 2.7

once the system up-to-date, you can install Python 2.7. Why not Python 3 do you say? It is possible without any problems. You can choose according to your level. If you’re new, you’ll find many more examples on Python 2.7.

we also install the package manager for python ( pip ). Indeed, all deposits may not be reported in the sources of the Armbian distribution. Execute the following command to install the pip command:

there are many tutorials on the Web that explain how to install OpenCV (on ‘ Raspberry or Orange ‘) in a virtual environment from source code. It is a solution, but to be tested, it is long (half a big day of compilation on my Orange Pi Lite) and especially the use of the virtual environment is tedious, especially for if you’re new. Here we follow the shortest path, we’re just going to install the library with this simple command

accept all questions.

place you in the directory of your choice and open a new document, for example testcam_orangepi.py. Paste the code below.

did this code?

we call the library OpenCV 2 ( import cv2 )

we created a object c that captures the video stream sent by the camera (0), that is to say one that is related to / dev/video0 .

we show the image of the camera until the Escape key is pressed

reads the video stream (c.read) and it is stored in the variable f ( _ , f = c .read () ).

then it displays the video stream using imshow which takes as a parameter:

  • the title of the window in which airs the video stream
  • the variable that contains the video stream

first test

save the script (CTRL + X then Y) and run the

Ah It doesn’t work!

why it doesn’t work?

first of all, we know that the cv2 (OpenCV) library works. It’s already good news, we will not have to compile everything from source! In the error googlisant ( libv4l2 : error setting pixformat : Operation not permitted ), we quickly hit article of the designer of the vidcopy script that allows you to copy the video stream produced by the library v4l2loopback .

Let’s just follow the Leonardo Lontra tutorial .

installation of v4l2loopback