Sign inSign up

sipeom/rpi3python3opencv4

By sipeom

Updated over 4 years ago

Image
0

279

sipeom/rpi3python3opencv4 repository overview

Debian 10 (buster) Python 3.10.4 OpenCV 4.1.2

build_docker_opencv.sh

#!/bin/bash

sudo sed -i 's/CONF_SWAPSIZE=100/CONF_SWAPSIZE=2048/g' /etc/dphys-swapfile sudo /etc/init.d/dphys-swapfile stop sudo /etc/init.d/dphys-swapfile start

docker build .

sudo sed -i 's/CONF_SWAPSIZE=2048/CONF_SWAPSIZE=100/g' /etc/dphys-swapfile sudo /etc/init.d/dphys-swapfile stop sudo /etc/init.d/dphys-swapfile start

Dockerfile

FROM balenalib/raspberrypi3-debian:buster-build

RUN cwd=$(pwd)

https://superuser.com/questions/1423486/issue-with-fetching-http-deb-debian-org-debian-dists-jessie-updates-inrelease

RUN printf "deb http://archive.debian.org/debian/ buster main\ndeb-src http://archive.debian.org/debian/ buster main\ndeb http://security.debian.org buster/updates main\ndeb-src http://security.debian.org buster/updates main" > /etc/apt/sources.list

Install dependencies needed for building and running OpenCV

RUN apt-get update && apt-get install -y --no-install-recommends
# to build and install unzip
build-essential cmake pkg-config
checkinstall yasm
# to work with images libjpeg-dev libtiff-dev libjasper-dev libpng12-dev libtiff5-dev
# to work with videos libavcodec-dev libavformat-dev libswscale-dev
libxine2-dev libv4l-dev

RUN cd /usr/include/linux &&
sudo ln -s -f ../libv4l1-videodev.h videodev.h &&
cd $cwd

RUN apt-get install -y --no-install-recommends
libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
# needed by highgui tool libgtk2.0-dev
# for opencv math operations libatlas-base-dev gfortran
# others libtbb2 libtbb-dev qt5-default
libmp3lame-dev libtheora-dev
libvorbis-dev libxvidcore-dev libx264-dev
libopencore-amrnb-dev libopencore-amrwb-dev
libavresample-dev
x264 v4l-utils
# cleanup && rm -rf /var/lib/apt/lists/*
&& apt-get -y autoremove

Install python packages

RUN pip install --no-cache-dir
# OpenCV dependency numpy
# other usefull stuff ipython
# cleanup && find /usr/local
( -type d -a -name test -o -name tests )
-o ( -type f -a -name '.pyc' -o -name '.pyo' )
-exec rm -rf '{}' +
&& cd /
&& rm -rf /usr/src/python ~/.cache

Install OpenCV

ARG OPENCV_VERSION=4.1.2 RUN mkdir opencv && cd opencv
&& wget -O opencv.zip https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip
&& wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip
&& unzip opencv.zip
&& unzip opencv_contrib.zip
&& rm -rf opencv.zip
&& rm -rf opencv_contrib.zip

RUN cd opencv/opencv-${OPENCV_VERSION} && mkdir build && cd build
&& cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules
-D OPENCV_PYTHON3_INSTALL_PATH=/usr/local/lib/python3.10/site-packages/
-D ENABLE_NEON=ON
-D ENABLE_VFPV3=ON
-D BUILD_TESTS=OFF
-D OPENCV_ENABLE_NONFREE=ON
-D INSTALL_PYTHON_EXAMPLES=OFF
-D BUILD_EXAMPLES=OFF ..

RUN cd opencv/opencv-4.1.2/build
&& make RUN cd opencv/opencv-4.1.2/build
&& make install RUN cd opencv/opencv-4.1.2/build
&& ldconfig

RUN python -c "import cv2; print('Installed OpenCV version is: {}'.format(cv2.version))"

Tag summary

Content type

Image

Digest

Size

864.1 MB

Last updated

over 4 years ago

docker pull sipeom/rpi3python3opencv4