OpenCV 5.0.0
Open Source Computer Vision
Loading...
Searching...
No Matches
QRCode detection and encoding

Detailed Description

Classes

struct  cv::CirclesGridFinderParameters
class  cv::QRCodeDetector
 QR code detector. More...
class  cv::QRCodeDetectorAruco
 QR code detector based on Aruco markers detection code. More...
class  cv::QRCodeEncoder
 QR code encoder. More...

Enumerations

enum  {
  cv::CALIB_CB_ADAPTIVE_THRESH = 1 ,
  cv::CALIB_CB_NORMALIZE_IMAGE = 2 ,
  cv::CALIB_CB_FILTER_QUADS = 4 ,
  cv::CALIB_CB_FAST_CHECK = 8 ,
  cv::CALIB_CB_EXHAUSTIVE = 16 ,
  cv::CALIB_CB_ACCURACY = 32 ,
  cv::CALIB_CB_LARGER = 64 ,
  cv::CALIB_CB_MARKER = 128 ,
  cv::CALIB_CB_PLAIN = 256
}
enum  {
  cv::CALIB_CB_SYMMETRIC_GRID = 1 ,
  cv::CALIB_CB_ASYMMETRIC_GRID = 2 ,
  cv::CALIB_CB_CLUSTERING = 4
}

Functions

bool cv::checkChessboard (InputArray img, Size size)
 Checks whether the image contains chessboard of the specific size or not.
void cv::drawChessboardCorners (InputOutputArray image, Size patternSize, InputArray corners, bool patternWasFound)
 Renders the detected chessboard corners.
Scalar cv::estimateChessboardSharpness (InputArray image, Size patternSize, InputArray corners, float rise_distance=0.8F, bool vertical=false, OutputArray sharpness=noArray())
 Estimates the sharpness of a detected chessboard.
bool cv::find4QuadCornerSubpix (InputArray img, InputOutputArray corners, Size region_size)
 finds subpixel-accurate positions of the chessboard corners
bool cv::findChessboardCorners (InputArray image, Size patternSize, OutputArray corners, int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE)
 Finds the positions of internal corners of the chessboard.
bool cv::findChessboardCornersSB (InputArray image, Size patternSize, OutputArray corners, int flags, OutputArray meta)
 Finds the positions of internal corners of the chessboard using a sector based approach.
bool cv::findChessboardCornersSB (InputArray image, Size patternSize, OutputArray corners, int flags=0)
bool cv::findCirclesGrid (InputArray image, Size patternSize, OutputArray centers, int flags, const Ptr< FeatureDetector > &blobDetector, const CirclesGridFinderParameters &parameters)
 Finds centers in the grid of circles.
bool cv::findCirclesGrid (InputArray image, Size patternSize, OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID, const Ptr< FeatureDetector > &blobDetector=cv::SimpleBlobDetector::create())

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

#include <opencv2/objdetect.hpp>

Enumerator
CALIB_CB_ADAPTIVE_THRESH 
Python: cv.CALIB_CB_ADAPTIVE_THRESH
CALIB_CB_NORMALIZE_IMAGE 
Python: cv.CALIB_CB_NORMALIZE_IMAGE
CALIB_CB_FILTER_QUADS 
Python: cv.CALIB_CB_FILTER_QUADS
CALIB_CB_FAST_CHECK 
Python: cv.CALIB_CB_FAST_CHECK
CALIB_CB_EXHAUSTIVE 
Python: cv.CALIB_CB_EXHAUSTIVE
CALIB_CB_ACCURACY 
Python: cv.CALIB_CB_ACCURACY
CALIB_CB_LARGER 
Python: cv.CALIB_CB_LARGER
CALIB_CB_MARKER 
Python: cv.CALIB_CB_MARKER
CALIB_CB_PLAIN 
Python: cv.CALIB_CB_PLAIN

◆ anonymous enum

anonymous enum

#include <opencv2/objdetect.hpp>

Enumerator
CALIB_CB_SYMMETRIC_GRID 
Python: cv.CALIB_CB_SYMMETRIC_GRID
CALIB_CB_ASYMMETRIC_GRID 
Python: cv.CALIB_CB_ASYMMETRIC_GRID
CALIB_CB_CLUSTERING 
Python: cv.CALIB_CB_CLUSTERING

Function Documentation

◆ checkChessboard()

bool cv::checkChessboard ( InputArray img,
Size size )
Python:
cv.checkChessboard(img, size) -> retval

#include <opencv2/objdetect.hpp>

Checks whether the image contains chessboard of the specific size or not.

Parameters
imgSource chessboard view.
sizeSize of the chessboard.
Returns
Whether a chessboard was found.

◆ drawChessboardCorners()

void cv::drawChessboardCorners ( InputOutputArray image,
Size patternSize,
InputArray corners,
bool patternWasFound )
Python:
cv.drawChessboardCorners(image, patternSize, corners, patternWasFound) -> image

#include <opencv2/objdetect.hpp>

Renders the detected chessboard corners.

