findChessboardCorners
import { findChessboardCorners } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Finds the positions of internal corners of the chessboard.
Size patternsize(8,6); //interior number of corners
Mat gray = ....; //source image
vector<Point2f> corners; //this will be filled by the detected corners
//CALIB_CB_FAST_CHECK saves a lot of time on images
//that do not contain any chessboard corners
bool patternfound = findChessboardCorners(gray, patternsize, corners,
CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE
+ CALIB_CB_FAST_CHECK);
if(patternfound)
cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1),
TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
drawChessboardCorners(img, patternsize, Mat(corners), patternfound);
Note: The function requires white space (like a square-thick border, the wider the better) around the board to make the detection more robust in various environments. Otherwise, if there is no border and the background is dark, the outer black squares cannot be segmented properly and so the square grouping and ordering algorithm fails.
Use the generate_pattern.py Python script (tutorial_camera_calibration_pattern)
to create the desired checkerboard pattern.
findChessboardCorners(image: Mat, patternSize: Size, corners: Mat, flags: number): boolean;2 available overloads
findChessboardCorners(image: Mat, patternSize: Size, corners: Mat): boolean;findChessboardCorners(image: Mat, patternSize: Size, corners: Mat, flags: number): boolean;imageSource chessboard view. It must be an 8-bit grayscale or color image.
patternSizeNumber of inner corners per a chessboard row and column ( patternSize = cv::Size(points_per_row,points_per_column) = cv::Size(columns,rows) ).
cornersOutput destination, filled by the native operation. Output array of detected corners.
flagsVarious operation flags that can be zero or a combination of the following values:
CALIB_CB_ADAPTIVE_THRESHUse adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness).CALIB_CB_NORMALIZE_IMAGENormalize the image gamma with equalizeHist before applying fixed or adaptive thresholding.CALIB_CB_FILTER_QUADSUse additional criteria (like contour area, perimeter, square-like shape) to filter out false quads extracted at the contour retrieval stage.CALIB_CB_FAST_CHECKRun a fast check on the image that looks for chessboard corners, and shortcut the call if none is found. This can drastically speed up the call in the degenerate condition when no chessboard is observed.CALIB_CB_PLAINAll other flags are ignored. The input image is taken as is. No image processing is done to improve to find the checkerboard. This has the effect of speeding up the execution of the function but could lead to not recognizing the checkerboard if the image is not previously binarized in the appropriate manner.
True if all of the corners are found and placed in a certain order (row by row, left to right in every row). Otherwise, if the function fails to find all the corners or reorder them, it returns false.
The function attempts to determine whether the input image is a view of the chessboard pattern and locate the internal chessboard corners. For example, a regular chessboard has 8 x 8 squares and 7 x 7 internal corners, that is, points where the black squares touch each other. The detected coordinates are approximate, and to determine their positions more accurately, the function calls #cornerSubPix. You also may use the function #cornerSubPix with different parameters if returned coordinates are not accurate enough.
Sample usage of detecting and drawing chessboard corners: :
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.