赞
踩
- public static void Forexample()
- {
-
- var Src_Images = Cv2.ImRead("lenna.png", ImreadModes.Color);
- var SRC = new Mat();
- var SRC1 = new Mat();
- Cv2.Flip(Src_Images, SRC, FlipMode.X);
- Cv2.Flip(Src_Images, SRC1, FlipMode.Y);
- Cv2.ImShow("1", Src_Images);
- Cv2.ImShow("2", SRC);
- Cv2.ImShow("3", SRC1);
-
- }
- //转置矩阵
- public static void Transpose(InputArray src, OutputArray dst)
- {
- //需要搭配使用
- Cv2.Flip(src,dst,FlipMode.XY);
- Cv2.Transpose(src, dst);
-
- }
rotate 这个算子只能旋转固定的角度。90度180度270度
- public static void Forexample()
- {
-
- var Src_Images = Cv2.ImRead("lenna.png", ImreadModes.Color);
- var SRC = new Mat();
- var SRC1 = new Mat();
- var SRC2 = new Mat();
-
-
- //90度
- Cv2.Rotate(Src_Images, SRC, RotateFlags.Rotate90Clockwise);
- //180度
- Cv2.Rotate(Src_Images, SRC2, RotateFlags.Rotate180);
- //270度
- Cv2.Rotate(Src_Images, SRC1, RotateFlags.Rotate90Counterclockwise);
-
-
- Cv2.ImShow("1", Src_Images);
- Cv2.ImShow("2", SRC);
- Cv2.ImShow("3", SRC1);
- Cv2.ImShow("4", SRC2);
-
- }
- //仿射变换
- //方法一 旋转缩放
- //Point center = new Point(SrcImage.Cols / 2, SrcImage.Rows / 2);
- //double angle =0;
- //double scale = 1;
- //Mat rot_mat = Cv2.GetRotationMatrix2D(center, angle, scale);
-
- //方法二 旋转平移缩放
- Point center = new Point(SrcImage.Cols / 2, SrcImage.Rows / 2);
- double angle = 60.0 / 180.0 * Cv2.PI;//旋转角度,正值表示逆时针旋转
- //旋转平移缩放
- Mat rot_mat = GetTransformRotationMatrix2D(center, 100, 0, 0, 1);
- Mat warp_rotate_dst =new Mat();
- Cv2.WarpAffine(SrcImage, warp_rotate_dst, rot_mat, SrcImage.Size());
- Cv2.ImShow("warp_rotate_dst", warp_rotate_dst);
- Cv2.ImShow("origindst", SrcImage);
旋转平移封装代码
- public static Mat GetTransformRotationMatrix2D(OpenCvSharp.Point2f center, double Translation_X, double Translation_Y, double Rotate_Angle, double Scale = 1)
- {
-
- Mat M = Mat.Zeros(2, 3, MatType.CV_64FC1);
-
- M.At<double>(0, 0) = (double)(Scale * Math.Cos(Rotate_Angle * Math.PI / 180));
- M.At<double>(0, 1) = -(double)(Scale * Math.Sin(Rotate_Angle * Math.PI / 180));
- M.At<double>(1, 0) = (double)(Scale * Math.Sin(Rotate_Angle * Math.PI / 180));
- M.At<double>(1, 1) = (double)(Scale * Math.Cos(Rotate_Angle * Math.PI / 180));
-
- M.At<double>(0, 2) = (double)((1 - M.At<double>(0, 0)) * center.X - M.At<double>(0, 1) * center.Y + Translation_X);
- M.At<double>(1, 2) = (double)(M.At<double>(0, 1) * center.X + (1 - M.At<double>(0, 0)) * center.Y + Translation_Y);
-
-
- return M;
- }
图像的平移
修改代码
Mat rot_mat = GetTransformRotationMatrix2D(center, 0, 0, 45, 1);
图像的旋转
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。