Sitemap

OpenCV Basic example

2 min readJan 9, 2022

--

OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real-time computer vision. Originally developed by Intel, it was later supported by Willow Garage then Itseez (which was later acquired by Intel). The library is cross-platform and free for use under the open-source Apache 2 License. Starting with 2011, OpenCV features GPU acceleration for real-time operations. wiki

I am using python for this example and you can install python using Python Releases for Windows | Python.org link.

Get Sanjaya Deshapriya’s stories in your inbox

Join Medium for free to get updates from this writer.

You can verify your python version using below command

py --version

We are using pip to install opencv (PIP is a package management system used to install and manage software packages/libraries written in Python.) You can check your pip version using below command

py -m pip -V

To upgrade pip version

py -m pip install --upgrade pip

To install OpenCV use below command

py -m pip install opencv-python

Now OpenCV successfully installed on your machine. We can check OpenCV version using below python code

import cv2cv2.__version__
OpenCV Version

Open web cam and show video using imshow

import cv2cam = cv2.VideoCapture(0)if not cam.isOpened():
raise IOError("Cannot open webcam")
while True:
ret, frame = cam.read()
cv2.imshow('open web cam', frame)
c = cv2.waitKey(1)
if c == 27:
break
cam.release()
cv2.destroyAllWindows()

--

--

Sanjaya Deshapriya
Sanjaya Deshapriya

Written by Sanjaya Deshapriya

I am a Senior Software Engineer of Infor (Sri lanka/ Colombo). I start writing technical articles because it will help who is seeking technical knowledge.