Install OpenCV to work with Python


This tutorial will install OpenCV 2.4 for Python 2.7on Windows.

  1. Download OpenCV for your OS from https://sourceforge.net/projects/opencvlibrary/files/
  2. I use opencv cv 2.4 for windows https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.13/
  3. Extract opencv to a folder 
  4. Install Python 2.7
  5. Copy file cv2.pyd in folder /opencv/build/python/2.7/x64 to Python27/Lib/site-packages/
  6. We will need instal numpy library: pip install numpy
  7. 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

Popular posts from this blog

Recognize text from image with Python + OpenCV + OCR

Edit image with Android and OpenCV and JNI (C/C++)