2

Recently I started working with Docker, I succeeded in building some images for the purpose of running my python script which uses OpenCV.

Now for the next step, I want to deploy these images on my Raspberry Pi3B+, but I failed in building them on the Pi. I've also tried pushing the image which I build successfully on my Ubuntu laptop then go on to Pi and pull the image to run container from it, but it didn't work either.

I found the reason is that all I did was trying to use a amd64 arch (my laptop) image on armv7 arch (my Pi) so that causes some kind of conflict.

I then tried some base images on Docker Hub which were created for armv7, for example: arm32v7/python:3.6, and here's my Dockerfile:

FROM arm32v7/python:3.6

RUN apt-get -y update && apt-get -y upgrade \
        && apt-get install -y python3-pip \
        python3-numpy \
        libblas-dev \
        liblapack-dev \
        python3-dev \
        libatlas-base-dev \
        gfortran \
        python3-setuptools \
        python3-scipy \
        && apt-get -y update \
        && apt-get -y install python3-h5py \
        libsm6 \
        libxext6 \
        libxrender-dev 


RUN pip3 install scipy \
                cython \
                keras \
                opencv-python \
                scikit-image 

COPY cut.py detect.py c9_0_04_46_23_0.jpg /opt/
COPY MODEL /opt/MODEL
RUN mkdir -p /opt/anh_cut


WORKDIR /opt/

ENTRYPOINT ["python3", "cut.py"]

An error occurred at OpenCV installation step:

Could not find a version that satisfies the requirement opencv-python

I also tried to replace pip config with:

[global]
extra-index-url=https://www.piwheels.org/simple

which is a repository of precompiled packages for arm architecture, but the same problem still occurred.

Is there any way for me to work around this problem? If not, can I just cross compile OpenCV on my laptop then copy to Dockerfile ? It would be nice if I could have some document to follow, thanks.

Aimery
  • 1,559
  • 1
  • 19
  • 24
Nguyen Nam
  • 23
  • 4

1 Answers1

0

Based on https://www.piwheels.hostedpi.com/, they support python version 3.4, 3.5 and 3.7. Here's a quote (emphasis is mine) :

Support

Wheels provided support all Raspberry Pi models (Pi 4, Pi 3, Pi 2, Pi 1 and Pi Zero). Wheels are provided for Raspbian Jessie (Python 3.4), Raspbian Stretch (Python 3.5) and Raspbian Buster (Python 3.7). See each package's project page for information on available wheels.


Keeping your modified pip config, and changing the FROM clause in the Dockerfile by :

FROM arm32v7/python:3.7-buster

might fix the issue.

Lescurel
  • 10,749
  • 16
  • 39
  • Thanks for your suggestion, ive been able to install opencv normally, but another problem came up, the import cv2 in my python script inside the container show error: **ImportError: libjasper.so.1: cannot open shared object file: No such file or directory**. I did some searching and found this answer but didnt quite work as well. Is there any chance that i can find the libjasper source code and install in through copying and install in Dockerfile? – Nguyen Nam Mar 07 '20 at 13:32