Member-only story

OpenCV & Python

Getting started with Computer Vision and Video in Python

Keno Leon
5 min readAug 7, 2020

--

OpenCV is the goto library for many image and video projects in Python, I remember struggling a bit with the documentation when starting out, so here’s a guided coding tour that I hope helps you.

Install OpenCV: <= Search for your particular environment, but this usually works:pip install opencv-python

What is it ?

OpenCV is a lot of things mostly dealing with processing images and video on your computer, my current interests are AI and real time applications, so this is biased towards that; for starters let’s look at simply capturing video from your webcam :

The above script consists of creating a video capture and then feeding that into a loop where frames are read and displayed one by one with imshow, the conditional checks for the exit command (type q to exit), cap.release and cv2.destroyAllWindows outside of the loop then deal with final cleanup. The result should be a video feed with the default OpenCV UI: 
Artifacts and washed colors from gif compression.

Colorspaces

If you notice the bottom part of the window you will see a readout with coordinates (x=629, y=112) and 3 changing numbers R: G: B: , this means that at those mouse coordinates the image is coded in 3 channels RED, GREEN and BLUE with values in each channel that go from 0–255 and this constitutes a colorspace called RGB

There are a number of color spaces and transformations available, and the subject is worthy of its own post, for now let’s just transform the previous example to another colorspace:

--

--

Keno Leon
Keno Leon

No responses yet