OpenCV Tutorial

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library.
OpenCV consists of a series of C functions and a small number of C++ classes, and also provides interfaces in languages such as Python, Java, and MATLAB.
OpenCV provides a large number of computer vision algorithms and image processing tools, widely used in image and video processing, analysis, and machine learning.
OpenCV is designed to provide a set of simple and easy-to-use computer vision foundation libraries, helping developers quickly build complex visual applications.
What you need to know before studying this tutorial
OpenCV supports many programming languages, but Python and C++ are the two most commonly used; Python has simple and easy-to-learn syntax, suitable for beginners.
Before starting to learn the OpenCV tutorial, we need to have a basic foundation in Python. If you are not yet familiar with Python, you can read our tutorial:
Historical development
The OpenCV project was first launched by Intel in 1999, dedicated to CPU-intensive tasks, as part of a plan that included things like ray tracing and 3D display.
-
In 1999, the OpenCV project was launched by Intel Research, aiming to promote computer vision research and applications.
-
In 2000, the first version of OpenCV was released.
-
In 2006, OpenCV 1.0 was released.
-
In 2009, OpenCV 2.0 was released, adding support for Python.
-
In 2015, OpenCV 3.0 was released, adding support for deep learning.
-
In 2018, OpenCV 4.0 was released, further optimizing performance and features.
Example
OpenCV reads and displays an image:
Example
Import the OpenCV library and use the alias cv instead of cv2
import
cv2
as
cv
Replace "path/to/image" with the actual image path, such as "cat.jpg" or "C:/images/dog.png"
img
=
cv.
imread
(
"path/to/image"
)
If the image path is wrong or the file does not exist, cv.imread() returns None
if
img
is
None
:
Print error information
(
"Error: Could not load image."
)
Exit program
exit
(
)
"Display window" is the name of the display window and can be customized
img is the image data to be displayed
cv.
imshow
(
"Display window"
,
img
)
Wait for key input
The parameter 0 means wait indefinitely until the user presses any key
The return value k is the ASCII code of the key pressed by the user
k
=
cv.
waitKey
(
0
)
Check whether the user pressed the Esc key (ASCII code 27)
if
k
==
27
:
Close all OpenCV windows
cv.
destroyAllWindows
(
)
Related links
- OpenCV official website https://opencv.org/
- OpenCV source code:https://github.com/opencv/opencv
- OpenCV documentation:https://docs.opencv.org/