1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include "stdafx,h" #include "opencv.hpp" using namespace cv; using namespace std; int main() { cv::Mat image =cv::imread("D:/image/lane.bmp",cv::IMREAD_COLOR); cv::Mat resize_image, resize_image_M; cv::resize(image,resize_image,cv::size(0,0),0.5,0.5,1); cv::Mat warp_matrix_resize; warp_matrix_resize = cv::Mat::zeros(2,3,CV 32F); float cx=0.75,cy=0.5; warp_matrix_resize.at<float>(0, 0) = cx; warp_matrix_resize.at<float>(1, 1) = cy; cv::Size dsize = image.size(); dsize.width *= cx; dsize.height *= cy; warpAffine(image,resize_image_M,warp_matrix_resize,dsize,INTER LINEAR,1); cv::Mat temp_image=resize_image.clone(); cv::Mat translation_image; cv::Mat warp_matrix_translation; warp_matrix_translation = cv::Mat::eye(2,3,CV 32F); float tx=40,ty=20; warp_matrix_translation.at<float>(0,2) = tx; warp_matrix_translation.at<float>(1,2) = ty; int top =0,bottom = ty, left =0,right = tx; cv::copyMakeBorder(temp_image, temp_image,top,bottom,left,right, BORDER_CONSTANT,cv::Scalar(200)); cv::warpAffine(temp_image, translation_image, warp_matrix_translation,temp image.size(),INTER LINEAR,BORDER_TRANSPARENT); cv::Mat rotate_image; temp_image= resize_image.clone(); double angle=45; int border=0.207 * temp_image.cols; cv::copyMakeBorder(temp_image, temp_image, border, border, border,border, BORDER_CONSTANT,cv::Scalar(200)); cv::Point2f center(temp_image.cols / 2., temp_image.rows / 2.); cv::Mat warp_rotate_matrix = cv::getRotationMatrix2D(center, angle, 1.0); cv::warpAffine(temp_image, rotate_image, warp_rotate_matrix,temp_image.size(),INTER_LINEAR,BORDER_REPLICATE); cv::Mat shear_vertical_image,shear_horizontal_image; temp_image= resize_image.clone(); cv::Mat temp_image_vertical,temp_image_horizontal; border=40; cv::copyMakeBorder(temp_image, temp_image_vertical,10,2* border, border,10 +border,BORDER_CONSTANT,cv::Scalar(200)); cv::copyMakeBorder(temp_image, temp_image_horizontal, border + 10, border,10,2*border,BORDER_CONSTANT,cv::Scalar(200)); cv::Mat warp_matrix_shear_vertical, warp_matrix_shear_horizontal; warp_matrix_shear_vertical = cv::Mat::eye(2,3,CV 32F); warp_matrix_shear_horizontal = cv::Mat::eye(2,3,CV 32F); float sv=0.3,sh=0.3; warp_matrix_shear_horizontal.at<float>(0, 1)=sh; warp_matrix_shear_vertical.at<float>(1, 0) = sv; cv::warpAffine(temp_image_vertical,shear_vertical_image,warp_matrix_shear_vertical,temp_image vertical.size(),INTER_LINEAR,BORDER_REPLICATE); cv::warpAffine(temp_image_horizontal, shear_horizontal_image,warp_matrix_shear_horizontal,temp_image horizontal.size(),INTER_LINEAR, BORDER_REPLICATE); return0; }
|