开发者

cv.cornerSubPix parameters in the OpenCV Python Library

I am having problems getting the following function to execute using the OpenCV python wrapper:

img = cv.LoadImage("calib0.jpg")
grayImg = cv.CreateImage((img.width,img.height), img.depth,1)
cv.CvtColor(img,grayImg开发者_运维问答,cv.CV_BGR2GRAY)
corners = cv.FindChessboardCorners(grayImg,(5,6), cv.CALIB_CB_ADAPTIVE_THRESH + cv.CALIB_CB_NORMALIZE_IMAGE + cv.CALIB_CB_FAST_CHECK )
cv.cornerSubPix(grayImg,corners,(11,11),(-1,-1),(cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS, 10, 0.01))

If I run this in iPython on (OSX) I get the following error:


TypeError Traceback (most recent call last) /Users/katherinescott/simplecv-git/SimpleCV/sampleimages/ in () ----> 1 cv.cornerSubPix(grayImg,corners,(11,11),(-1,-1),(cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS, 10, 0.01))

TypeError: is not a numpy array

I've tried just about every permutation of casting the above objects to a numpy ndarray but to no avail. My guess is that this error lives in the term criteria object, but I am at a loss as to what it is asking for. Has anyone else encountered this problem when trying to perform calibration using the OpenCV Python wrappers? I am about to start digging into the source to see what I can find.


cornerSubPix, having a lowercase letter first, is a module-internal function for the OpenCV python wrapper.

I believe you want cv.FindCornerSubPix:

http://opencv.willowgarage.com/documentation/python/imgproc_feature_detection.html#findcornersubpix


Old question, but I believe there may be some misunderstanding with the winSize parameter in cv.cornerSubPix().

When using

cv.cornerSubPix(grayImg, corners, winSize, (-1,-1), criteria)

Assuming you want an 11x11 search window, the appropriate input for winSize should be winSize=(5,5) and not winSize=(11,11). If you use (11,11) for winSize as posted in the original question, the resulting search window would actually be 23x23.

According to the documentation:

winSize: Half of the side length of the search window. For example, if winSize=Size(5,5) , then a (5∗2+1)×(5∗2+1)=11×11 search window is used.

As of OpenCV 4.5.2 (April 2021), the example in the documentation under related cv.findChessboardCorners() appears to be incorrect and (5,5) for winSize should be used instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