C# 如何使用Emgu.CV将小图像复制到大图像中的指定位置?
我有几个小的图像,我希望他们有准确的100x100像素没有缩放。为了归档,我创建了一个100x100的白色图像,并将小图像复制到这些图像中 我的代码:C# 如何使用Emgu.CV将小图像复制到大图像中的指定位置?,c#,image,emgucv,C#,Image,Emgucv,我有几个小的图像,我希望他们有准确的100x100像素没有缩放。为了归档,我创建了一个100x100的白色图像,并将小图像复制到这些图像中 我的代码: /*Small image*/ Emgu.CV.Mat Char = new Emgu.CV.Mat(); /*...fill small Image with stuff...*/ /*Create black Image (don't know how to create a White Image)*/ FinalChar = Emgu.
/*Small image*/
Emgu.CV.Mat Char = new Emgu.CV.Mat();
/*...fill small Image with stuff...*/
/*Create black Image (don't know how to create a White Image)*/
FinalChar = Emgu.CV.Mat.Zeros(100, 100, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
/*Invert Image to become white*/
Emgu.CV.CvInvoke.BitwiseNot(FinalChar, FinalChar);
/*Copy small Image to large Image starting at row 5 and column 5*/
Char.CopyTo(FinalChar.Row(5).Col(5)); /*This is NOT working... Image 'Finalchar' is still White.*/
请不要告诉我这个帖子:
我不知道,但是rowRange
和colRange
不是Emgu.CV的一部分
下面是一个小的、不起作用的示例,您可以复制来试用:
/*Create small black image*/
Emgu.CV.Mat Small = Emgu.CV.Mat.Zeros(10, 10, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
/*Create large white image*/
Emgu.CV.Mat Large = Emgu.CV.Mat.Zeros(20, 20, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
Emgu.CV.CvInvoke.BitwiseNot(Large, Large);
/*Copy small, black image to large white image at 5,5 - the large image should
now contain a black rect in its center*/
Small.CopyTo(Large.Row(5).Col(5));
Emgu.CV.CvInvoke.NamedWindow("Output", Emgu.CV.CvEnum.NamedWindowType.AutoSize);
Emgu.CV.CvInvoke.Imshow("Output", Large);
Emgu.CV.CvInvoke.WaitKey();
return;
好的,示例“将较小的图像放在较大的图像中”是不正确的-它只是添加了图像。所以,如果你的基础图像是黑色的,它会起作用。但是,如果您的图像是白色的(R=G=B=255),并且您添加了任何值,它将剪辑为255
但这对我来说是可行的:
public static Emgu.CV.Mat EnterAtCenter(int Size = 100)
{
/*Create Mat and Image large, white*/
Emgu.CV.Mat Large = Emgu.CV.Mat.Zeros(Size, Size, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
Emgu.CV.CvInvoke.BitwiseNot(Large, Large);
Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> ImageLarge = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(Large.Bitmap);
/*Create Mat and Image small, black*/
Emgu.CV.Mat Small = Emgu.CV.Mat.Zeros(10, 10, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> ImageSmall = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(Small.Bitmap);
/*Copy small Image to large Image at 5,5*/
ImageLarge.ROI = new System.Drawing.Rectangle(5, 5, Small.Width, Small.Height);
ImageSmall.CopyTo(ImageLarge);
ImageLarge.ROI = System.Drawing.Rectangle.Empty;
return ImageLarge.Mat;
}
public static Emgu.CV.Mat EnterAtCenter(int Size=100)
{
/*创建大的白色垫子和图像*/
Emgu.CV.Mat Large=Emgu.CV.Mat.zero(大小,大小,Emgu.CV.CvEnum.DepthType.Cv8U,1);
Emgu.CV.CvInvoke.BitwiseNot(大,大);
Emgu.CV.Image ImageLarge=新Emgu.CV.Image(大位图);
/*创建小的、黑色的垫子和图像*/
Emgu.CV.Mat Small=Emgu.CV.Mat.zero(10,10,Emgu.CV.CvEnum.DepthType.Cv8U,1);
Emgu.CV.Image imagesall=新Emgu.CV.Image(小位图);
/*在5,5处将小图像复制到大图像*/
ImageLarge.ROI=新系统.绘图.矩形(5,5,小.宽,小.高);
ImageSmall.CopyTo(ImageLarge);
ImageLarge.ROI=System.Drawing.Rectangle.Empty;
返回ImageLarge.Mat;
}
好的,示例“将较小的图像放在较大的图像中”是不正确的-它只是添加了图像。所以,如果你的基础图像是黑色的,它会起作用。但是,如果您的图像是白色的(R=G=B=255),并且您添加了任何值,它将剪辑为255
但这对我来说是可行的:
public static Emgu.CV.Mat EnterAtCenter(int Size = 100)
{
/*Create Mat and Image large, white*/
Emgu.CV.Mat Large = Emgu.CV.Mat.Zeros(Size, Size, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
Emgu.CV.CvInvoke.BitwiseNot(Large, Large);
Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> ImageLarge = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(Large.Bitmap);
/*Create Mat and Image small, black*/
Emgu.CV.Mat Small = Emgu.CV.Mat.Zeros(10, 10, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> ImageSmall = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(Small.Bitmap);
/*Copy small Image to large Image at 5,5*/
ImageLarge.ROI = new System.Drawing.Rectangle(5, 5, Small.Width, Small.Height);
ImageSmall.CopyTo(ImageLarge);
ImageLarge.ROI = System.Drawing.Rectangle.Empty;
return ImageLarge.Mat;
}
public static Emgu.CV.Mat EnterAtCenter(int Size=100)
{
/*创建大的白色垫子和图像*/
Emgu.CV.Mat Large=Emgu.CV.Mat.zero(大小,大小,Emgu.CV.CvEnum.DepthType.Cv8U,1);
Emgu.CV.CvInvoke.BitwiseNot(大,大);
Emgu.CV.Image ImageLarge=新Emgu.CV.Image(大位图);
/*创建小的、黑色的垫子和图像*/
Emgu.CV.Mat Small=Emgu.CV.Mat.zero(10,10,Emgu.CV.CvEnum.DepthType.Cv8U,1);
Emgu.CV.Image imagesall=新Emgu.CV.Image(小位图);
/*在5,5处将小图像复制到大图像*/
ImageLarge.ROI=新系统.绘图.矩形(5,5,小.宽,小.高);
ImageSmall.CopyTo(ImageLarge);
ImageLarge.ROI=System.Drawing.Rectangle.Empty;
返回ImageLarge.Mat;
}
如果你能提供一个,那就太棒了。如果你能提供一个。可能的副本,那就太棒了