const static int w_rc = 424, h_rc = 32;
void img_per(Mat img)
{
cv::resize(img, img, cv::Size2i(600, 55));
std::vector<float> result_points{2,13,565,14,1,44,565,43 };
Mat result = Mat(result_points);
result= result.reshape(1, std::vector<int>{ 4, 2 });
std::vector<float> target_points{ 0,0,w_rc - 1,0,0,h_rc - 1,w_rc - 1,h_rc - 1 };
Mat target = cv::Mat(target_points);
target = target.reshape(1, std::vector<int>{ 4, 2 });
Mat transform_matrix = cv::getPerspectiveTransform(result, target);
Mat target_img;
cv::warpPerspective(img, target_img, transform_matrix, cv::Size2i(w_rc, h_rc));//将result_points中的内容放到target_points大小的图像中
cv::imshow("original img2", img);
cv::imshow("transformed img2", target_img);
cv::waitKey(0);
}
以上代码中的img即上图,该代码是对img做透视变换!
备注:
warpPerspective()的Size2i()参数必须与target_points中的宽高一致,否则生成的透视变换的图像不正确!