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. We use cv2.adaptiveThreshold for this.
Example: Python OpenCV Adaptive Thresholding
Python3
# Python program to illustrate # adaptive thresholding type on an image # organizing imports import cv2 import numpy as np # path to input image is specified and # image is loaded with imread command image1 = cv2.imread( 'geeks.png' ) # cv2.cvtColor is applied over the # image input with applied parameters # to convert the image in grayscale img = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY) # applying different thresholding # techniques on the input image thresh1 = cv2.adaptiveThreshold(img, 255 , cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 199 , 5 ) thresh2 = cv2.adaptiveThreshold(img, 255 , cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 199 , 5 ) # the window showing output images # with the corresponding thresholding # techniques applied to the input image cv2.imshow( 'Adaptive Mean' , thresh1) cv2.imshow( 'Adaptive Gaussian' , thresh2) # De-allocate any associated memory usage if cv2.waitKey( 0 ) & 0xff = = 27 : cv2.destroyAllWindows() |
Output:
Getting Started with Python OpenCV
Computer Vision is one of the techniques from which we can understand images and videos and can extract information from them. It is a subset of artificial intelligence that collects information from digital images or videos.
Python OpenCV is the most popular computer vision library. By using it, one can process images and videos to identify objects, faces, or even handwriting of a human. When it is integrated with various libraries, such as NumPy, python is capable of processing the OpenCV array structure for analysis.
In this article, we will discuss Python OpenCV in detail along with some common operations like resizing, cropping, reading, saving images, etc with the help of good examples.