Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DanielChuDC/c740b023abfeedd19992a6c0c68c3976 to your computer and use it in GitHub Desktop.
Save DanielChuDC/c740b023abfeedd19992a6c0c68c3976 to your computer and use it in GitHub Desktop.
Install opencv-python 4.5.3.56 on raspberry pi model 4
## Tested on
# pi@raspberrypi:~ $ python3 --version
# Python 3.7.3
# pi@raspberrypi:~ $ pip3 --version
# pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
curl https://pyenv.run | bash
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
source ~/.bashrc
pyenv
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo pip3 install opencv-python
sudo pip3 install opencv-contrib-python
sudo apt install libhdf5-103 libqtgui4 libatlas3-base libjasper1 libqt4-test
pip3 install -U numpy
sudo tee -a $HOME/cv2-demo.py <<EOF
import cv2
cap = cv2.VideoCapture(0)
while True:
# capture for each 1 frame
ret, frame = cap.read()
# if cannot cappture, close the window
if not ret:
break
# output to the window
cv2.imshow("Frame", frame)
key = cv2.waitKey(1)
# if interrupted, stop the process
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
EOF
python3 demo.py
@DanielChuDC
Copy link
Author

pi@raspberrypi:~ $ cat /etc/debian_version
10.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment