Installing the required packages on system:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libfontconfig1-dev libcairo2-dev
sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
sudo apt-get install python3-dev
sudo apt-get install libilmbase23
sudo apt-get install libopenexr-dev
Installing and activating the python virtual environment:
mkdir env && cd env
python3 –m venv env
source env/bin/activate
Installing PIcamera and OpenCV4:
pip install “picamera[array]”
pip install opencv-contrib-python==4.1.0.25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import numpy as np import cv2 cap = cv2.VideoCapture(0) #Raspberryi camera #cap = cv2.VideoCapture(1) #USB camera #cap = cv2.VideoCapture('rtsp://login:password@192.168.1.243:554/12') #IP camera cap.set(3,640) # set Width cap.set(4,360) # set Height while(True): ret, frame = cap.read() #ret, img = cap.read() #frame = cv2.flip(frame, -1) #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('frame', frame) #cv2.imshow("input", img) #cv2.imshow('gray', gray) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() ''' 1280*720/640*360/320*180 ''' |
134