Differences between revisions 2 and 3
Revision 2 as of 2011-03-19 10:57:06
Size: 2785
Editor: acpcalin
Comment:
Revision 3 as of 2011-03-19 14:51:46
Size: 2870
Editor: PaulBoddie
Comment: Keeping requests under the "Asking for Help" namespace.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from How do I detect the circles/round shapes in a color image?

Hello everybody!

I just installed the python-opencv package on Ubuntu 10.10 and I was wondering how I can use it to detect the circles/round figures in an RGB image. I am not an expert in images and I do not know what terms like HSV and 8-bit image mean(I know these two now, of course).

I tried this code, which I adapted from a website, and it doesn't work:

   1 import cv
   2         
   3 def main():
   4         
   5         storage = cv.CreateMemStorage(0)
   6         
   7         im = cv.LoadImageM("Proba1.jpg")
   8         size = (640, 480)
   9         hsv_im = cv.CreateImage(size, cv.IPL_DEPTH_8U, 3)
  10         thresholded = cv.CreateImage(size, cv.IPL_DEPTH_8U, 1)
  11         thresholded2 = cv.CreateImage(size, cv.IPL_DEPTH_8U, 1)
  12          
  13         hsv_min = cv.Scalar(0, 50, 170, 0)
  14         hsv_max = cv.Scalar(10, 180, 256, 0)
  15         hsv_min2 = cv.Scalar(170, 50, 170, 0)
  16         hsv_max2 = cv.Scalar(256, 180, 256, 0)
  17         
  18         cv.CvtColor(im, hsv_im, cv.CV_BGR2HSV)
  19         cv.InRangeS(im, hsv_min, hsv_max, thresholded)
  20         cv.InRangeS(im, hsv_min2, hsv_max2, thresholded2)
  21         cv.cvOr(thresholded, thresholded2, thresholded)
  22         # pre-smoothing improves Hough detector
  23         cv.Smooth(im, im, cv.CV_GAUSSIAN, 9, 9)
  24         
  25         
  26         circles = cv.HoughCircles(im, im, cv.CV_HOUGH_GRADIENT, 2, thresholded.height/4, 100, 40, 20, 200)
  27         
  28         
  29 if __name__ == '__main__':
  30         main()

The error I get is: OpenCV Error: Sizes of input arguments do not match () in cvCvtColor, file /build/buildd/opencv-2.1.0/src/cv/cvcolor.cpp, line 2208OpenCV Error: Sizes of input arguments do not match () in cvCvtColor, file /build/buildd/opencv-2.1.0/src/cv/cvcolor.cpp, line 2208

I really do NOT understand the whole code above(not the error, the code) since there is no good documentation about opencv and python available. I also tried installing pyopencv but it didn't work.

I would be very glad if someone could show me a code sample that takes a .jpg image, makes it 8-bit(because this is another error it gives me) and detects the circles in it. It would also be nice if you could tell me a good opencv tutorial for python.

Thanks for your time and interest and sorry for my grammar.

Calin

Asking for Help: ...

...

When answering questions, add the CategoryAskingForHelpAnswered category when saving the page. This will move the link to this page from the questions section to the answers section on the Asking for Help page.


CategoryAskingForHelp

Asking for Help/How do I detect the circles/round shapes in a color image? (last edited 2011-03-21 03:55:19 by RodDrenth)

Unable to edit the page? See the FrontPage for instructions.