OpenCV & Python
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:
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
BLUE with values in each channel that go from
0–255 and this constitutes a colorspace called
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: