使用python和opencv进行校准 [英] calibration with python and opencv

查看:139
本文介绍了使用python和opencv进行校准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在棋盘上找到拐角 但是当我运行它时,我什么也没显示 虽然在opencv的页面中他们说应该显示图像,但没有任何迹象表明已经找到了角落.

I am using the following code to find the corners in the chess board but when i run it i got nothing no images are shown and nothing shows that the corners had been found although in the page of opencv they say that an image should appear.

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)
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 = glob.glob('*.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)

    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(500)

cv2.destroyAllWindows()

这是我正在使用的木板图像:

Here's the board image I'm using:

推荐答案

也许是代码行

cv2.waitKey(500)

因此,即使您找到角落,您也不会真正看到任何东西,因为该行仅等待500毫秒,直到窗口被

So even if you find the corners you won't realy see something, because this line only waits for 500 milliseconds until the window gets closed by

cv2.destroyAllWindows()

因此,将500替换为零,直到您将焦点对准键盘上的一个按键,窗口将保持打开状态.

So replace 500 with zero and the window will remain open until you focus on it an klick a key on your keyboard.

这篇关于使用python和opencv进行校准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