OpenCV Basics Part I - How to read Image with OpenCV

  OpenCV (Open Source computer vision library) is one of the popular libraries for machine learning, image processing, and computer vision. It is available for different platforms like Windows, Linux, Mac OS, iOS, and Android and it is also available with  C, C++, Python, and Java interfaces. Clearly, we are not here to discuss What OpenCV is? and why is it used? and if you are curious then,  I will recommend you to read and understand this (Nvidia guide) or this (Intel guide) or this (a blog).


Background:
The aim of this tutorial series is to teach and learn some basics of the OpenCV as I am not an expert of OpenCV, learning it myself and sharing my learning so that I can grasp this skill. This tutorial assumes you have basic knowledge of python. Remember, I am not a regular or experienced python programmer. My primary language is C# and Unity Game-engine while occasionally I code in JS, PHP, and python. The reason to mention my background is that a beginner python developer can follow this tutorial  (as I am a beginner) and expert of python and OpenCV can correct/improve this tutorial.
So, without further ado, we jump to the code and in this tutorial, we simply learn how can we read and display an image in OpenCV.

Code Snippet:
I have created this gist of code snippet with proper comments


How to run the Script:
Save this script in a folder with the name (OpenCVImageLoad) or whatever name you like. Then,  in the folder where your script is located use Shift + mouse right-click and Open Command window here. Now, finally, run this script in command like this python OpenCVImageLoad.py yourImage.extension but wait you should paste your desired image next to the script and put its name with extension instead oyourImage.extension

Explanation:
A little more explanation, first we imported cv2 and sys. cv2 is for openCV and sys is for reading image name input from the command-line. Next, we took a variable and use cv2 imread function to read input (image name input) from command line. Then, imShow method has used to show the image.



How to Read Image with OpenCV

 

How to Get Image Width, Height and Depth with OpenCV

 

How to Convert Image into grayscale with OpenCV

Post a Comment

0 Comments