Skip to content

guide opencv

Tianshu Huang edited this page Oct 12, 2018 · 2 revisions

Getting Started with OpenCV

This guide isn't very complete. If you have experience with OpenCV, or figured out a few things while learning, feel free to add to this page!

Installing OpenCV

In order to maintain inter-compatibility between Python modules, please use Python 3.

pip install opencv-python

or (if python3 outside of virtual environment in linux)

pip3 install opencv-python

Loading a test image

  • Reading an image:
# Read image
image = cv2.imread(filepath)
  • Image conversions:
# Convert grayscale
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Convert to HSV
image_hsv = cv2.cv2Color(image, cv2.COLOR_BGR2HSV)
  • Showing images:
cv2.imshow("This is an image window", image_gray)
cv2.waitKey(0)
cv2.destroyAllWindows()

The second two lines close the window whenever any keys are pressed in the window and continues execution. Since it's hard to write unit tests for problems without clear correct answers such as clustering problems, most vision algorithms will have to rely on visual inspection for testing.

Clone this wiki locally