Comments (6)
I had the same problem. I used a different size checkered board image. Mine was size 6,9 and not 7,6.
I got this error when i did not change the dimension in some, but not all the necessary places.
Below is the code that worked for me, with the checkered board image saved as "test.png" in the same folder as the python file. link 🏁 to the image i used
# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
objp = np.zeros((6*9,3), np.float32)
objp[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)
# Arrays to store object points and image points from all the images.
imgpoints = [] # 2d points in image plane.
objpoints = [] # 3d point in real world space
img = cv2.imread("test2.png")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, (6,9),None)
# If found, add object points, image points (after refining them)
if ret == True:
objpoints.append(objp)
corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
imgpoints.append(corners2)
# Draw and display the corners
cv2.drawChessboardCorners(img, (6,9), corners2,ret)
cv2.imshow('img',img)
cv2.waitKey(500)
from opencv2-python-tutorials.
Hi @alexblack
I had the same issue and after a little research I found the problem in stackoverflow
I resolved it changing the shape of objp
:
objp = objp.reshape(-1,1,3)
Also I had another problem: the number of corners found by findChessboardCorners
can be less than 7*6 (pattern size) so I just kept number of corners found 3D points:
corners2 = cv2.cornerSubPix(image=gray, corners=corners, winSize=(11,11), zeroZone=(-1,-1),
criteria=(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001))
imgpoints.append(corners2)
objpoints.append(objp[0:corners2.shape[0]])
after that the code worked fine 😄
from opencv2-python-tutorials.
Hi @mgmacias95
I did not understand what you mean by doing reshape obj.
Do you mean reshap it at the time of initailization?
from opencv2-python-tutorials.
Hi @rabiafyz
Yes, just before the for loop:
# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((6*7,3), np.float32)
objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
objp = objp.reshape(-1,1,3)
# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.
images = glob.glob('*.jpg')
for fname in images:
print 'Filename: ', fname
.
.
.
from opencv2-python-tutorials.
I had a similar problem (error: (-215) ni >= 0 in function collectCalibrationData
). For me it was that my objp
points were float64
instead of float32
, which was not exactly obvious from that message.
from opencv2-python-tutorials.
Hi @mgmacias95 @petered @alexblack ,
I am also having the same problem. I tried the above suggested changes but still of no help and getting the same error. can someone please help me.
Thank you.
from opencv2-python-tutorials.
Related Issues (20)
- tutorials doc code at page 138 not work as img show below.
- Update README.md file
- Hough Transform Example Code Does Not Produce the Plot Shown
- Update the cv2.findCountours return value example in `Contours:Getting Started`.
- Illustration about `minAreaRect()` is wrong. HOT 1
- Contours : Getting Started —— the code is wrong
- Typo in formula "How Otsu’s Binarization Works?"
- Is there any assistance needed ? HOT 1
- trying to crop the original part of the image for the excersice...
- "Mathematical Tools in OpenCV" page is missing.
- Inpainting, for anisotropic pixel
- hi,how to get camera_list ?
- local variable 'tot_error' referenced before assignment
- Hello, please tell me how to get the Mask image
- Turn off automatic publishing for this repository HOT 2
- Description of `minAreaRect` output is wrong
- FYI: This repo is unmaintained! HOT 1
- Proposing a PR to fix a few small typos
- How to remove thick long lines in image?
- Need to extract test strip image mask
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencv2-python-tutorials.