0

I am trying to calibrate an SJ4000 camera using OpenCV 2.4.11 in Python 2.7 in Anaconda.

However, I am unable to run the script available here: http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html#setup

I am even testing it with the sample images available in samples/cpp/, images left01.jpg to left14.jpg. It is able to detect the chessboard in the images, but once it hits this line:

cv2.imshow('img',img)

It throws an error:

error: ..\..\..\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow

EDIT 1: After further debugging, I have found that img = cv2.drawChessboardCorners(img, (7,6), corners2,ret) results in a None object.

How do I solve this?

Thanks for any help!

9
  • check img it can be None Commented Dec 5, 2016 at 15:12
  • This is as highly descriptive as all OpenCV errors, but it basically means that it fails the assertion size.width>0 && size.height>0. i.e. your image is probably 0x0 in size, or doesn't exist. Commented Dec 5, 2016 at 15:13
  • @furas - Yes, it turned out to be None but why? Commented Dec 5, 2016 at 15:13
  • What is img before that? In fact, is it not None right after img = cv2.imread(fname)? Commented Dec 5, 2016 at 15:14
  • check img before drawChessboardCorners maybe problem is somewhere before this line. I found that CV doesn't raise error when there is some problem but it returns None - ie. it returns None when it can't get image from camera. Commented Dec 5, 2016 at 15:16

1 Answer 1

2

Hooray! All solved after some further debugging. I suspect this is a version issue.

I changed

corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
imgpoints.append(corners2)
# Draw and display the corners
img1 = cv2.drawChessboardCorners(img, (7,6), corners2,ret)

To

cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
# Draw and display the corners
cv2.drawChessboardCorners(img, (7,6), corners,ret)

And everything works perfectly!

Sign up to request clarification or add additional context in comments.

1 Comment

Realize now the reason it didn't work is drawChessboardCorners() operates on the image directly, and doesn't return anything. Which also means you can still save corners2 if you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.