# include & lt; Iostream>
# include & lt; An FCNTL. H>
# include & lt; IO. H>
# include & lt; Opencv2/core/core. Hpp>
# include & lt; Opencv2/opencv. Hpp>
using namespace std;
Using the namespace CV;
////method from https://blog.csdn.net/shirly_xr/article/details/83792028
Bool SetResolution (const char * path, int iResolution)
{
The FILE * FILE=fopen (path, "rb +");//- open the image file
if (! The file) return false.
Int len=_filelength (_fileno (file));//- access to the file size
Char * buf=new char (len);
Fread (buf, sizeof (char), len, file).//- the image data read cache
Char * pResolution=(char *) & amp; IResolution;//- iResolution to set the value of the resolution of the, such as 72 dpi
Buf x0d [0]=1;//- set using image density
//- level density, horizontal resolution
Buf x0e [0]=pResolution [1].
Buf [0 x0f]=pResolution [0].
//- vertical density, vertical resolution
Buf [0 x10]=pResolution [1].
Buf x11 [0]=pResolution [0].
//- the file pointer back to the beginning
Fseek (file, 0, SEEK_SET);
//- the data is written to the file, cover the original data, make changes to take effect
Fwrite (buf, sizeof (char), len, file).
The fclose (file);
return true;
}
Int main () {
//custom calibration plate
Int blockSize_mm=10;//block length, unit: mm
Int blockNum=10;//
Int blockNum_col=7;//column
Int resolution_ratio=10;
Int blockSize_pixel=blockSize_mm * resolution_ratio;
Int edge_size_pixel=blockSize_pixel/2;
Int imageSize=blockSize_pixel * blockNum;
Int imageSize_col=blockSize_pixel * blockNum_col;
Cout & lt; <"ImageSize=" & lt;
Cout & lt; <"ChessBoard. The size ()=" & lt;
For (int I=0; I & lt; ImageSize_col; I=I + blockSize_pixel) {//column
for (int j=0; J & lt; ImageSize; J={j + blockSize_pixel)
Mat ROI=chessBoard (the Rect (I, j, blockSize_pixel, blockSize_pixel));
If (((I + j)/blockSize_pixel) % 2==0)
ROI. SetTo (Scalar: : all (0));
The else
ROI. SetTo (Scalar: : all (255));
}
}
Mat chessBoard_final=CV: : Mat: : zeros ((imageSize + blockSize_pixel), (imageSize_col + blockSize_pixel), CV_8UC1);
ChessBoard_final. SetTo (Scalar: : all (255));
The Rect chessBoard_rect=the Rect (edge_size_pixel edge_size_pixel, imageSize_col, imageSize);
Cout & lt; <"ChessBoard_final. The size ()=" & lt;
//chessBoard_final (chessBoard_rect)=chessBoard;
ChessBoard. CopyTo (chessBoard_final (chessBoard_rect));
Imshow (" Chess board ", chessBoard_final);
Imwrite (" chessBoard. JPG ", chessBoard_final);
Int iResolution=254;//image resolution
Char path [20]="./chessBoard. JPG ";
SetResolution (path, iResolution);
WaitKey (3000);
return 0;
}
CodePudding user response:
Try the printer resolution 300 dpi or 600 dpi