Python Forum
how to detect irregular circles in python with opencv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to detect irregular circles in python with opencv
#1
I want to create a vision system for the detection of defect in SMD capacitors, the defect is called "pinhole" and they are small holes in the surface of the chip that are generated at the time of construction. my objective is to create an algorithm that is able of detecting these holes and with this, discard the chips that have this defect

For the moment I have created two codes:

the first one converts the original image to a binary image so that I can clear the circles, the code and the result is as follows. after obtaining the image in a binary way, I don't know how to make my algorithm detect that there is a circle, according to what I have investigated with "HOUGH" it can only be applied to images in grayscale

import cv2
import numpy as np
from matplotlib import pyplot as plt


img = cv2.imread("C:/Users/Johanna Menendez/Documents/UNIR/TFM/chips/20190905_124734.jpg", 0)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
newImg = cv2.resize(img, (0,0), fx=0.50, fy=0.50)
(thresh, blackAndWhiteImage) = cv2.threshold(newImg, 127, 255, cv2.THRESH_BINARY)
numpy_vertical_concat = np.concatenate((newImg, blackAndWhiteImage), axis=1)


cv2.imshow('binary', numpy_vertical_concat)

cv2.waitKey(0)
[python]
binary
https://ibb.co/j8c3GCt

-The second is with contours detection, the problem with this is that it not only detects circles and likewise after this I don't know how to make my algorithm detect that it is a circle

[/
import cv2
import numpy as np
from matplotlib import pyplot as plt


img = cv2.imread("C:/Users/Johanna Menendez/Documents/UNIR/TFM/chips/20190905_124734.jpg", 0)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
newImg = cv2.resize(img, (0,0), fx=0.50, fy=0.50)
gray = cv2.cvtColor(newImg, cv2.COLOR_RGB2GRAY)
(thresh, blackAndWhiteImage) = cv2.threshold(gray, 130, 255, cv2.THRESH_BINARY)
(contours, hierarchy) = cv2.findContours(blackAndWhiteImage, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
img = cv2.drawContours(newImg, contours, -1, (0, 255, 0), 2)
#numpy_vertical_concat = np.concatenate((newImg, img), axis=1)

cv2.imshow('binary', img)

cv2.waitKey(0)
]

[python]
contours detection
https://ibb.co/G0ZmGRk


could help me find out how to know the way for my algorithm to detect the circles please?
Reply
#2
If cv2.HoughCircles only works with grayscale why not convert you image to grayscale?
gray_img = cv2.cvtColor(color_img,cv2.COLOR_GRAY2BGR)
Reply
#3
because just converting it hough does not only recognize the circle that is the defect, it recognizes circles that do not exist, so I try to highlight only the defect by binarizing the image or with contour detection
Reply
#4
Any way you can filter the results to determine which are which? Defects are in the range of … kind of thing? Or are there so many false positives that the results are worthless?
Reply
#5
yes, there so many false positives that the results are worthless,for this reason i no longer use this function, I think it is because the chips are of ceramic and it has a gloss on the surface, but I cannot make it not a false positive even though it qualifies the image and converts it to grayscale
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculation of circles frohr 14 3,366 Jun-28-2022, 07:57 PM
Last Post: frohr
  Can python detect style of language? eg. Flowery words vs simple words mcp111 4 2,414 Jan-07-2020, 02:25 PM
Last Post: mcp111
  Project using Python and Opencv trabis03 7 8,715 Apr-29-2017, 10:09 AM
Last Post: trabis03
  face tracking using optical flow method using python+opencv Aftab 1 7,009 Mar-22-2017, 07:54 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020