Raspberry Pi 4 pip install opencv-python
我尝试在我的树莓派4上安装opencv
1 | pip install opencv-python |
我收到以下错误
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting opencv-python
ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none)
ERROR: No matching distribution found for opencv-python
我用2019-07-10-raspbian-buster-full
1 | $ python -V |
Python 3.7.3
1 | $ pip --version |
pip 19.2.1 from
/home/pi/envs/django_env/lib/python3.7/site-packages/pip (python 3.7)
我看到了一些推荐的方法,但是没有一个起作用:
https://raspberrypi.stackexchange.com/questions/94990/installation-of-opencv-contrib-python-through-pip3-fails
1 | sudo pip3 install opencv-contrib-python==3.4.4.19 |
1 2 3 4 5 6 | $ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-100 $ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5 $ sudo apt-get install libatlas-base-dev $ sudo apt-get install libjasper-dev pip install opencv-contrib-python |
我记得它总是可以在我的其他树莓pis(2b和3)上使用。
是否可以在树莓派4上安装opencv?
嘿,您可以在具有更强版本的raspbian的raspberry pi上使用此脚本。
首先,要使用下面的代码,您必须制作opencv41.sh文件并将此代码放入opencv41.sh文件。 将此文件放入home。*在终端中使用bash opencv41.sh运行。 请记住,您应该先进入主目录,然后打开终端并输入此命令。让我知道它是否有效。
bash opencv41.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | sudo apt-get -y update sudo apt-get -y upgrade sudo apt-get -y install screen sudo apt-get -y install htop # substitute string1 for string2 globally 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 sudo sed -i '$a gpu_mem=128' /boot/config.txt sudo apt-get -y install build-essential cmake pkg-config sudo apt-get -y install libjpeg-dev libtiff-dev libjasper-dev libpng12-dev sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev sudo apt-get -y install libxvidcore-dev libx264-dev sudo apt-get -y install libgtk2.0-dev libgtk-3-dev sudo apt-get -y install libatlas-base-dev gfortran sudo apt-get -y install python3-dev wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.0.zip wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.1.0.zip unzip opencv.zip unzip opencv_contrib.zip # yes you really need to rename the directories mv opencv-4.1.0/ opencv mv opencv_contrib-4.1.0/ opencv_contrib # you have to make python3.6 env so it uses python3.6 for the build mkdir -p .virtualenvs python3 -m venv .virtualenvs/cv2_env source .virtualenvs/cv2_env/bin/activate # took a really long time pip3 install numpy cd ~/opencv mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \ -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 .. make -j4 sudo make install sudo ldconfig sudo apt-get update cd ~/opencv/build/lib/python3 mkdir -p ~/lib/cv2 cp cv2.cpython-37m-arm-linux-gnueabihf.so ~/lib/cv2 ln -s ~/lib/cv2/cv2.cpython-37m-arm-linux-gnueabihf.so ~/.virtualenvs/cv2_env/lib/python3.7/site-packages/cv2.so cd ~ # update /etc/dphys-swapfile to increase size # set CONF_SWAPSIZE=100 # set CONF_SWAPSIZE=2048 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 # update /boot/config.txt sudo sed -i 's/gpu_mem=128/gpu_mem=16/g' /boot/config.txt rm opencv.zip rm opencv_contrib.zip sudo rm -r opencv sudo rm -r opencv_contrib # to test # source ~/.virtualenvs/cv2_env/bin/activate # python # import cv2 # print(cv2.__version__) # you should see 4.1.0 |
自周日以来,我的Raspberry Pi 3B和当前的Raspbian版本都存在完全相同的问题。
在Python 2.7下,安装已完成,但是图像中有噪点,这是以前没有发生的。
PS:由于SD卡问题,我必须在周日完全重新安装Raspbian。
版本:
1 2 3 4 5 6 7 8 9 | Raspbian Buster with desktop and recommended software Image with desktop and recommended software based on Debian Buster Version:July 2019 Release date:2019-07-10 Kernel version:4.19 Python 3.7.3 PIP 19.2.1 |
当前已安装numpy软件包