이것은 opencv python 문서의 카메라 보정 코드입니다. objp [:, : 2] = np.mgrid [0 : 7,0 : 6] .T.reshape (-1,2)가 어떻게 작동하는지 알고 싶습니다. 재구성 (-1,2)은 무엇을합니까? 이 코드 줄에서 값을 변경하려고 시도했지만 오류가 발생했습니다. 누군가가 어떻게 작동하는지, 왜이 숫자 만 작동하는지 설명 할 수 있습니까?Opencv python 카메라 보정 : objp 매트릭스
import numpy as np
import cv2
import glob
# 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)
print "objp: ",objp
objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
print "objp: ",objp
# 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('left*.jpg')
for fname in images:
img = cv2.imread(fname)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, (7,6),None)
# If found, add object points, image points (after refining them)
if ret == True:
objpoints.append(objp)
cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
imgpoints.append(corners)
# Draw and display the corners
cv2.drawChessboardCorners(img, (7,6), corners,ret)
cv2.imshow('img',img)
cv2.waitKey(500)
cv2.destroyAllWindows()
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None) # camera matrix, distortion coefficients, rotation and translation vectors
또한, objpoints는 3D 실제 좌표입니다. 이것은 수동으로 올바르게 측정해야합니까? 왜 (0,0,0), (1,0,0), (2,0,0) ...., (6,5,0) ?? 감사합니다. . 어떤 도움을 주시면 감사하겠습니다.
감사합니다. 그게 도움이 됐어! – Clive