Category Archives: Uncategorized

Making a Chessboard Pattern for Camera Calibration

The following code can be used to make a chessboard image given the number of rows and columns of the chessboard, square size in pixel, and two colors.

The default size of the square is 100 pixels and default colors are black and white.

chessboard
crvlMakeChessboardPattern(chessboardImg, 6, 8);
chessboard2
crvlMakeChessboardPattern(chessboardImg, 5, 7, 200, CV_RGB(255, 0, 0), CV_RGB(0, 0, 255))

Use an image viewer like Irfanview to print the saved chessboard pattern to a paper maintaining the required size of the chessboard in metric measurements.

As an example, if you want to print a 5×7 chessboard pattern where one square should be 3cm×3cm, select the options as follows.

clipboard01
Printing options.

Converting images from RGB to HSV

Here is a code snippet we can use for converting an image from RGB colour space to HSV colour space. OpenCV uses BGR format instead of RGB. Therefore, we have to use the CV_BGR2HSV flag to convert the image to HSV space and then the “split” method to separate the hue, saturation and value channels.

OpenCV “cv::Mat” Data Types

These are the data types we can use with OpenCV Matrices.

DATA TYPERANGEIPL IMAGESCV::MAT
Unsigned 8bitsuchar0 ~ 255IPL_DEPTH_8UCV_8UC1
CV_8UC2
CV_8UC3
CV_8UC4
Signed 8bitschar-128 ~ 127IPL_DEPTH_8SCV_8SC1
CV_8SC2
CV_8SC3
CV_8SC4
Unsigned 16bitsushort0 ~ 65535IPL_DEPTH_16UCV_16UC1
CV_16UC2
CV_16UC3
CV_16UC4
Signed 16bitsshort-32768 ~ 32767IPL_DEPTH_16SCV_16SC1
CV_16SC2
CV_16SC3
CV_16SC4
Signed 32bitsint-2147483648 ~ 2147483647IPL_DEPTH_32SCV_32SC1
CV_32SC2
CV_32SC3
CV_32SC4
Float 32bitsfloat-1.18e-38 ~ 3.40e-38IPL_DEPTH_32FCV_32FC1
CV_32FC2
CV_32FC3
CV_32FC4
Double 64bitsdouble-1.7e+308 ~ +1.7e+308IPL_DEPTH_64FCV_64FC1
CV_64FC2
CV_64FC3
CV_64FC4
Unsigned 1bitbool0 and 1IPL_DEPTH_1U 

‘C’ represents the number of channels

  • C1: 1 channel
  • C2: 2 channels
  • C3: 3 channels
  • C4: 4 channels

We can check the Data Type of a cv::Mat using “type()” method.

This is a method you can use for checking the type of an cv::Mat.

The following method can be used to print any type of single channel cv::Mat

clipboard03
Example output of _PrintMatrix() method

src: StackOverflaw