The Python OpenCV Cheat Sheet is your complete guide to mastering computer vision and image processing using Python. It's designed to be your trusty companion, helping you quickly understand the important ideas, functions, and techniques in the OpenCV library. Whether you're an experienced developer needing a quick reminder or a newcomer excited to start, this cheat sheet has got you covered.
In this article, we've gathered all the vital OpenCV concepts and explained them in simple terms. We've also provided practical examples to make things even clearer. You'll learn everything from how to handle images to using advanced filters, spotting objects, and even exploring facial recognition. It's all here to help you on your journey of discovering the amazing world of computer vision.
Python OpenCV Cheat Sheet 2023
Presenting the fully updated cheat sheet for mastering OpenCV and its array of commands
Core Operations
|
imread(image_path, flag) | This method is used to read an image from its path |
imshow(window_name, image) | It is used to show the image in the window. |
imwrite(filename, image) | This method is used to write or save an image using OpenCV. |
Reading Images
You can read an image in Python using OpenCV's cv.2imread() method. By default, OpenCV stores colored images in BGR(Blue, Green, and Red) format.
img = cv2.imread(image_path, flag)
The types of flags are described below:
|
cv2.IMREAD_COLOR | Read colored images |
cv2.IMREAD_GRAYSCALE | Read Grayscale images |
cv2.IMREAD_UNCHANGED | Read images with alpha channel |
Showing Images
The cv2.imshow() method is used to display an image in a window.
cv2.imshow(window_name, image)
Image Cropping
Cropping is the removal of unwanted outer areas from an image.
cropped_img = img[100:300, 100:300]
Saving an Image
The cv2.imwrite() method is used to save an image to any storage device. This will save the image according to the specified format in the current working directory.
cv2.imwrite(filename, image)
Drawing Shapes and Text on Images
OpenCV provides the following drawing functions to draw geometric shapes on images. It also provides functions to write text on images.
|
line(image, start_coordinates, end_coordinates, color_in_bgr, line_thickness) | By using this function we can create a line in the image from start coordinates to end coordinates with a certain thickness which can be mentioned specifically as well. |
rectangle(image,top_left_vertex_coordinates, lower_right_vertex_coordinates, color_in_bgr, thickness)
| This function is used to create a box with a certain thickness and color which can be specified as well. |
circle(image, center_coordinates, radius, color, thickness) | It is used to draw a circle whose centre and radius length is given with a certain thickness and the colour of the strokes of the circle. |
polylines(image, [pts], isClosed, color, thickness) | It is used to draw a polygon on any image whose vertex coordinates are provided. |
putText(image, ‘TextContent’, ‘text_starting_point_coordinates’,
‘fontToBeUsed’, ‘font_size’, ‘text_color’, ‘text_thickness’, ‘line_type’)
| It is used to write some text on the image loaded. |
Draw Line
The cv2.line() method is used to draw the line on an image.
cv2.line(image, (start_coordinates), (end_coordinates), (color_in_bgr),
line_thickness)
Draw Rectangle
The cv2.rectangle() method is used to draw a rectangle on an image.
cv2.rectangle(image, (‘top_left_vertex_coordinates’),
(‘lower_right_vertex_coordinates’),
(‘stroke_color_in_bgr’), ‘stroke_thickness’)
Draw Circle
The cv2.circle() method is used to draw a circle on an image.
cv2.circle(image, (‘center_coordinates’), (‘circle_radius’),
(‘color_in_bgr’), ‘stroke_thickness’)
Draw Polygon
The cv2.polylines() method is used to draw a polygon on any image.
cv2.polylines(image, [pts], isClosed, color, thickness)
Writing Text
The cv2.putText() method is used to write some text on an image.
cv2.putText(image, ‘TextContent’, (‘text_starting_point_coordinates’),
‘fontToBeUsed’, ‘font_size’, (‘text_color’, ‘text_thickness’, ‘line_type’)
Arithmetic Operations on Images
Arithmetic Operations like Addition, Subtraction, and Bitwise Operations(AND, OR, NOT, XOR) can be applied to the input images.
|
add(image1, image2) | This function is used to add two images. |
subtract(image1, image2) | This function is used to subtract two images. |
addWeighted(image1, weight1, image2, weight2, gammaValue) | This is also known as Alpha Blending. This is nothing but a weighted blending process of two images. |
bitwise_and(image1, image2, destination, mask) | This performs bitwise and logical operations between two images. |
bitwise_or(image1, image2, destination, mask) | This performs bitwise or logical operations between two images. |
bitwise_not(image, destination, mask) | This performs bitwise not logical operations between an image and a mask. |
bitwise_xor(image1, image2, destination, mask) | This performs bitwise xor logical operations between two images. |
Image Addition
We can add two images by using the cv2.add() method. This directly adds up image pixels in the two images.
cv2.add(image1, image2)
Image Alpha Blending
Alpha blending is the process of overlaying a foreground image on a background image which can be done using the addWeighted() method.
cv2.addWeighted(image1, weight1, image2, weight2, gammaValue)
Image Subtraction
We can subtract the pixel values in two images and merge them with the help of cv2.subtract(). The images should be of equal size and depth.
cv2.subtract(image1, image2)
Bitwise And
Bit-wise conjunction of input array elements.
cv2.bitwise_and(image1, image2, destination, mask)
Bitwise Or
Bit-wise disjunction of input array elements.
cv2.bitwise_or(image1, image2, destination, mask)
Bitwise Not
Inversion of input array elements.
cv2.bitwise_not(image, destination, mask)
Bitwise Xor
Bit-wise exclusive-OR operation on input array elements.
cv2.bitwise_xor(image1, image2, destination, mask)
Morphological Operations on Images
Python OpenCV Morphological operations are one of the Image processing techniques that process images based on shape. This processing strategy is usually performed on binary images.
|
erode(image, kernel, iterations=1) | Erosion primarily involves eroding the outer surface (the foreground) of the image. As binary images only contain two pixels 0 and 255, it primarily involves eroding the foreground of the image and it is suggested to have the foreground as white. |
dilate(image, kernel, iterations=1) | Dilation involves dilating the outer surface (the foreground) of the image. As binary images only contain two pixels 0 and 255, it primarily involves expanding the foreground of the image and it is suggested to have the foreground as white. |
morphologyEx(image, Morphology_method, kernel, iterations=1) | Some of the morphology methods are shown below:
- cv2.MORPH_GRADIENT
- cv2.MORPH_CLOSE
- cv2.MORPH_OPEN
- cv2.MORPH_TOPHAT
- cv2.MORPH_BLACKHAT
|
Erosion
Erosion primarily involves eroding the outer surface (the foreground) of the image. As binary images only contain two pixels 0 and 255, it primarily involves eroding the foreground of the image and it is suggested to have the foreground as white.
cv2.erode(image, kernel, iterations=1)
Dilation
Dilation involves dilating the outer surface (the foreground) of the image. As binary images only contain two pixels 0 and 255, it primarily involves expanding the foreground of the image and it is suggested to have the foreground as white.
cv2.dilate(image, kernel, iterations=1)
Opening
The opening involves erosion followed by dilation in the outer surface (the foreground) of the image. It is generally used to remove the noise in the image.
cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel, iterations=1)
Closing
Closing involves dilation followed by erosion in the outer surface (the foreground) of the image. It is generally used to remove the noise in the image.
cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel, iterations=1)
Morphological Gradient
The morphological gradient first applies erosion and dilation individually on the image and then computes the difference between the eroded and dilated image. The output will be an outline of the given image.
cv2.morphologyEx(image, cv2.MORPH_GRADIENT, kernel)
Top Hat
Top Hat is yet another morphological operation where an Opening is performed on the binary image and the output of this operation is a difference between the input image and the opened image.
cv2.morphologyEx(image, cv2.MORPH_TOPHAT, kernel)
Black Hat
The Black Hat enhances dark objects of interest on a bright background. The output of this operation is the difference between the closing of the input image and the input image.
cv2.morphologyEx(image, cv2.MORPH_BLACKHAT, kernel)
Image Transformation involves the transformation of images, such as scaling, rotating, cropping, etc for further usage.
|
resize(image, width, height, interpolation_method) | By using this method we can resize the image at hand for specific width and height.
Some of the methods that can be used for interpolation are as below:
- cv2.INTER_AREA
- cv2.INTER_CUBIC
- cv2.INTER_LINEAR
|
M = cv2.getRotationMatrix2D(center, angle, scale)
warpAffine(image, M, (width, height))
| Image rotation is a common image processing routine with applications in matching, alignment, and other image-based algorithms, in image rotation the image is rotated by a definite angle. We can also use cv2.rotate() function for image rotation. |
matrix = cv2.getPerspectiveTransform(src, dst) warpPerspective(image, matrix, dsize) | In Perspective Transformation, we can change the perspective of a given image or video for getting better insights into the required information. We need to provide the points on the image from which want to gather information by changing the perspective. We also need to provide the points inside which we want to display our image. |
Scaling
Image scaling is a process used to resize a digital image using the cv2.resize() method.
res = cv2.resize(img,(2width, 2height), interpolation)
The resize() method's Interpolation attribute has the following types: (Scaling types)
|
cv2.INTER_AREA | Used to shrink the image |
cv2.INTER_CUBIC | Bicubic interpolation |
cv2.INTER_LINEAR | Default interpolation technique used to zoom the image |
Translation
Translation refers to the rectilinear shift of an object i.e. an image from one location to another. If we know the amount of shift in the horizontal and vertical direction, then we can make a transformation matrix. Then, we can use the cv2.wrapAffine() function to implement these translations. This function requires a 2×3 array. The numpy array should be of float type.
T = np.float32([[1, 0, new_width], [0, 1, new_height]])
cv2.warpAffine(image, T, (original_width, original_height))
Rotation
Image rotation is a common image processing routine with applications in matching, alignment, and other image-based algorithms, in image rotation the image is rotated by a definite angle. We can also use cv2.rotate() function for image rotation.
M = cv2.getRotationMatrix2D(center, angle, scale)
cv2.warpAffine(image, M, (width, height))
Affline Transformation
In Affine transformation, all parallel lines in the original image will still be parallel in the output image. This can be done by using the cv2.getAfflineTransform() method.
M = cv2.getAffineTransform(pts1, pts2)
dst = cv2.warpAffine(img, M, (cols, rows))
Perspective Transformation
In Perspective Transformation, we can change the perspective of a given image or video to get better insights into the required information. We need to provide the points on the image from which want to gather information by changing the perspective. We also need to provide the points inside which we want to display our image.
matrix = cv2.getPerspectiveTransform(src, dst)
cv2.warpPerspective(image, matrix, dsize)
Image Thresholding
Thresholding is a technique in OpenCV, which is the assignment of pixel values about the threshold value provided. In thresholding, each pixel value is compared with the threshold value. If the pixel value is smaller than the threshold, it is set to 0, otherwise, it is set to a maximum value (generally 255).
|
cv2.threshold(source, thresholdValue, maxVal, thresholdingTechnique) | For every pixel, the same threshold value is applied. If the pixel value is smaller than the threshold, it is set to 0, otherwise, it is set to a maximum value. This can be achieved using the cv2.threshold() method.
|
cv2.adaptiveThreshold(source, maxVal, adaptiveMethod, thresholdType, blocksize, constant) | Adaptive thresholding is the method where the threshold value is calculated for smaller regions. This leads to different threshold values for different regions concerning the change in lighting. |
cv2.threshold(source, thresholdValue, maxVal, thresholdingTechnique) | In Otsu Thresholding, a value of the threshold isn’t chosen but is determined automatically. A bimodal image (two distinct image values) is considered. The histogram generated contains two peaks. |
Thresholding Techniques:
|
If pixel intensity is greater than the set threshold, the value is set to 255, else set to 0 |
Inverted or Opposite case of cv2.THRESH_BINARY |
If the pixel intensity value is greater than the threshold, it is truncated to the threshold. The pixel values are set to be the same as the threshold |
Pixel intensity is set to 0, for all the pixels' intensity, less than the threshold value |
Inverted or Opposite case of cv2.THRESH_TOZERO |
Simple Threshold
For every pixel, the same threshold value is applied. If the pixel value is smaller than the threshold, it is set to 0, otherwise, it is set to a maximum value. This can be achieved using the cv2.threshold() method.
cv2.threshold(source, thresholdValue, maxVal, thresholdingTechnique)
Adaptive Thresholding
Adaptive thresholding is the method where the threshold value is calculated for smaller regions. This leads to different threshold values for different regions with respect to the change in lighting.
cv2.adaptiveThreshold(source, maxVal, adaptiveMethod, thresholdType, blocksize, constant)
Otsu Thresholding
In Otsu Thresholding, a value of the threshold isn’t chosen but is determined automatically. A bimodal image (two distinct image values) is considered. The histogram generated contains two peaks. So, a generic condition would be to choose a threshold value that lies in the middle of both the histogram peak values.
cv2.threshold(source, thresholdValue, maxVal, thresholdingTechnique)
Edge/Line Detection (Features)
|
cv2.Canny(image, T_lower, T_upper, aperture_size, L2Gradient) | The Canny Edge Detection is an algorithm used for edge detection. It reduces noise using Gaussian Smoothing and computes image gradient using The Sobel filter. |
cv2.HoughLines(edges, 1, np.pi/180, 200) | The Hough Transform is a method that is used in image processing to detect any shape if that shape can be represented in mathematical form. It can detect the shape even if it is broken or distorted a little bit. |
cv2.HoughCircles(image, cv2.HOUGH_GRADIENT, 1, 20, param1 = 50, param2 = 30, minRadius = 1, maxRadius = 40) | Circle detection finds a variety of uses in biomedical applications, ranging from iris detection to white blood cell segmentation. |
cv2.cornerHarris(src, dest, blockSize, kSize, freeParameter, borderType) | Harris Corner detection algorithm was developed to identify the internal corners of an image. The corners of an image are basically identified as the regions in which there are variations in the large intensity of the gradient in all possible dimensions and directions. |
cv2.goodFeaturesToTrack(image, max_corner, quantity_level, min_distance) | The cv2.goodFeaturesToTrack() function in OpenCV is used for corner detection. |
cv2.drawKeypoints(input_image, key_points, output_image, colour, flag) | The distinguishing qualities of an image that make it stand out are referred to as key points in an image. The key points of a particular image let us recognize objects and compare images. This can be done by using the cv2.drawKeypoints() method. |
Canny Edge Detection
The Canny Edge Detection is an algorithm used for edge detection. It reduces noise using Gaussian Smoothing and computes image gradient using The Sobel filter. Finally, apply Hysteresis thresholding which that 2 threshold values T_upper and T_lower which are used in the Canny() function.
cv2.Canny(image, T_lower, T_upper, aperture_size, L2Gradient)
Houghline Method for Line Detection
The Hough Transform is a method that is used in image processing to detect any shape if that shape can be represented in mathematical form. It can detect the shape even if it is broken or distorted a little bit.
cv2.HoughLines(edges, 1, np.pi/180, 200)
Houghline Method for Circle Detection
Circle detection finds a variety of uses in biomedical applications, ranging from iris detection to white blood cell segmentation.
cv2.HoughCircles(image, cv2.HOUGH_GRADIENT, 1, 20, param1 = 50,
param2 = 30, minRadius = 1, maxRadius = 40)
Harris Corner Method for Corner Detection
Harris Corner detection algorithm was developed to identify the internal corners of an image. The corners of an image are basically identified as the regions in which there are variations in the large intensity of the gradient in all possible dimensions and directions.
cv2.cornerHarris(src, dest, blockSize, kSize, freeParameter, borderType)
Shi-Tomasi Method for Corner Detection
In Shi-Tomasi Method, the basic intuition is that corners can be detected by looking for significant changes in all directions. We consider a small window on the image and then scan the whole image, looking for corners. Shifting this small window in any direction would result in a large change in appearance if that particular window happens to be located in a corner.
cv2.goodFeaturesToTrack(imgage, max_corner, quantity_level, min_distance)
Keypoints Detection
The distinguishing qualities of an image that make it stand out are referred to as key points in an image. The key points of a particular image let us recognize objects and compare images. This can be done by using the cv2.drawKeypoints() method.
cv2.drawKeypoints(input_image, key_points, output_image, colour, flag)
Other Detection Techniques
OpenCV module provides functions and classes for the detection of various objects. We can detect a circle or ellipses in an image using the SimpleBlobDetector() function, which is basically used to detect any shape in which the pixels are connected.
Another detection technique used is template matching. It is an image processing technique that is used to find the location of small parts/templates of a large image. This technique is widely used for object detection projects, like product quality, vehicle tracking, robotics, etc. This technique can also be used in matching for detecting document fields in a document image.
We can also use OpenCV to detect emotions. Emotion detectors are used in many industries, one being the media industry where it is important for the companies to determine the public reaction to their products. Smile detectors can also work with a live feed from webcams.
Other than that, OpenCV's Sobel edge detection method can also be used to detect the edges of an image in a live stream video. Edge detection involves mathematical methods to find points in an image where the brightness of pixel intensities changes distinctly, which requires finding the gradient of the grayscale image. It also makes use of the Laplacian() function.
Image Pyramids
Image Pyramids are used to change the resolution of the images.
Lower Gaussian Pyramid
The pyrDown() function decreases the size of an image to half of the original image.
cv2.pyrDown(layer)
Higher Gaussian Pyramid
The pyrUp() function increases the size of an image to double its original size.
cv2.pyrUp(layer)
Changing the Colorspace of Images
We can change the colorspace of images using OpenCV. Let’s discuss different ways to visualize images where we will represent images in different formats like grayscale, RGB scale, Hot_map, edge map, Spectral map, etc.
cv2.cvtColor(image, conversion_scale) | Some of the commonly used ways in which color coding of the images are changed is as shown below:
- cv2.COLOR_BGR2GRAY
- cv2.COLOR_BGR2HSV
- cv2.COLOR_BGR2LAB
- cv2.COLOR_BGR2YCrCb
|
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
cv2.inRange(hsv, lower_blue, upper_blue)
| OpenCV provides functions for the
detection of a specific color
in live-stream video content. A video is composed of infinite frames at different time instants.
|
green = np.uint8([[[0, 255, 0]]]) hsv_green = cv2.cvtColor(green, cv2.COLOR_BGR2HSV) | OpenCV lets you find out the HSV color code from the RGB color code. |
Convert to Gray
Grayscale image contains only a single channel.
cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Convert to HSV
Hue(H) represents the dominant wavelength. Saturation(S) represents shades of color. Value(V) represents Intensity.
cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
Convert to LAB color
L represents Lightness. A represents color components ranging from Green to Magenta. B represents color components ranging from Blue to Yellow.
cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
Convert to YCrCb Color
Y represents Luminance or Luma component, and Cb and Cr are Chroma components. Cb represents the blue difference (difference between the blue component and Luma Component). Cr represents the red difference (difference between the red component and Luma Component).
cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
Track Blue (color) Object
OpenCV provides functions for the detection of a specific color in live-stream video content. A video is composed of infinite frames at different time instants.
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
cv2.inRange(hsv, lower_blue, upper_blue)
Find HSV Color
OpenCV lets you find out the HSV color code from the RGB color code.
green = np.uint8([[[0, 255, 0]]])
hsv_green = cv2.cvtColor(green, cv2.COLOR_BGR2HSV)
Smoothing Images
When we are dealing with images at some points the images will be crisper and sharper which we need to smoothen or blur to get a clean image, or sometimes the image will be with a really bad edge which also we need to smooth down to make the image usable. In OpenCV, we got more than one method to smooth or blur an image.
cv2.filter2D(image, ddepth, kernel) | Using the cv2.filter2D() method we can smoothen an image with a custom-made kernel with an image to achieve different image filters like sharpening and blurring and more. |
cv2.blur(image, shapeOfTheKernel) | The cv2.blur() method is used to blur an image using the normalized box filter. The function smooths an image using the kernel. |
cv2.getGaussianKernel(ksize, sigma[, ktype]) | The cv2.getGaussianKernel() method is used to find the Gaussian filter coefficients. The Gaussian kernel is also used in Gaussian Blurring. The 'ktype' is the type of filter coefficient. It can be CV_32F or CV_64F. |
cv2.GaussianBlur(image, shapeOfTheKernel, sigmaX ) | In a Gaussian blur we are going to use a weighted mean. In this type of kernel, the values near the center pixel will have a higher weight. The sigmaX is the Gaussian kernel standard deviation which is by default set to 0. |
cv2.medianBlur(image, kernel size) | In the cv2.medianBlur() method of smoothing, we will simply take the median of all the pixels inside the kernel window and replace the center value with this value. |
cv2.bilateralFilter(image, diameter, sigmaColor, sigmaSpace) | The Bilateral Blur method concerns more about the edges and smoothens the image by preserving the images. This is achieved by performing two Gaussian distributions. The SigmaColor is the number of colors to be considered in the given range of pixels and should not be very high. |
Convolve an Image
Using the cv2.filter2D() method we can smoothen an image with a custom-made kernel with an image to achieve different image filters like sharpening and blurring and more.
cv2.filter2D(image, ddepth, kernel)
Averaging Filtering
The cv2.blur() method is used to blur an image using the normalized box filter. The function smooths an image using the kernel
cv2.blur(image, shapeOfTheKernel)
Create Gaussian Kernel
The cv2.getGaussianKernel() method is used to find the Gaussian filter coefficients. The Gaussian kernel is also used in Gaussian Blurring. The 'ktype' is the type of filter coefficient. It can be CV_32F or CV_64F.
cv2.getGaussianKernel(ksize, sigma[, ktype])
Gaussian Blur
In a Gaussian blur, we are going to use a weighted mean. In this type of kernel, the values near the center pixel will have a higher weight. The sigmaX is the Gaussian kernel standard deviation which is by default set to 0.
cv2.GaussianBlur(image, shapeOfTheKernel, sigmaX )
Median Blur
In the cv2.medianBlur() method of smoothing, we will simply take the median of all the pixels inside the kernel window and replace the center value with this value.
cv2.medianBlur(image, kernel size)
Bilateral Blur
The Bilateral Blur method concerns more about the edges and smoothens the image by preserving the images. This is achieved by performing two Gaussian distributions. The SigmaColor is the number of colors to be considered in the given range of pixels and should not be very high. SigmaSpace is the space between the biased pixel and the neighbor pixel.
cv2.bilateralFilter(image, diameter, sigmaColor, sigmaSpace)
Working With Videos
OpenCV library can be used to perform multiple operations on videos. We can perform operations like creating a video using multiple images, extracting images, and frames, drawing shapes, putting text, etc on a video. Let us see a few of these operations.
cv2.VideoCapture(“file_name.mp4”) | To
capture a video
using OpenCV, we need to create a VideoCapture object. VideoCapture has the device index or the name of a video file. The device index is just the number to specify which camera. If we pass 0 then it is for the first camera, 1 for the second camera so on.
|
cv2.VideoCapture(File_path)
cv2.read()
cv2.imwrite(filename, img[, params])
| Using OpenCV, techniques such as image scanning, and face recognition can be accomplished quite easily. We can
extract images from videos as well using the OpenCV module along with the os module.
|
Playing a Video
To capture a video using OpenCV, we need to create a VideoCapture object. VideoCapture has the device index or the name of a video file. The device index is just the number to specify which camera. If we pass 0 then it is for the first camera, 1 for the second camera so on. We capture the video frame by frame.
cv2.VideoCapture(“file_name.mp4”)
Create a Video from Multiple Images
We can create videos from multiple images using OpenCV. It also requires the PIL library which is used to open and resize images to their mean_height and mean_width because the video which will be created using the cv2 library required the input images of the same height and width.
PIL.Image.open(filename, mode)
Extracting Images from Video
Using OpenCV, techniques such as image scanning, and face recognition can be accomplished quite easily. We can extract images from videos as well using the OpenCV module along with the os module.
cv2.VideoCapture(File_path)
cv2.read()
cv2.imwrite(filename, img[, params])
Camera Calibration and 3D Reconstruction
A Camera Calibration is estimating the parameters of a camera, parameters about the camera are required to determine an accurate relationship between a 3D point in the real world and its corresponding 2D projection (pixel) in the image captured by that calibrated camera. We need to consider both internal parameters like focal length, optical center, and radial distortion coefficients of the lens, etc., and external parameters like rotation and translation of the camera with respect to some real-world coordinate system.
Pose estimation is a computer vision technique that is used to predict the configuration of the body(POSE) from an image. It is used in various applications such as robotics, human-computer interactions, etc.
Often in multiple-view geometry, there are interesting relationships between the multiple cameras, a 3D point, and that point’s projections in each of the camera’s image planes. The geometry that relates the cameras, points in 3D, and the corresponding observations are referred to as the Epipolar geometry of a stereo pair.
A depth map is a picture where every pixel has depth information(rather than RGB) and it is normally represented as a grayscale picture. Depth information means the distance of the surface of scene objects from a viewpoint. The Stereo Images are two images with a slight offset.
Conclusion
In Conclusion, the Python OpenCV Cheat Sheet is like a helpful guide for understanding computer vision and working with images. It's like having a map to explore this new world! Whether you're just starting out or already know a lot, the cheat sheet gives you a quick and organized collection of important stuff. You'll learn from basic image stuff to more advanced things like finding objects in pictures or recognizing faces. This makes learning OpenCV easy and fun. So, as you start using Python and OpenCV for your image work, remember this cheat sheet is your buddy.
Similar Reads
Python Tutorial - Learn Python Programming Language Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. It'sA high-level language, used in web development, data science, automation, AI and more.Known fo
9 min read
Python Fundamentals
Python IntroductionPython was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read
Input and Output in PythonUnderstanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython's input() function
7 min read
Python VariablesIn Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read
Python OperatorsIn Python programming, Operators in general are used to perform operations on values and variables. These are standard symbols used for logical and arithmetic operations. In this article, we will look into different types of Python operators. OPERATORS: These are the special symbols. Eg- + , * , /,
6 min read
Python KeywordsKeywords in Python are reserved words that have special meanings and serve specific purposes in the language syntax. Python keywords cannot be used as the names of variables, functions, and classes or any other identifier. Getting List of all Python keywordsWe can also get all the keyword names usin
2 min read
Python Data TypesPython Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
9 min read
Conditional Statements in PythonConditional statements in Python are used to execute certain blocks of code based on specific conditions. These statements help control the flow of a program, making it behave differently in different situations.If Conditional Statement in PythonIf statement is the simplest form of a conditional sta
6 min read
Loops in Python - For, While and Nested LoopsLoops in Python are used to repeat actions efficiently. The main types are For loops (counting through items) and While loops (based on conditions). In this article, we will look at Python loops and understand their working with the help of examples. For Loop in PythonFor loops is used to iterate ov
9 min read
Python FunctionsPython Functions is a block of statements that does a specific task. The idea is to put some commonly or repeatedly done task together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it over an
9 min read
Recursion in PythonRecursion involves a function calling itself directly or indirectly to solve a problem by breaking it down into simpler and more manageable parts. In Python, recursion is widely used for tasks that can be divided into identical subtasks.In Python, a recursive function is defined like any other funct
6 min read
Python Lambda FunctionsPython Lambda Functions are anonymous functions means that the function is without a name. As we already know the def keyword is used to define a normal function in Python. Similarly, the lambda keyword is used to define an anonymous function in Python. In the example, we defined a lambda function(u
6 min read
Python Data Structures
Python StringA string is a sequence of characters. Python treats anything inside quotes as a string. This includes letters, numbers, and symbols. Python has no character data type so single character is a string of length 1.Pythons = "GfG" print(s[1]) # access 2nd char s1 = s + s[0] # update print(s1) # printOut
6 min read
Python ListsIn Python, a list is a built-in dynamic sized array (automatically grows and shrinks). We can store all types of items (including another list) in a list. A list may contain mixed type of items, this is possible because a list mainly stores references at contiguous locations and actual items maybe s
6 min read
Python TuplesA tuple in Python is an immutable ordered collection of elements. Tuples are similar to lists, but unlike lists, they cannot be changed after their creation (i.e., they are immutable). Tuples can hold elements of different data types. The main characteristics of tuples are being ordered , heterogene
6 min read
Dictionaries in PythonPython dictionary is a data structure that stores the value in key: value pairs. Values in a dictionary can be of any data type and can be duplicated, whereas keys can't be repeated and must be immutable. Example: Here, The data is stored in key:value pairs in dictionaries, which makes it easier to
7 min read
Python SetsPython set is an unordered collection of multiple items having different datatypes. In Python, sets are mutable, unindexed and do not contain duplicates. The order of elements in a set is not preserved and can change.Creating a Set in PythonIn Python, the most basic and efficient method for creating
10 min read
Python ArraysLists in Python are the most flexible and commonly used data structure for sequential storage. They are similar to arrays in other languages but with several key differences:Dynamic Typing: Python lists can hold elements of different types in the same list. We can have an integer, a string and even
9 min read
List Comprehension in PythonList comprehension is a way to create lists using a concise syntax. It allows us to generate a new list by applying an expression to each item in an existing iterable (such as a list or range). This helps us to write cleaner, more readable code compared to traditional looping techniques.For example,
4 min read
Advanced Python
Python OOPs ConceptsObject Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. OOPs is a way of organizing code that uses objects and classes to represent real-world entities and their behavior. In OOPs, object has attributes thing th
11 min read
Python Exception HandlingPython Exception Handling handles errors that occur during the execution of a program. Exception handling allows to respond to the error, instead of crashing the running program. It enables you to catch and manage errors, making your code more robust and user-friendly. Let's look at an example:Handl
6 min read
File Handling in PythonFile handling refers to the process of performing operations on a file, such as creating, opening, reading, writing and closing it through a programming interface. It involves managing the data flow between the program and the file system on the storage device, ensuring that data is handled safely a
4 min read
Python Database TutorialPython being a high-level language provides support for various databases. We can connect and run queries for a particular database using Python and without writing raw queries in the terminal or shell of that particular database, we just need to have that database installed in our system.A database
4 min read
Python MongoDB TutorialMongoDB is a popular NoSQL database designed to store and manage data flexibly and at scale. Unlike traditional relational databases that use tables and rows, MongoDB stores data as JSON-like documents using a format called BSON (Binary JSON). This document-oriented model makes it easy to handle com
2 min read
Python MySQLMySQL is a widely used open-source relational database for managing structured data. Integrating it with Python enables efficient data storage, retrieval and manipulation within applications. To work with MySQL in Python, we use MySQL Connector, a driver that enables seamless integration between the
9 min read
Python PackagesPython packages are a way to organize and structure code by grouping related modules into directories. A package is essentially a folder that contains an __init__.py file and one or more Python files (modules). This organization helps manage and reuse code effectively, especially in larger projects.
12 min read
Python ModulesPython Module is a file that contains built-in functions, classes,its and variables. There are many Python modules, each with its specific work.In this article, we will cover all about Python modules, such as How to create our own simple module, Import Python modules, From statements in Python, we c
7 min read
Python DSA LibrariesData Structures and Algorithms (DSA) serve as the backbone for efficient problem-solving and software development. Python, known for its simplicity and versatility, offers a plethora of libraries and packages that facilitate the implementation of various DSA concepts. In this article, we'll delve in
15 min read
List of Python GUI Library and PackagesGraphical User Interfaces (GUIs) play a pivotal role in enhancing user interaction and experience. Python, known for its simplicity and versatility, has evolved into a prominent choice for building GUI applications. With the advent of Python 3, developers have been equipped with lots of tools and li
11 min read
Data Science with Python
NumPy Tutorial - Python LibraryNumPy (short for Numerical Python ) is one of the most fundamental libraries in Python for scientific computing. It provides support for large, multi-dimensional arrays and matrices along with a collection of mathematical functions to operate on arrays.At its core it introduces the ndarray (n-dimens
3 min read
Pandas TutorialPandas is an open-source software library designed for data manipulation and analysis. It provides data structures like series and DataFrames to easily clean, transform and analyze large datasets and integrates with other Python libraries, such as NumPy and Matplotlib. It offers functions for data t
6 min read
Matplotlib TutorialMatplotlib is an open-source visualization library for the Python programming language, widely used for creating static, animated and interactive plots. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, Qt, GTK and wxPython. It
5 min read
Python Seaborn TutorialSeaborn is a library mostly used for statistical plotting in Python. It is built on top of Matplotlib and provides beautiful default styles and color palettes to make statistical plots more attractive.In this tutorial, we will learn about Python Seaborn from basics to advance using a huge dataset of
15+ min read
StatsModel Library- TutorialStatsmodels is a useful Python library for doing statistics and hypothesis testing. It provides tools for fitting various statistical models, performing tests and analyzing data. It is especially used for tasks in data science ,economics and other fields where understanding data is important. It is
4 min read
Learning Model Building in Scikit-learnBuilding machine learning models from scratch can be complex and time-consuming. Scikit-learn which is an open-source Python library which helps in making machine learning more accessible. It provides a straightforward, consistent interface for a variety of tasks like classification, regression, clu
8 min read
TensorFlow TutorialTensorFlow is an open-source machine-learning framework developed by Google. It is written in Python, making it accessible and easy to understand. It is designed to build and train machine learning (ML) and deep learning models. It is highly scalable for both research and production.It supports CPUs
2 min read
PyTorch TutorialPyTorch is an open-source deep learning framework designed to simplify the process of building neural networks and machine learning models. With its dynamic computation graph, PyTorch allows developers to modify the networkâs behavior in real-time, making it an excellent choice for both beginners an
7 min read
Web Development with Python
Flask TutorialFlask is a lightweight and powerful web framework for Python. Itâs often called a "micro-framework" because it provides the essentials for web development without unnecessary complexity. Unlike Django, which comes with built-in features like authentication and an admin panel, Flask keeps things mini
8 min read
Django Tutorial | Learn Django FrameworkDjango is a Python framework that simplifies web development by handling complex tasks for you. It follows the "Don't Repeat Yourself" (DRY) principle, promoting reusable components and making development faster. With built-in features like user authentication, database connections, and CRUD operati
10 min read
Django ORM - Inserting, Updating & Deleting DataDjango's Object-Relational Mapping (ORM) is one of the key features that simplifies interaction with the database. It allows developers to define their database schema in Python classes and manage data without writing raw SQL queries. The Django ORM bridges the gap between Python objects and databas
4 min read
Templating With Jinja2 in FlaskFlask is a lightweight WSGI framework that is built on Python programming. WSGI simply means Web Server Gateway Interface. Flask is widely used as a backend to develop a fully-fledged Website. And to make a sure website, templating is very important. Flask is supported by inbuilt template support na
6 min read
Django TemplatesTemplates are the third and most important part of Django's MVT Structure. A Django template is basically an HTML file that can also include CSS and JavaScript. The Django framework uses these templates to dynamically generate web pages that users interact with. Since Django primarily handles the ba
7 min read
Python | Build a REST API using FlaskPrerequisite: Introduction to Rest API REST stands for REpresentational State Transfer and is an architectural style used in modern web development. It defines a set or rules/constraints for a web application to send and receive data. In this article, we will build a REST API in Python using the Fla
3 min read
How to Create a basic API using Django Rest Framework ?Django REST Framework (DRF) is a powerful extension of Django that helps you build APIs quickly and easily. It simplifies exposing your Django models as RESTfulAPIs, which can be consumed by frontend apps, mobile clients or other services.Before creating an API, there are three main steps to underst
4 min read
Python Practice
Python QuizThese Python quiz questions are designed to help you become more familiar with Python and test your knowledge across various topics. From Python basics to advanced concepts, these topic-specific quizzes offer a comprehensive way to practice and assess your understanding of Python concepts. These Pyt
3 min read
Python Coding Practice ProblemsThis collection of Python coding practice problems is designed to help you improve your overall programming skills in Python.The links below lead to different topic pages, each containing coding problems, and this page also includes links to quizzes. You need to log in first to write your code. Your
1 min read
Python Interview Questions and AnswersPython is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read