I am doing lots of Image Processing projects based on OPENCV and Python. This is how to setup it up on a Windows PC.
You need to download Anaconda and OpenCV.
OpenCV download link:
https://sourceforge.net/projects/opencvlibrary/
The version I have on my machine is 3.2.0. Executable file is "opencv-3.2.0-vc14.exe".
Anaconda download link:
https://www.anaconda.com/download/
For the Anaconda, I still use Python 2.
The version I have on my machine is 4.4.0. Executable file is "Anaconda2-4.4.0-Windows-x86_64.exe"
You need to install Anaconda. After installation you will have access with the default IDE which is Spyder. I have a stream.py script when I captured my screen.
It is now time to install OpenCV.
Put the .exe installer to the C: drive and install it. You will have an opencv folder after installation.
Next step is to copy-paste cv2.pyd file to Anaconda Site-packages to be able to import it to our Python scripts.
The location of cv2.pyd file is located here:
For 64bit machines (C:\opencv\build\python\2.7\x64)
For 32bit machiens (C:\opencv\build\python\2.7\x86)
Paste it on this location. (C:\ProgramData\Anaconda2\Lib\site-packages)
You should be able to import cv2 on a python script.
On the Spyder console on the lower right part. I use IPython console.
Try to input import cv2.
Then check version by print cv2.__version__.
You can now try to access the webcam on your laptop or PC.
import cv2, time
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
print ret
if ret == 1:
cv2.imshow('frame',frame)
else:
print "no video"
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
You can also access IP cameras.
cap = cv2.VideoCapture("http://192.168.1.7:8080")
And also input video files.
cap = cv2.VideoCapture("test.mp4")
No comments:
Post a Comment