6

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.

Original Color 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 : Result

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!

2
  • What is your problem ?
    – Van Tr
    Feb 20, 2016 at 4:36
  • Oh sorry i forgot to mention the main part, i'm not able detect these properly , this is the result i'm getting result Feb 20, 2016 at 4:39

3 Answers 3

11

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

2

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.

1

You can detect features here, using the module trackpy. You need to vary feature sizes with odd numbers and see which one matches best. You may also need to do some pre-processing like, converting image to grayscale.

import trackpy as tp
import numpy as np
import pandas as pd
import pims
import matplotlib.pyplot as plt

#%% importing the data
frames=pims.ImageSequence('F:/TrapHysteresis/processing/Positions/*.TIF')

#%% tracking circles and center positions
featuresize=71
f1=tp.locate(frames[0],featuresize)

plt.figure()
tp.annotate(f1,frames[0])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.