At night, my mother sleeps quietly - we collect OpenCV for Raspbian
3r33570. The last couple of weeks have been hard for our team. Produced OpenCV 4 , and with it, prepared for Intel's OpenVINO toolkit R? which includes OpenCV. You think, I’ll distract myself for a while, I’ll see, as usual, the OpenCV forums, yes user comments, and then you, it became fashionable to say that OpenCV is not IoT, what to collect under Raspberry Pi - solder is not enough, that at night 3r36363. make -j2 3r31313. set - in the morning will be ready, if you're lucky. 3r33571. 3r? 3572.
3r33570. Therefore, I propose to join hands and see how you can build an OpenCV library for a 32-bit operating system running on an ARM processor using machine resources with a 64-bit OS, driven by excellent CPU architecture.
Sorcery
Cross compilation, no other way! 3r33571. 3r318. 3r3566. 3r? 3572.
Problem statement
3r? 3572.
3r33570. Compilation directly on the microcontroller, which is commonly called native, is really laborious, so we’ll look at a way to build a project here that allows stronger computing devices (let's call them hosts) to prepare binaries for their small relatives. Moreover, both machines may have different CPU architectures. This is cross-compiling. 3r33571. 3r? 3572.
3r33570. So, for the preparation of raspberry cake stuffed with OpenCV, we need: 3r33571. 3r? 3572.
3r33333.
3r33382. The carcass docker image of Ubuntu ???r3333391.
3r33382. The host machine is more powerful than the Raspberry Pi (otherwise what’s the point, isn't it?)
3r33382. Cross-compiler under ARMhf, as well as libraries of the corresponding architecture 3r-3391.
3r33393. 3r? 3572.
3r33570. The entire assembly process of OpenCV will occur on the host machine. I use Ubuntu in my home. With another version of Linux, there should be no problems with playback. For Windows users, my sincere wishes not to give up and try to figure it out. 3r33571. 3r? 3572.
Installing Docker
3r? 3572.
3r33570. I started my acquaintance with docker about a week ago, so gourmets should add salt and syntactic sugar to taste. We have enough with you three ingredients - Dockerfile, the concept of the image and the container. 3r33571. 3r? 3572.
3r33570. Docker itself is a tool for creating and reproducing the configuration of any operating system with the required set of components. A dockerfile is a set of shell commands that you usually use on a host machine, but in this case they all apply to the so-called docker
image 3r33571. 3r? 3572.
3r33570. In order to deliver the docker, consider the easiest way: order a package through the 3r36363 delivery service. apt-get : 3r? 3572.
3r? 3574. 3r3164. sudo apt-get install -y docker.io 3r31414. 3r? 3572.
3r33570. Let's give the docker daemon everything he asks for and logout from the system (notice login accordingly). 3r33571. 3r? 3572.
3r? 3574. 3r3164. sudo usermod -a -G docker $ USER 3r31414. 3r? 3572.
3r388. Prepare the workspace 3r? 3572.
3r33570. Raspberry Pi (in my case RPI 2 Model B) in the most common preparation is the ARMv7 CPU with the Raspbian (Debian based) operating system. We will create 3r36363. docker an image based on Ubuntu 16.0? in which we report the cross-compiler, arm libraries and build OpenCV there. 3r33571. 3r? 3572.
3r33570. Create a daddy, where our will lie. Dockerfile
: 3r? 3572.
3r? 3574. 3r3164. mkdir ubuntu16_armhf_opencv && cd ubuntu16_armhf_opencv
touch Dockerfile 3r31414. 3r? 3572.
3r33570. Add information about the base OS and armhf
architecture for the installer package apt-get
: 3r? 3572.
3r? 3574. 3r33575. FROM ubuntu: ???r3r3621.
USER root
RUN dpkg --add-architecture armhf
RUN apt-get update 3r31414. 3r? 3572.
3r33570. Note commands like FROM 3r31313. , 3r36363. RUN 3r31313. - This is the syntax 3-333563. docker
and are written in the generated test file 3r33535. Dockerfile . 3r33571. 3r? 3572.
3r33570. Returning to the parent directory 3r33535. ubuntu16_armhf_opencv and try to create our docker image: 3r? 3572.
3r? 3574. 3r3164. docker image build ubuntu16_armhf_opencv 3r31414. 3r? 3572.
3r33570. During the execution of the command apt-get update
you should lead to see errors of the following kind: Err:[число] xenial[чего-нибудь]armhf Packages
3r33571. 3r? 3572.
3r? 3574. 3r3164. Ign: 30 [url]http://archive.ubuntu.com/ubuntu xenial-backports /armhf Packages
Ign: 32 http://archive.ubuntu.com/ubuntu xenial-backports /universe armhf Packages
Err: 7 http://archive.ubuntu.com/ubuntu xenial /main armhf Packages
404 Not Found
Ign: 9 http://archive.ubuntu.com/ubuntu xenial /restricted armhf Packages
Ign: 18 http://archive.ubuntu.com/ubuntu xenial /universe armhf Packages
Ign: 20 http://archive.ubuntu.com/ubuntu xenial /multiverse armhf Packages
Err: 22 http://archive.ubuntu.com/ubuntu xenial-updates /main armhf Packages
404 Not Found
Ign: 24 http://archive.ubuntu.com/ubuntu xenial-updates /restricted armhf Packages
Ign: 26 http://archive.ubuntu.com/ubuntu xenial-updates /universe armhf Packages
Ign: 28 http://archive.ubuntu.com/ubuntu xenial-updates /multiverse armhf Packages
Err: 30 http://archive.ubuntu.com/ubuntu xenial-backports /armhf Packages
404 Not Found
Ign: 32 http://archive.ubuntu.com/ubuntu xenial-backports /universe armhf Packages 3r31414. 3r? 3572.
3r33570. If you spy in the file 3r36363. /etc/apt/sources.list then each such error corresponds to a line, for example: 3r33571. 3r? 3572.
3r33570. Error 3r33571. 3r? 3572.
3r? 3574. 3r33575. Err: 22 http://archive.ubuntu.com/ubuntu xenial-updates /main armhf Packages
404 Not Found 3r31414. 3r? 3572.
3r33570. The line in /etc/apt/sources.list : 3r? 3572.
3r? 3574. 3r33575. deb http://archive.ubuntu.com/ubuntu/xenial-updates main restricted 3r31414. 3r? 3572.
3r33570. Solution :
Split into two: 3r? 3572.
3r? 3574. 3r33575. deb[arch=amd64]http://archive.ubuntu.com/ubuntu/xenial-updates main restricted
deb[arch=armhf]http://ports.ubuntu.com/ubuntu-ports/xenial-updates main restricted 3r31414. 3r? 3572.
3r33570. Thus, it is necessary to replace several sources of packages. In our docker, we will replace them all with one team: 3r33571. 3r? 3572.
3r? 3574. 3r33575. RUN sed -i -E 's | ^ deb ([^ ]+) (. *) $ | Deb[arch=amd64]1 2ndeb[arch=armhf]http://ports.ubuntu.com/ubuntu-ports/2 | ' /etc/apt/sources.list 3r31414. 3r? 3572.
3r33570. Now apt-get update
should work without errors. 3r33571. 3r? 3572.
We put the necessary packages
3r? 3572.3r33570. We need to put the host packages such as 3r33563. git , 3r36363. python-pip , 3r36363. cmake and 3r36363. pkg-config , as well as 3r36363. crossbuild-essential-armhf that there is a set of gcc /g ++ cross-compilers (3r33535. arm-linux-gnueabihf-gcc 3r3-3613. and 3r33535. arm-linux-gnueabihf-g ++ ) and the system libraries of the appropriate architecture: 3r? 3572.
3r? 3574. 3r33575. RUN apt-get install -y git python-pip cmake pkg-config crossbuild-essential-armhf 3r31414. 3r? 3572.
3r33570. From the unusual - we also download GTK (used for drawing windows in the highgui module), GStreamer and Python, but with an explicit indication of the foreign architecture: 3r33571. 3r? 3572.
3r? 3574. 3r33575. RUN apt-get install -y --no-install-recommends
libgtk2.0-dev: armhf
libpython-dev: armhf
libgstreamer1.0-dev: armhf
libgstreamer-plugins-base1.0-dev: armhf
libgstreamer-plugins-good1.0-dev: armhf
libgstreamer-plugins-bad1.0-dev: armhf 3r31414. 3r? 3572.
3r33570. A further - we clone and collect, indicating the necessary flags: 3r? 3572.
3r? 3574. 3r33575. RUN git clone https://github.com/opencv/opencv --depth 1
RUN mkdir opencv /build && cd opencv /build &&
export PKG_CONFIG_PATH = /usr /lib /arm-linux-gnueabihf /pkgconfig &&
cmake -DCMAKE_BUILD_TYPE = Release
-DOPENCV_CONFIG_INSTALL_PATH = "cmake"
-DCMAKE_TOOLCHAIN_FILE = "/opencv /platforms /linux /arm-gnueabi.toolchain.cmake"
-DWITH_IPP = OFF
-DBUILD_TESTS = OFF
-DBUILD_PERF_TESTS = OFF
-DOPENCV_ENABLE_PKG_CONFIG = ON
-DPYTHON2_INCLUDE_PATH = "/usr /include /python2.7"
-DPYTHON2_NUMPY_INCLUDE_DIRS = "/usr /local /lib /python2.7 /dist-packages /numpy /core /include"
-DENABLE_NEON = ON
-DCPU_BASELINE = "NEON"
3r31414. 3r? 3572.
3r33570. where is 3r33571. 3r? 3572.
3r33333.
3r33382. 3r33570. 3r33535. CMAKE_TOOLCHAIN_FILE - path to the cmake file, which defines the cross-compilation process (sets the required compiler, limits the use of host libraries. 3r3571. 3r33535.
3r3333391.
3r33382. 3r33570. 3r33535. WITH_IPP = OFF , - disable heavy dependencies. 3r33571. 3r? 3572.
3r3333391.
3r33382. 3r33570. 3r33535. BUILD_TESTS = OFF , 3r36363. BUILD_PERF_TESTS = OFF , disable test build. 3r33571. 3r? 3572.
3r3333391.
3r33382. 3r33570. 3r33535. OPENCV_ENABLE_PKG_CONFIG = ON - so that pkg-config can find dependencies such as GTK. 3r33535. PKG_CONFIG_PATH 3r3-3613. - the right way, where
pkg-config
will search for libraries. 3r33571. 3r? 3572. 3r3333391.
3r33382. 3r33570. 3r33535. PYTHON2_INCLUDE_PATH 3r3363613. , 3r36363. PYTHON2_NUMPY_INCLUDE_DIRS - paths required for cross-compiling wrappers for python2. 3r33571. 3r? 3572.
3r3333391.
3r33382. 3r33570. 3r33535. ENABLE_NEON = ON , 3r36363. CPU_BASELINE = "NEON" - we allow NEON optimization. 3r33571. 3r? 3572.
3r3333391.
3r33382. 3r33570. 3r33535. OPENCV_CONFIG_INSTALL_PATH - adjusts the location of files in
install
directories. 3r33571. 3r? 3572. 3r3333391.
3r33393. 3r? 3572.
3r33570. The main thing that you should pay attention after the execution of
cmake
that all the necessary modules are built (python? for example): 3r33571. 3r? 3572. 3r? 3574. 3r33575. - OpenCV modules:
- To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc java_bindings_generator ml objdetect photo python2 python_bindings_generator stitching ts video video
- Disabled: world
- Disabled by dependency: -
- Unavailable: java js python3
- Applications: tests perf_tests apps
- Documentation: NO
- Non-free algorithms: NO 3r31414. 3r? 3572.
3r33570. and the necessary dependencies, such as GTK, were found: 3r33571.
3r? 3574. 3r33575. - GUI: 3r3621. - GTK +: YES (ver ???)
- GThread: YES (ver ???)
- GtkGlExt: NO
- 3r3621. - Video I /O:
- GStreamer:
- base: YES (ver ???)
- video: YES (ver ???)
- app: YES (ver ???)
- riff: YES (ver ???)
- pbutils: YES (ver ???)
- v4l /v4l2: linux /videodev2.h 3r31414. 3r? 3572.
3r33570. It remains only to call
make
, 3r36363. make install and wait for the end of the assembly: 3r? 3572. 3r? 3574. 3r33575. Successfully built 4dae6b1a7d32 3r31414. 3r? 3572.
3r33570. Use this
id
image in order to put the tag and create a container: 3r33571. 3r? 3572. 3r? 3574. 3r33575. docker tag 4dae6b1a7d32 ubuntu16_armhf_opencv: latest
docker run ubuntu16_armhf_opencv 3r31414. 3r? 3572.
3r33570. And it remains for us to pump the collected OpenCV from the container. First we look at the identifier of the created container: 3r33571. 3r? 3572.
3r? 3574. 3r33575. $ docker container ls --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e94667fe60d2 ubuntu16_armhf_opencv "/bin /bash" 6 seconds ago Exited (0) 5 seconds ago clever_yalow 3r31414. 3r? 3572.
3r33570. And copy the install directory with OpenCV installed: 3r33571. 3r? 3572.
3r? 3574. 3r33575. docker cp e94667fe60d2: /opencv /build /install /./
mv install ocv_install 3r31414. 3r? 3572.
Laying the table
3r? 3572.3r33570. We copy 3r36363. ocv_install on the Raspberry Pi, install paths and try to run OpenCV from python. 3r33571. 3r? 3572.
3r? 3574. 3r33575. export LD_LIBRARY_PATH = /path /to /ocv_install /lib /: $ LD_LIBRARY_PATH
export PYTHONPATH = /path /to /ocv_install /python /: $ PYTHONPATH 3r31414. 3r? 3572.
3r33570. Let's run the detection example using the MobileNet-SSD neural network from 3r3505. https://github.com/chuanqi305/MobileNet-SSD : 3r? 3572.
3r? 3574. 3r33511. import cv2 as cv
print cv .__ file__
classes =['backgroud', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat',
'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person',
'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
cap = cv.VideoCapture (0)
net = cv.dnn.readNet ('MobileNetSSD_deploy.caffemodel', 'MobileNetSSD_deploy.prototxt')
cv.namedWindow ('Object detection', cv.WINDOW_NORMAL)
while cv.waitKey (1)! = 27:
hasFrame, frame = cap.read ()
if not hasFrame:
break
frame_height, frame_width = frame.shape[0], frame.shape[1]
blob = cv.dnn.blobFromImage (frame, scalefactor = ???? size = (30? 300),
mean = (127.? 127.? 127.5))
net.setInput (blob)
out = net.forward ()
for detection in out.reshape (-? 7):
classId = int (detection[1])
confidence = float (detection[2])
xmin = int (detection[3]* frame_width)
ymin = int (detection[4]* frame_height)
xmax = int (detection[5]* frame_width)
ymax = int (detection[6]* frame_height)
if confidence> 0.5:
cv.rectangle (frame, (xmin, ymin), (xmax, ymax), color = (25? ? 255), thickness = 3)
label = '% s:% .2f'% (classes[classId], confidence)
labelSize, baseLine = cv.getTextSize (label, cv.FONT_HERSHEY_SIMPLEX, 0.? 1)
ymin = max (ymin, labelSize[1])
cv.rectangle (frame, (xmin, ymin - labelSize[1]), (xmin + labelSize[0], ymin + baseLine), (25?0?25), cv.FILLED)
cv.putText (frame, label, (xmin, ymin), cv.FONT_HERSHEY_SIMPLEX, 0.? (? ? 0))
cv.imshow ('Object detection', frame) 3r3363613. 3r31414. 3r? 3572.
3r33570. 3r33558. 3r33571. 3r? 3572.
3r33570. That's all, the complete assembly takes no more than 20 minutes. I am applying the final version of 3r33563. Dockerfile below and take this opportunity to offer a short survey from the OpenCV team for those who once had experience with the library: 3r36565. https://opencv.org/survey-2018.html 3r3-3566. . 3r33571. 3r? 3572.
3r33570. And yes, congratulations on OpenCV 4! This is not just the work of a separate team, it is the work of the entire community - OpenCV 4 you. 3r33571. 3r? 3572.
3r? 3574. 3r33575. FROM ubuntu: ???r3r3621.
USER root
RUN dpkg --add-architecture armhf
RUN sed -i -E 's | ^ deb ([^ ]+) (. *) $ | Deb[arch=amd64]1 2ndeb[arch=armhf]http://ports.ubuntu.com/ubuntu-ports/2 | ' /etc/apt/sources.list
RUN apt-get update &&
apt-get install -y --no-install-recommends
cmake
pkg-config
crossbuild-essential-armhf
git
python-pip
libgtk2.0-dev: armhf
libpython-dev: armhf
libgstreamer1.0-dev: armhf
libgstreamer-plugins-base1.0-dev: armhf
libgstreamer-plugins-good1.0-dev: armhf
libgstreamer-plugins-bad1.0-dev: armhf
RUN pip install numpy == ???
RUN git clone https://github.com/opencv/opencv --depth 1
RUN mkdir opencv /build && cd opencv /build &&
export PKG_CONFIG_PATH = /usr /lib /arm-linux-gnueabihf /pkgconfig &&
cmake -DCMAKE_BUILD_TYPE = Release
-DOPENCV_CONFIG_INSTALL_PATH = "cmake"
-DCMAKE_TOOLCHAIN_FILE = "/opencv /platforms /linux /arm-gnueabi.toolchain.cmake"
-DWITH_IPP = OFF
-DBUILD_TESTS = OFF
-DBUILD_PERF_TESTS = OFF
-DOPENCV_ENABLE_PKG_CONFIG = ON
-DPYTHON2_INCLUDE_PATH = "/usr /include /python2.7"
-DPYTHON2_NUMPY_INCLUDE_DIRS = "/usr /local /lib /python2.7 /dist-packages /numpy /core /include"
-DENABLE_NEON = ON
-DCPU_BASELINE = "NEON" && make -j4 && make install 3r31414. 3r3622.
3r3619. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r3620.
3r3622.
It may be interesting
weber
Author24-11-2018, 02:21
Publication DateGitHub / Open source / Python
Category- Comments: 0
- Views: 325
nursing test bank
nursing test bank