Using minEnclosingCircle(...) in pyopencv - what does it want?

202 views
Skip to first unread message

Drmn4ea

unread,
Sep 20, 2010, 2:27:26 AM9/20/10
to ctypes-opencv
Hi,
I am working on the beginnings of an open-source pick and place
system, but new to OpenCV and pyOpenCv in particular. Right now I'm
trying to find the bounding circle enclosing each object on a table by
using minEnclosingCircle(...) on the external contours returned from
findContours(img, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0,0))

Does anyone know what the pyOpenCV implementation of
minEnclosingCircle expects as input? I can't seem to find a
combination of logical input arguments that do not return, e.g:

Traceback (most recent call last):
File "C:\data\projects\pickplace\sticker\segmentation\contours.py",
line 147, in <module>
minEnclosingCircle(contour_mat, center, radius)
ArgumentError: Python argument types in
pyopencv.pyopencvext.minEnclosingCircle(Mat, Point2f, float)
did not match C++ signature:
minEnclosingCircle(cv::Mat points, cv::Point_<float> {lvalue}
center, float {lvalue} radius)



The autogenerated API document has this to say:

minEnclosingCircle( (Mat)points, (Point2f)center, (object)radius) ->
None :

C++ signature :
void minEnclosingCircle(cv::Mat,cv::Point_<float>
{lvalue},float {lvalue})


and in opencv, it returns the result in the passed-by-reference
Point2f and float passed in. The 2nd argument is pretty obvious (I
think). But passing a float for radius and expecting a return value
seems suspect for Python - aren't the basic numeric types immutable?
Also, what is the shape/dimensionality/type(s) of the Mat expected for
the first argument?

Any help would be appreciated.
Thanks!

Minh-Tri Pham

unread,
Sep 20, 2010, 4:33:12 AM9/20/10
to ctypes...@googlegroups.com
Hi,

I've double-checked the wrapping code and it was indeed a bug. The radius and
the center point should be output arguments rather than input arguments. I
will fix it soon. Thanks for raising the issue.

Cheers,
Minh-Tri

--
Minh-Tri Pham Tel +44 1223 436 952
Toshiba Research Europe Fax +44 1223 436 909
208 Cambridge Science Park
Cambridge CB4 0GZ, UK

NOTE: The information in this email and any attachments may be confidential
and/or legally privileged. This message may be read, copied and used only by
the intended recipient. If you are not the intended recipient, please destroy
this message, delete any copies held on your system and notify the sender
immediately.

Toshiba Research Europe Limited, registered in England and Wales (2519556).
Registered Office: 208 Cambridge Science Park, Milton Road, Cambridge
CB4 0GZ, England. Web: http://www.toshiba-europe.com/research/crl

Drmn4ea

unread,
Sep 21, 2010, 11:11:25 PM9/21/10
to ctypes-opencv
Minh-Tri,
Thanks!!

It looks like openCV passes return values this way fairly frequently.

gblaha

unread,
Nov 4, 2010, 5:46:44 PM11/4/10
to ctypes-opencv
I just posted a new (related) topic then came across this one. I've
having what seems like a similar problem with the cornerSubPix
function, which also accepts an argument with the offending {lvalue}
signature.

Minh-Tri Pham

unread,
Nov 7, 2010, 3:18:27 AM11/7/10
to ctypes...@googlegroups.com
I've just checked the cornerSubPix function. Although it accepts an lvalue
argument, the argument is passed by reference. Therefore the method works
just fine in this case.

By the way, the issue with the minEnclosingCircle function has been fixed in
one of recent revisions.

Cheers,
Minh-Tri

Reply all
Reply to author
Forward
0 new messages