本文介绍了Python OpenCV检测棋盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚棋盘图案的角落,并认为我可以将openCV与 cv2.findChessboardCorners 一起使用。

I'm trying to get the corners of a chessboard pattern, and thought I could use openCV with cv2.findChessboardCorners.

但是,我找不到传递给该函数的好参数,以使其成功检测到棋盘。我认为该图像适合该功能。如果不是这样,我就搞不清楚应该做什么预处理。.

However, I can't find the good arguments to pass to the function such that it succeeds in detecting the chessboard. I thought the image would be appropriated for this function. If it is not, I can't figure out what king of preprocessing I should do ..

这是我的代码:

import numpy as np
import cv2
import glob
import sys
import os

nline = 4
ncol = 4

img = cv2.imread(glob.glob('*.jpg')[0])

## termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

## processing
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Find the chessboard corners
ret, corners = cv2.findChessboardCorners(gray, (nline, ncol), None)
corners2 = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)

这是图片:

我尝试了各种图案大小来给他,因为我认为4 * 4 p

I have tried various pattern size to give him, because I thought that a 4*4 pattern would be easier to find but it wan not.

编辑:实际上使用适当数量的行和列,其工作原理是:

EDIT : Actually using the appropriated number of lines and columns its works :

但是,对于与第一个没有太大区别的那些对象并没有... ... 11行(用于8列或9列),都尝试过。

However, it doesn't for these ones which are not so different from the first one ... 11 lines, for 8 or 9 columns, tried both.

或者这是,它是13 * 9。

Or this one : which is 13*9.

如何处理此类图像?

推荐答案

参数 nline ncol 必须准确,(行数-1,列数-1)

Parameters nline and ncol must be exact, (number of rows -1, number colums -1)

nline = 11
ncol = 9

这篇关于Python OpenCV检测棋盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:21