everyone i'm fairly new to OpenCV and computer vision and i'm stuck at this problem , which might seem like a fairly trivial but forgive my noobness :)
I'm trying to detect Rebars from a cross-sectional image.
i'm using this code :
import cv2
import cv2.cv as cv
import numpy as np
img = cv2.imread('test/t2.jpg',0)
img = cv2.equalizeHist(img)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,10,param1=50,param2=30,minRadius=0,maxRadius=25)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
This is the result i'm getting currently, which is not good :
I'm looking for pointers on how to proceed with this problem and how to learn more about CV as i'm really interested!
Thanks a ton!
HoughCircles() function. Finds circles in a grayscale image using the Hough transform. In the below example we will take an image as input. Then make a copy of it and apply this transform function to identify the circle in the output.
Use the OpenCV function HoughCircles() to detect circles in an image.
We can find shapes present in an image using the findContours() and approxPolyDP() function of OpenCV. We can detect shapes depending on the number of corners it has. For example, a triangle has 3 corners, a square has 4 corners, and a pentagon has 5 corners.
HoughCircles
is not a strong enough way to detect circle in such complex image like your case.
SO has already had some discussion about this. You could refer these post with quality accepted answers
Standard way:
Filled circle detection using CV2 in Python?
What are the possible fast ways to detect circle in an image?
Noise image:
https://dsp.stackexchange.com/questions/5930/find-circle-in-noisy-data
Another method:
Gradient Pair Vectors
Learning Automata
Those results can be slightly improved with setting the parameters better on this line:
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,10,param1=50,param2=30,minRadius=0,maxRadius=25)
For example, you can reduce the maxRadius slightly and increase the sensitivity.
In my experience, however, you won't get a good result on an image like this. It is very complex, the circles are irregular and at different angles. If your goal is to practice, then sure, play with the parameters and try different methods to improve it. I don't see much practical use though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With