功能说明:将长宽不一致的图片,以短边为基准,生成新的正方形图片
Mat src;
src = imread("D:/Learn/OpenCV/Info/PIC/dt.jpg");
int mix = src.rows;
if (mix > src.cols)
{
mix = src.cols;
}
Mat matdst = Mat(mix, mix, src.type());
for (int row = 0; row < mix; row++)
{
for (int col = 0; col < mix; col++)
{
matdst.at<Vec3b>(row, col) = src.at<Vec3b>(row, col);
}
}
imshow("newdt",matdst);
imwrite("D:/Learn/OpenCV/Info/PIC/newdt.jpg", matdst);
前后效果图片:
dt.jpg
newdt.jpg