Search code examples
pythonopencvcalibrationsubpixel

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.


Solution

  • 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