学习图像处理知识---Emgu3.4 image类学习(四)
图片尺寸变法
1.降图片变成指定大小(3个重载函数)
PyrDown() 尺寸变小
PyrUp() 尺寸变大
public Image<TColor, TDepth> Resize( double scale, Inter interpolationType )
public Image<TColor, TDepth> Resize( int width, int height, Inter interpolationType )
public Image<TColor, TDepth> Resize( int width, int height, Inter interpolationType, bool preserveScale //如为true,图像比列不变。 )
pictureBox2.Image = YUAN.Resize(500, 500, Emgu.CV.CvEnum.Inter.Linear, false).Bitmap;
旋转图片(3个重载函数)
public Image<TColor, TDepth> Rotate( double angle, TColor background, bool crop //false,不裁切 要缩小图片,默认为中心点旋转,角度为正为顺时针 )
public Image<TColor, TDepth> Rotate( double angle, PointF center, Inter interpolationMethod, TColor background, bool crop )
Emgu.CV.Image<Bgr, Byte> YUAN = new Image<Bgr, byte>((Bitmap)pictureBox1.Image);
pictureBox2.Image = YUAN.Rotate(20,new Bgr(Color.Red),false ).Bitmap;
pictureBox2.Image = YUAN.Rotate(20,new PointF(100,50), Emgu.CV.CvEnum.Inter.Linear, new Bgr(Color.Red), true).Bitmap;
图片仿射变换(首先要得到2*3变换矩阵Mat mapMatrix)
采用CvInvoke类
public static Mat GetAffineTransform( PointF[] src, //找3个点 源图像 PointF[] dest //目标图像 )
public static void GetRotationMatrix2D( PointF center, double angle, double scale, IOutputArray mapMatrix )
public Image<TColor, TDepth> WarpAffine( Mat mapMatrix, Inter interpolationType, Warp warpType, BorderType borderMode, TColor backgroundColor )
public Image<TColor, TDepth> WarpAffine( Mat mapMatrix, int width, int height, Inter interpolationType, Warp warpType, BorderType borderMode, TColor backgroundColor )
Emgu.CV.Image<Bgr, Byte> YUAN = new Image<Bgr, byte>((Bitmap)pictureBox1.Image);
Mat af1 = new Mat(); //得到2*3变换矩阵Mat mapMatrix
CvInvoke.GetRotationMatrix2D(new PointF(YUAN.Width / 2, YUAN.Height / 2), 20, 1, af1);
pictureBox2.Image = YUAN.WarpAffine(af1,Emgu.CV.CvEnum.Inter.Linear,Emgu.CV.CvEnum.Warp.Default,Emgu.CV.CvEnum.BorderType.Default,new Bgr(Color.Blue)).Bitmap;