1

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.

kscottz
  • 1,072
  • 2
  • 13
  • 17
  • UPDATE: with later versions of opencv (>=2.7) there is some changes in grammar- this worked for me when I changed the criteria to : criteria = (cv2.TERM_CRITERIA_MAX_ITER | cv2.TERM_CRITERIA_COUNT, 10, 0.01) – Niall O'Dowd Mar 08 '16 at 17:00

2 Answers2

0

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

  • It works! The correct call is: cv.FindCornerSubPix(grayImg,corners[1],(11,11),(-1,-1),(cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS, 10, 0.01)) – kscottz Jun 06 '11 at 21:27
  • 1
    Functions starting with lowercase are from the C++ or cv2 Python library, what is the "this should be used" version of it. cv is there mostly for legacy reasons. – shinjin Nov 25 '12 at 06:54
0

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.

Bryan W
  • 1,112
  • 15
  • 26