Reputation: 1511
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 ..
Here is my code:
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)
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 :
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.
How to deal with this kind of images ?
Upvotes: 4
Views: 14311
Reputation: 670
Parameters nline
and ncol
must be exact, (number of rows -1, number colums -1)
nline = 11
ncol = 9
Upvotes: 3