Parameters
imageDestination image. It must be an 8-bit color image.
patternSizeNumber of inner corners per a chessboard row and column (patternSize = cv::Size(points_per_row,points_per_column)).
cornersArray of detected corners, the output of findChessboardCorners.
patternWasFoundParameter indicating whether the complete board was found or not. The return value of findChessboardCorners should be passed here.

The function draws individual chessboard corners detected either as red circles if the board was not found, or as colored corners connected with lines if the board was found.

Examples
samples/cpp/tutorial_code/features/Homography/pose_from_homography.cpp.

◆ estimateChessboardSharpness()

Scalar cv::estimateChessboardSharpness ( InputArray image,
Size patternSize,
InputArray corners,
float rise_distance = 0.8F,
bool vertical = false,
OutputArray sharpness = noArray() )
Python:
cv.estimateChessboardSharpness(image, patternSize, corners[, rise_distance[, vertical[, sharpness]]]) -> retval, sharpness

#include <opencv2/objdetect.hpp>

Estimates the sharpness of a detected chessboard.

Image sharpness, as well as brightness, are a critical parameter for accuracte camera calibration. For accessing these parameters for filtering out problematic calibraiton images, this method calculates edge profiles by traveling from black to white chessboard cell centers. Based on this, the number of pixels is calculated required to transit from black to white. This width of the transition area is a good indication of how sharp the chessboard is imaged and should be below ~3.0 pixels.

Parameters
imageGray image used to find chessboard corners
patternSizeSize of a found chessboard pattern
cornersCorners found by findChessboardCornersSB
rise_distanceRise distance 0.8 means 10% ... 90% of the final signal strength
verticalBy default edge responses for horizontal lines are calculated
sharpnessOptional output array with a sharpness value for calculated edge responses (see description)

The optional sharpness array is of type CV_32FC1 and has for each calculated profile one row with the following five entries: 0 = x coordinate of the underlying edge in the image 1 = y coordinate of the underlying edge in the image 2 = width of the transition area (sharpness) 3 = signal strength in the black cell (min brightness) 4 = signal strength in the white cell (max brightness)

Returns
Scalar(average sharpness, average min brightness, average max brightness,0)

◆ find4QuadCornerSubpix()

bool cv::find4QuadCornerSubpix ( InputArray img,
InputOutputArray corners,
Size region_size )
Python:
cv.find4QuadCornerSubpix(img, corners, region_size) -> retval, corners

#include <opencv2/objdetect.hpp>

finds subpixel-accurate positions of the chessboard corners

◆ findChessboardCorners()

bool cv::findChessboardCorners ( InputArray image,
Size patternSize,
OutputArray corners,
int flags = CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE )
Python:
cv.findChessboardCorners(image, patternSize[, corners[, flags]]) -> retval, corners

#include <opencv2/objdetect.hpp>

Finds the positions of internal corners of the chessboard.

Parameters
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 array of detected corners.
flagsVarious operation flags that can be zero or a combination of the following values:
  • CALIB_CB_ADAPTIVE_THRESH Use 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_IMAGE Normalize the image gamma with equalizeHist before applying fixed or adaptive thresholding.
  • CALIB_CB_FILTER_QUADS Use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads extracted at the contour retrieval stage.
  • CALIB_CB_FAST_CHECK Run 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_PLAIN All 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.
Returns
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: :

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,
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);
Comma-separated Matrix Initializer.
Definition mat.hpp:964
The class defining termination criteria for iterative algorithms.
Definition types.hpp:896
Size2i Size
Definition types.hpp:373
void cornerSubPix(InputArray image, InputOutputArray corners, Size winSize, Size zeroZone, TermCriteria criteria)
Refines the corner locations.
void drawChessboardCorners(InputOutputArray image, Size patternSize, InputArray corners, bool patternWasFound)
Renders the detected chessboard corners.
bool findChessboardCorners(InputArray image, Size patternSize, OutputArray corners, int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE)
Finds the positions of internal corners of the chessboard.
@ CALIB_CB_FAST_CHECK
Definition objdetect.hpp:323
@ CALIB_CB_ADAPTIVE_THRESH
Definition objdetect.hpp:320
@ CALIB_CB_NORMALIZE_IMAGE
Definition objdetect.hpp:321
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 (Create Calibration Pattern) to create the desired checkerboard pattern.

Examples
samples/cpp/tutorial_code/features/Homography/decompose_homography.cpp, samples/cpp/tutorial_code/features/Homography/homography_from_camera_displacement.cpp, and samples/cpp/tutorial_code/features/Homography/pose_from_homography.cpp.

◆ findChessboardCornersSB() [1/2]

bool cv::findChessboardCornersSB ( InputArray image,
Size patternSize,
OutputArray corners,
int flags,
OutputArray meta )
Python:
cv.findChessboardCornersSB(image, patternSize[, corners[, flags]]) -> retval, corners
cv.findChessboardCornersSBWithMeta(image, patternSize, flags[, corners[, meta]]) -> retval, corners, meta

#include <opencv2/objdetect.hpp>

Finds the positions of internal corners of the chessboard using a sector based approach.

