Go straight to code

#include<opencv2/core.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/imgproc.hpp>
using namespace cv;

int main(int argc, char* argv[]) {
	Mat img = imread("C:\\Users\\Administrator\\Desktop\\timg.jpg", CV_LOAD_IMAGE_GRAYSCALE);
	if(! img.data)return- 1; Mat s = (Mat_<) // The first way: use warpAffine to scale the affine matrix.float>(2, 3) << 0.5, 0, 0, 0, 0.5, 0); Mat dst1; warpAffine(img, dst1, s, Size(img.cols / 2, img.rows / 2)); // Second way: use resize to scale down twice Mat dST2; Resize (img, dst2, Size(img.cols / 2, img.rows / 2), 0.5, 0.5); resize(img, dst2, Size(img.cols / 2, img.rows / 2), 0.5, 0.5); imshow("Original",img);
	imshow("warpAffine",dst1);
	imshow("resize",dst2);
	waitKey(0);
	return 0;

}Copy the code


Results:





Ps: If the program flashes back

Error: program “[2232] opencvDemo3.exe” has quit, return -1 (0xffffFFFF).

The image in imread cannot be found




1