天天看點

學習圖像處理知識---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; 

學習圖像處理知識---Emgu3.4 image類學習(四)

旋轉圖檔(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
)      
學習圖像處理知識---Emgu3.4 image類學習(四)

 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
)      
學習圖像處理知識---Emgu3.4 image類學習(四)

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;