随手小功能1-图像正方形截取

功能说明:将长宽不一致的图片,以短边为基准,生成新的正方形图片

	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

猜你喜欢

转载自blog.csdn.net/ShawShankChina/article/details/81233692
今日推荐