ret和corner总是False&None

问题描述 投票:-1回答:1

ret和corner总是False&None。我写了img.py

import numpy as np
import cv2
import glob
from PIL import Image

# 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)

# 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 = Image.open('cosme.jpg')
gray = cv2.cvtColor(np.array(images),cv2.COLOR_BGR2GRAY)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, (7,6),None)
print(ret)
print(corners)

# 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
   img = cv2.drawChessboardCorners(img, (7,6), corners2,ret)
   cv2.imshow('img',img)
   cv2.waitKey(0)
   cv2.destroyAllWindows()

始终ret为False,因此不显示图像.print(ret)显示False,print(角)显示None,因此始终程序不会进入if语句。我真的不明白为什么ret总是假的,因为灰色有正常的值。我认为(7,6)导致这个错误,但我不知道是什么原因导致这个错误。我的代码出了什么问题?我应该怎么解决这个问题?

python numpy opencv
1个回答
0
投票

如果您张贴图像本身会有所帮助 - 它应该有一个校正棋盘,其内部角落尺寸为7,6可见 - 如果找不到角落,则返回值为False,角落列表将为None

© www.soinside.com 2019 - 2024. All rights reserved.