OpenCV प्लेटफॉर्म अजगर के लिए cv2 लाइब्रेरी प्रदान करता है। इसका उपयोग विभिन्न आकार विश्लेषण के लिए किया जा सकता है जो कंप्यूटर दृष्टि में उपयोगी है। इस लेख में हम ओपन सीवी का उपयोग करके एक सर्कल के आकार की पहचान करेंगे। उसके लिए हम cv2.HoughCircles () फ़ंक्शन का उपयोग करेंगे। हफ़ ट्रांसफ़ॉर्म का उपयोग करके ग्रेस्केल छवि में मंडलियों को ढूँढता है। नीचे के उदाहरण में हम इनपुट के रूप में एक इमेज लेंगे। फिर इसकी एक कॉपी बनाएं और आउटपुट में सर्कल की पहचान करने के लिए इस ट्रांसफॉर्म फ़ंक्शन को लागू करें।
सिंटैक्स
cv2.HoughCircles(image, method, dp, minDist) Where Image is the image file converted to grey scale Method is the algorithm used to detct the circles. Dp is the inverse ratio of the accumulator resolution to the image resolution. minDist is the Minimum distance between the center coordinates of detected circles.
उदाहरण
नीचे दिए गए उदाहरण में हम नीचे दी गई छवि को अपनी इनपुट छवि के रूप में उपयोग करते हैं। फिर मंडलियां प्राप्त करने के लिए नीचे दिया गया प्रोग्राम चलाएं।

नीचे दिया गया प्रोग्राम एक छवि फ़ाइल में सर्कल की उपस्थिति का पता लगाता है। यदि वृत्त मौजूद है तो वह इसे हाइलाइट करता है।
उदाहरण
import cv2
import numpy as np
image = cv2.imread('circle_ellipse_2.JPG')
output = image.copy()
img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Find circles
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1.3, 100)
# If some circle is found
if circles is not None:
# Get the (x, y, r) as integers
circles = np.round(circles[0, :]).astype("int")
print(circles)
# loop over the circles
for (x, y, r) in circles:
cv2.circle(output, (x, y), r, (0, 255, 0), 2)
# show the output image
cv2.imshow("circle",output)
cv2.waitKey(0) उपरोक्त कोड को चलाने से हमें निम्नलिखित परिणाम मिलते हैं -
आउटपुट
[[93 98 84]]
और हमें आउटपुट दिखाते हुए नीचे दिया गया चित्र मिलता है।
