Install OpenCV to work with Python
This tutorial will install OpenCV 2.4 for Python 2.7on Windows.
- Download OpenCV for your OS from https://sourceforge.net/projects/opencvlibrary/files/
- I use opencv cv 2.4 for windows https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.13/
- Extract opencv to a folder
- Install Python 2.7
- Copy file cv2.pyd in folder /opencv/build/python/2.7/x64 to Python27/Lib/site-packages/
- We will need instal numpy library: pip install numpy
- Test with simple code:
import cv2 print "Read image with opencv" img = cv2.imread("E:/test.png") print "Convert to gray" img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) print "Write gray image" cv2.imwrite("E:/gray.png", img) print "------ Done -------"
Result:
Comments
Post a Comment