QRCode detection and encoding#

Detailed Description#

Classes#

Name

Description

struct cv::CirclesGridFinderParameters

View details

class cv::QRCodeDetector

QR code detector. View details

class cv::QRCodeDetectorAruco

QR code detector based on Aruco markers detection code. View details

class cv::QRCodeEncoder

QR code encoder. View details

Enumerations#

View details

View details

Enumeration Type Documentation#

enum#

#include <opencv2/objdetect.hpp>

Enumerator:

CALIB_CB_ADAPTIVE_THRESH

CALIB_CB_NORMALIZE_IMAGE

CALIB_CB_FILTER_QUADS

CALIB_CB_FAST_CHECK

CALIB_CB_EXHAUSTIVE

CALIB_CB_ACCURACY

CALIB_CB_LARGER

CALIB_CB_MARKER

CALIB_CB_PLAIN

enum#

#include <opencv2/objdetect.hpp>

Enumerator:

CALIB_CB_SYMMETRIC_GRID

CALIB_CB_ASYMMETRIC_GRID

CALIB_CB_CLUSTERING

Function Documentation#

checkChessboard()#

bool cv::checkChessboard(
InputArray img,
Size size )

#include <opencv2/objdetect.hpp>

Python:

cv.checkChessboard(img, size) -> retval

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

Parameters

  • img — Source chessboard view.

  • size — Size of the chessboard.

Returns

Whether a chessboard was found.

drawChessboardCorners()#

void cv::drawChessboardCorners(
InputOutputArray image,
Size patternSize,
InputArray corners,
bool patternWasFound )

#include <opencv2/objdetect.hpp>

Python:

cv.drawChessboardCorners(image, patternSize, corners, patternWasFound) -> image

Renders the detected chessboard corners.

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.

Parameters

  • image — Destination image. It must be an 8-bit color image.

  • patternSize — Number of inner corners per a chessboard row and column (patternSize = cv::Size(points_per_row,points_per_column)).

  • corners — Array of detected corners, the output of findChessboardCorners.

  • patternWasFound — Parameter indicating whether the complete board was found or not. The return value of findChessboardCorners should be passed here.

estimateChessboardSharpness()#

Scalar cv::estimateChessboardSharpness(
InputArray image,
Size patternSize,
InputArray corners,
float rise_distance = 0.8F,
bool vertical = false,
OutputArray sharpness = noArray() )

#include <opencv2/objdetect.hpp>

Python:

cv.estimateChessboardSharpness(image, patternSize, corners[, rise_distance[, vertical[, sharpness]]]) -> retval, sharpness

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.

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)

Parameters

  • image — Gray image used to find chessboard corners

  • patternSize — Size of a found chessboard pattern

  • corners — Corners found by findChessboardCornersSB

  • rise_distance — Rise distance 0.8 means 10% … 90% of the final signal strength

  • vertical — By default edge responses for horizontal lines are calculated

  • sharpness — Optional output array with a sharpness value for calculated edge responses (see description)

Returns

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

find4QuadCornerSubpix()#

bool cv::find4QuadCornerSubpix(
InputArray img,
InputOutputArray corners,
Size region_size )

#include <opencv2/objdetect.hpp>

Python:

cv.find4QuadCornerSubpix(img, corners, region_size) -> retval, corners

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 )

#include <opencv2/objdetect.hpp>

Python:

cv.findChessboardCorners(image, patternSize[, corners[, flags]]) -> retval, corners

Finds the positions of internal corners of the chessboard.

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,
        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.

Parameters

  • image — Source chessboard view. It must be an 8-bit grayscale or color image.

  • patternSize — Number of inner corners per a chessboard row and column ( patternSize = cv::Size(points_per_row,points_per_column) = cv::Size(columns,rows) ).

  • corners — Output array of detected corners.

  • flags — Various 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.

findChessboardCornersSB()#

bool cv::findChessboardCornersSB(
InputArray image,
Size patternSize,
OutputArray corners,
int flags,
OutputArray meta )

#include <opencv2/objdetect.hpp>

Python:

cv.findChessboardCornersSB(image, patternSize[, corners[, flags]]) -> retval, corners
cv.findChessboardCornersSBWithMeta(image, patternSize, flags[, corners[, meta]]) -> retval, corners, meta

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

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 [86] “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 (tutorial_camera_calibration_pattern) to create the corresponding checkerboard pattern:

Parameters

  • image — Source chessboard view. It must be an 8-bit grayscale or color image.

  • patternSize — Number of inner corners per a chessboard row and column ( patternSize = cv::Size(points_per_row,points_per_column) = cv::Size(columns,rows) ).

  • corners — Output array of detected corners.

  • flags — Various 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.

  • meta — Optional 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)

findChessboardCornersSB()#

bool cv::findChessboardCornersSB(
InputArray image,
Size patternSize,
OutputArray corners,
int flags = 0 )

#include <opencv2/objdetect.hpp>

Python:

cv.findChessboardCornersSB(image, patternSize[, corners[, flags]]) -> retval, corners
cv.findChessboardCornersSBWithMeta(image, patternSize, flags[, corners[, meta]]) -> retval, corners, meta

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

Here is the call graph for this function:

cv::findChessboardCornersSB Node1 cv::findChessboardCornersSB Node2 cv::findChessboardCornersSB Node1->Node2 Node3 cv::noArray Node1->Node3

cv::findChessboardCornersSB Node1 cv::findChessboardCornersSB Node2 cv::findChessboardCornersSB Node1->Node2 Node3 cv::noArray Node1->Node3

findCirclesGrid()#

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

#include <opencv2/objdetect.hpp>

Python:

cv.findCirclesGrid(image, patternSize, flags, blobDetector, parameters[, centers]) -> retval, centers
cv.findCirclesGrid(image, patternSize[, centers[, flags[, blobDetector]]]) -> retval, centers

Finds centers in the grid of circles.

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);

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.

Parameters

  • image — grid view of input circles; it must be an 8-bit grayscale or color image.

  • patternSize — number of circles per row and column ( patternSize = Size(points_per_row, points_per_column) ).

  • centers — output array of detected centers.

  • flags — various operation flags that can be one of the following values:

    • CALIB_CB_SYMMETRIC_GRID uses symmetric pattern of circles.

    • CALIB_CB_ASYMMETRIC_GRID uses asymmetric pattern of circles.

    • CALIB_CB_CLUSTERING uses a special algorithm for grid detection. It is more robust to perspective distortions but much more sensitive to background clutter.

  • blobDetector — feature detector that finds blobs like dark circles on light background. If blobDetector is NULL then image represents Point2f array of candidates.

  • parameters — struct for finding circles in a grid pattern.

findCirclesGrid()#

bool cv::findCirclesGrid(
InputArray image,
Size patternSize,
OutputArray centers,
int flags = CALIB_CB_SYMMETRIC_GRID,
const Ptr< FeatureDetector > & blobDetector = cv::SimpleBlobDetector::create() )

#include <opencv2/objdetect.hpp>

Python:

cv.findCirclesGrid(image, patternSize, flags, blobDetector, parameters[, centers]) -> retval, centers
cv.findCirclesGrid(image, patternSize[, centers[, flags[, blobDetector]]]) -> retval, centers

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