You are reading the article How Does Opencv Findcontour() Work updated in September 2023 on the website Speedmintonvn.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How Does Opencv Findcontour() WorkIntroduction to OpenCV findContours
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
It works essentially well on binary pictures and images, thought at the first application of Sobel edges and thresholding techniques should be implemented. Each of the individual contour is representative of an individual numpy array with coordinates x and y, which represents the boundary point for the object that the user has entered.
Syntax of OpenCV findContour()
Following is the syntax used for application of the OpenCV findContour method:void cv :: findContours (InputOutputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset = Point() ) Parameters of OpenCV findContour():
Following are the parameters used for the Open CV findContour() method:
Image It is the source image that is used which is generated through a single channel of about eight bits. Any pixels that are in the non-zero category designated as 1’s, the pixels with zero categories are designated as 0’s, perforce converting the image into a binary form. Various parameters (such as adaptiveThreshold, inRange, Canny, threshold, etc.) can then be further applied in order to create the binary images using the coloured or grayscale image that is the user. In case the mode is equal to RETR_FLOODFILL or RETR_CCOMP, then the image which is being entered by the user as the source image be a 3- bit integer-based image of label CV_32SC1.
Contours Detection of contour – each of the single contour has been stored in the form of multiple points that are vectors.
Mode Mode activated specifically to contour retrieval.
Method Mode activated specifically to depict the approximation method for the image contour.
Offset It is an optional parameter by using which every contour point can be shifted. It is essentially useful when the contour has been extracted are image ROI, and then further analysis should be done in the context of the whole image.How does OpenCV findContour() Work?
When the computer is made to detect the edges of an input image, it then finds the points where specifically, there is a significant difference notice in the intensity of colouration, then simply those pixels are turned on. A stark differences noticed when the system is instructed to perform contouring.
Contours are basically an abstract collection of segments and points that correspond to the reflective shapes of the objects that are present in the images that have been processed through the system. as a result of this; it is in our capacity to manipulate the contouring within the programs through which they are being accessed.
This can be done in multiple ways, such as having a count on the number of contours in an image and then using that to categorize the object shapes, for segmentation of images or cropping objects from the image that is being processed and many more such similar functions.Example
Given below is the example of OpenCV findContour:
Code:import numpy as np1 import cv2 img_1 = cv2.imread('EduCBA.png') print (“The Gray scale image is ” /n) imgray_1 = cv2.cvtColor(img_1, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(imgray_1, 127, 255, 0) contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) print("The Total Number of Contours in the Image = ") print (str(len(contours))) print(contours) cv2.drawContours(img_1, contours, -1,(0,2550,0),3) cv2.drawContours(imgray_1, contours, -1,(0,255,0),3) print (“The original image is: “ /n) cv2.imshow('Image', img_1) cv2.imshow('Image GRAY', imgray_1) cv2.waitKey(0) cv2.destroyAllWindows()
The output screen displays the screenshot on the compiling of the above code.Conclusion – OpenCV findContours
The OpenCV find contour method is essentially useful as it provides for a pre-defined function that can be called without implementation of an entire code and can be modified using the various parameters. It is essentially helpful in terms of analysing the shape of the image provided, in the detection of the size and dimension of the object that has to be detected in the provided image and in the detection of specific objects. This is done in order to categorize the object shapes, for segmentation of images or cropping objects from the image that is being processed and many more such similar functions.Recommended Articles
We hope that this EDUCBA information on “OpenCV findContours” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
You're reading How Does Opencv Findcontour() Work
Update the detailed information about How Does Opencv Findcontour() Work on the Speedmintonvn.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!