Parameters
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 array of detected corners.
flagsVarious operation flags that can be zero or a combination of the following values:
  • CALIB_CB_NORMALIZE_IMAGE Normalize the image gamma with equalizeHist before detection.
  • CALIB_CB_EXHAUSTIVE Run an exhaustive search to improve detection rate.
  • CALIB_CB_ACCURACY Up sample input image to improve sub-pixel accuracy due to aliasing effects.
  • CALIB_CB_LARGER The detected pattern is allowed to be larger than patternSize (see description).
  • CALIB_CB_MARKER The detected pattern must have a marker (see description). This should be used if an accurate camera calibration is required.
metaOptional output array of detected corners (CV_8UC1 and size = cv::Size(columns,rows)). Each entry stands for one corner of the pattern and can have one of the following values:
  • 0 = no meta data attached
  • 1 = left-top corner of a black cell
  • 2 = left-top corner of a white cell
  • 3 = left-top corner of a black cell with a white marker dot
  • 4 = left-top corner of a white cell with a black marker dot (pattern origin in case of markers otherwise first corner)

The function is analog to findChessboardCorners but uses a localized radon transformation approximated by box filters being more robust to all sort of noise, faster on larger images and is able to directly return the sub-pixel position of the internal chessboard corners. The Method is based on the paper [duda2018] "Accurate Detection and Localization of Checkerboard Corners for Calibration" demonstrating that the returned sub-pixel positions are more accurate than the one returned by cornerSubPix allowing a precise camera calibration for demanding applications.

In the case, the flags CALIB_CB_LARGER or CALIB_CB_MARKER are given, the result can be recovered from the optional meta array. Both flags are helpful to use calibration patterns exceeding the field of view of the camera. These oversized patterns allow more accurate calibrations as corners can be utilized, which are as close as possible to the image borders. For a consistent coordinate system across all images, the optional marker (see image below) can be used to move the origin of the board to the location where the black circle is located.

Note
The function requires a white boarder with roughly the same width as one of the checkerboard fields around the whole board to improve the detection in various environments. In addition, because of the localized radon transformation it is beneficial to use round corners for the field corners which are located on the outside of the board. The following figure illustrates a sample checkerboard optimized for the detection. However, any other checkerboard can be used as well.

Use the generate_pattern.py Python script (Create Calibration Pattern) to create the corresponding checkerboard pattern:

◆ findChessboardCornersSB() [2/2]

bool cv::findChessboardCornersSB ( InputArray image,
Size patternSize,
OutputArray corners,
int flags = 0 )
inline
Python:
cv.findChessboardCornersSB(image, patternSize[, corners[, flags]]) -> retval, corners
cv.findChessboardCornersSBWithMeta(image, patternSize, flags[, corners[, meta]]) -> retval, corners, meta

#include <opencv2/objdetect.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ findCirclesGrid() [1/2]

bool cv::findCirclesGrid ( InputArray image,
Size patternSize,
OutputArray centers,
int flags,
const Ptr< FeatureDetector > & blobDetector,
const CirclesGridFinderParameters & parameters )
Python:
cv.findCirclesGrid(image, patternSize, flags, blobDetector, parameters[, centers]) -> retval, centers
cv.findCirclesGrid(image, patternSize[, centers[, flags[, blobDetector]]]) -> retval, centers

#include <opencv2/objdetect.hpp>

Finds centers in the grid of circles.

Parameters
imagegrid view of input circles; it must be an 8-bit grayscale or color image.
patternSizenumber of circles per row and column ( patternSize = Size(points_per_row, points_per_column) ).
centersoutput array of detected centers.
flagsvarious operation flags that can be one of the following values:
blobDetectorfeature detector that finds blobs like dark circles on light background. If blobDetector is NULL then image represents Point2f array of candidates.
parametersstruct for finding circles in a grid pattern.

return True if all of the centers have been found and they have been 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 contains a grid of circles. If it is, the function locates centers of the circles.

Sample usage of detecting and drawing the centers of circles: :

Size patternsize(7,7); //number of centers
Mat gray = ...; //source image
vector<Point2f> centers; //this will be filled by the detected centers
bool patternfound = findCirclesGrid(gray, patternsize, centers);
drawChessboardCorners(img, patternsize, Mat(centers), patternfound);
bool findCirclesGrid(InputArray image, Size patternSize, OutputArray centers, int flags, const Ptr< FeatureDetector > &blobDetector, const CirclesGridFinderParameters &parameters)
Finds centers in the grid of circles.
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.

◆ findCirclesGrid() [2/2]

bool cv::findCirclesGrid ( InputArray image,
Size patternSize,
OutputArray centers,
int flags = CALIB_CB_SYMMETRIC_GRID,
const Ptr< FeatureDetector > & blobDetector = cv::SimpleBlobDetector::create() )
Python:
cv.findCirclesGrid(image, patternSize, flags, blobDetector, parameters[, centers]) -> retval, centers
cv.findCirclesGrid(image, patternSize[, centers[, flags[, blobDetector]]]) -> retval, centers

#include <opencv2/objdetect.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.