本文整理汇总了C#中Mat.Resize方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.Resize方法的具体用法?C# Mat.Resize怎么用?C# Mat.Resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat.Resize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public static void Execute()
{
using (var vmClient = new VmClient())
using (var mouseClient = new MouseClient(VmIp))
{
var printIndex = new Dictionary<ScreenPrint, int>();
for (;;)
{
var bmp = GetScreenImage(vmClient.GameScreenRect);
var img = bmp.ToIplImage();
var vBmp = new Mat(img, false).CvtColor(ColorConversion.RgbToHsv).Split()[2];
//vBmp.ToBitmap().Save("v.png");
//vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(16, 16)).ToBitmap().Save("v.16.png");
//vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(128, 128)).ToBitmap().Save("v.128.png");
var small = vBmp.Resize(new OpenCvSharp.CPlusPlus.Size(4, 4));
//Console.WriteLine(small.ElemSize());
//Console.WriteLine(vBmp.ElemSize());
//return;
var print = new ScreenPrint(ColorCut(ToByteArray(small)));
var index = printIndex.FindValue(print);
if (index == null)
{
index = (printIndex.Count > 0 ? printIndex.Values.Max() : 0) + 1;
printIndex[print] = index.Value;
}
Console.WriteLine(index);
GC.Collect();
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
}
}
}
示例2: Main
public static void Main(string[] args)
{
Mat src = new Mat("TestImages/2013-12-27-09G37_TRB.jpg", LoadMode.Color);
src = src.Resize (new Size (420, 625));
Mat srcGrey = src.CvtColor(ColorConversion.BgrToGray);
Mat dst = new Mat ();
Point[][] contours;
Mat invertColour = new Mat (src.Rows, src.Cols, src.Type(), new Scalar(255, 255, 255) );
HiearchyIndex[] hierarchy;
Mat contoursLines = new Mat(src.Rows, src.Cols, src.Type());
// InputArray element = Cv2.GetStructuringElement (StructuringElementShape.Ellipse, new Size (16, 16));
// Mat thresh = srcGrey.Threshold (230, 255, ThresholdType.Binary).Dilate(element);
Mat thresh = srcGrey.Threshold (230, 255, ThresholdType.Binary);
Cv2.FindContours (thresh, out contours, out hierarchy, ContourRetrieval.Tree, ContourChain.ApproxSimple);
// Find center of mass in contour
Moments center = Cv2.Moments (contours [0]);
// Convert moment matrix to X/Y coords
int x = (int) (center.M10 / center.M00);
int y = (int) (center.M01 / center.M00);
src.Circle (new Point (x, y), 5, CvColor.CornflowerBlue, 2);
src.DrawContours (contours, 1, CvColor.Green, 2);
bool intersect = IsIntersecting (selector[0], selector[1], contours[1][0], contours[1][1]);
using (var orig = new Window ("src image", src))
{
orig.OnMouseCallback += new CvMouseCallback(MouseMove);
Cv2.WaitKey();
}
}
示例3: MakeImagesForArticle
private static void MakeImagesForArticle()
{
var resizeK = 0.2;
var dir = "Example/";
var src = new Mat("0.bmp");
var src_g = new Mat("0.bmp", LoadMode.GrayScale);
var src_1 = new Mat("1.bmp");
var src_1_g = new Mat("1.bmp", LoadMode.GrayScale);
var background = new Mat("background.bmp");
var background_g = new Mat("background.bmp", LoadMode.GrayScale);
src.Resize(resizeK).ImWrite(dir + "0.png");
src_g.Resize(resizeK).ImWrite(dir + "0 g.png");
src_g.ThresholdStairs().Resize(resizeK).ImWrite(dir + "0 g th.png");
var canny = new Mat();
Cv2.Canny(src_g, canny, 50, 200);
canny.Resize(0.5).ImWrite(dir + "0 canny.png");
Mat[] src_channels;
Cv2.Split(src, out src_channels);
for (var i = 0; i < src_channels.Length; ++i)
{
var channels = Enumerable.Range(0, src_channels.Length).Select(j => new Mat(src_channels[0].Rows, src_channels[0].Cols, src_channels[0].Type())).ToArray();
channels[i] = src_channels[i];
var dst = new Mat();
Cv2.Merge(channels, dst);
dst.Resize(resizeK).ImWrite(dir + string.Format("0 ch{0}.png", i));
src_channels[i].ThresholdStairs().Resize(resizeK).ImWrite(dir + string.Format("0 ch{0} th.png", i));
}
if (true)
{
src.Resize(0.4).ImWrite(dir + "0.png");
src_1.Resize(0.4).ImWrite(dir + "1.png");
background.Resize(0.4).ImWrite(dir + "bg.png");
var dst_01 = new Mat();
Cv2.Absdiff(src, src_1, dst_01);
dst_01.Resize(resizeK).ImWrite(dir + "01.png");
dst_01.Cut(new Rect(50, src.Height * 4 / 5 - 50, src.Width / 5, src.Height / 5)).ImWrite(dir + "01 part.png");
dst_01.Cut(new Rect(50, src.Height * 4 / 5 - 50, src.Width / 5, src.Height / 5)).CvtColor(ColorConversion.RgbToGray).ImWrite(dir + "01 g.png");
dst_01.CvtColor(ColorConversion.RgbToGray).ThresholdStairs().Resize(resizeK).ImWrite(dir + "01 g th.png");
var dst_01_g = new Mat();
Cv2.Absdiff(src_g, src_1_g, dst_01_g);
dst_01_g.Cut(new Rect(50, src.Height * 4 / 5 - 50, src.Width / 5, src.Height / 5)).ImWrite(dir + "0g1g.png");
dst_01_g.ThresholdStairs().Resize(resizeK).ImWrite(dir + "0g1g th.png");
}
if (true)
{
var dst_0b = new Mat();
Cv2.Absdiff(src, background, dst_0b);
dst_0b.Resize(0.6).ImWrite(dir + "0b.png");
var dst_0b_g = new Mat();
Cv2.Absdiff(src_g, background_g, dst_0b_g);
dst_0b_g.Resize(0.3).ImWrite(dir + "0b g.png");
dst_0b_g.ThresholdStairs().Resize(0.3).ImWrite(dir + "0b g th.png");
}
if (true)
{
var hsv_src = new Mat();
Cv2.CvtColor(src, hsv_src, ColorConversion.RgbToHsv);
var hsv_background = new Mat();
Cv2.CvtColor(background, hsv_background, ColorConversion.RgbToHsv);
var hsv_background_channels = hsv_background.Split();
var hsv_src_channels = hsv_src.Split();
if (true)
{
var all = new Mat(src.ToIplImage(), true);
for (var i = 0; i < hsv_src_channels.Length; ++i)
{
hsv_src_channels[i].CvtColor(ColorConversion.GrayToRgb).CopyTo(all, new Rect(i * src.Width / 3, src.Height / 2, src.Width / 3, src.Height / 2));
}
src_g.CvtColor(ColorConversion.GrayToRgb).CopyTo(all, new Rect(src.Width / 2, 0, src.Width / 2, src.Height / 2));
all.Resize(0.3).ImWrite(dir + "all.png");
}
foreach (var pair in new[] { "h", "s", "v" }.Select((channel, index) => new { channel, index }))
{
var diff = new Mat();
Cv2.Absdiff(hsv_src_channels[pair.index], hsv_background_channels[pair.index], diff);
diff.Resize(0.3).With_Title(pair.channel).ImWrite(dir + string.Format("0b {0}.png", pair.channel));
diff.ThresholdStairs().Resize(0.3).ImWrite(dir + string.Format("0b {0} th.png", pair.channel));
hsv_src_channels[pair.index].Resize(resizeK).With_Title(pair.channel).ImWrite(dir + string.Format("0 {0}.png", pair.channel));
foreach (var d in new[] { -100, -50, 50, 100 })
//.........这里部分代码省略.........