saviopalmieri / ctypes-opencv

Automatically exported from code.google.com/p/ctypes-opencv
0 stars 0 forks source link

cvHoughCircles KeyError #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Running this code with img = cvQueryFrame(capture):

def find_circles(img):
    gray = cvCreateImage(cvGetSize(img), 8, 1)
    storage = cvCreateMemStorage(0)
    cvCvtColor(img, gray, CV_BGR2GRAY)
    cvSmooth(gray, gray, CV_GAUSSIAN, 9, 9)
    print cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 2,
int(gray['height'])/4, 200, 100)

Throws this error:

Traceback (most recent call last):
  File "/home/liveuser/Desktop/bot/CVtypes/vision.py", line 70, in <module>
    find_circles(src)
  File "/home/liveuser/Desktop/bot/CVtypes/vision.py", line 45, in find_circles
    print cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 2,
int(gray['height'])/4, 200, 100)
  File "/usr/lib/python2.5/opencv/cxcore.py", line 493, in __getitem__
    pixel = self.get_pixel(key)
  File "/usr/lib/python2.5/opencv/cxcore.py", line 474, in get_pixel
    raise KeyError("Key (%s) is not a tuple of 2 integers." % str(key))
KeyError: 'Key (height) is not a tuple of 2 integers.'

Running Fedora 10 off a USB drive, Logitech webcam, Python 2.5 installation

Original issue reported on code.google.com by ian.wetherbee on 7 May 2009 at 5:22

GoogleCodeExporter commented 8 years ago
I think the problem is at your gray['height']. gray is a class, not a 
dictionary, a
tuple, nor a list. Can you try gray.height instead?

Original comment by pmtri80@gmail.com on 8 May 2009 at 12:24

GoogleCodeExporter commented 8 years ago
I mean replacing int(gray['height']) with gray.height

Original comment by pmtri80@gmail.com on 8 May 2009 at 12:25

GoogleCodeExporter commented 8 years ago
Sorry, I double-posted this issue and solved it in the other double post. The 
image
class's __dict__ feature is extended to allow for selection of pixels, so it was
looking for a tuple of two ints, not 'height'. I had to get the height attribute
through: gray.__dict__['height'], so it works now.

Original comment by ian.wetherbee on 8 May 2009 at 6:13

GoogleCodeExporter commented 8 years ago
Okay. Glad you have resolved the problem.

Original comment by pmtri80@gmail.com on 9 May 2009 at 1:30