private static Cloud MakeCloudTest() { using (var dmap = new Image<Gray, byte>(Path.Combine(Global.DatDir, @"Cloud Tests\dmap1.jpg"))) using (var cmap = new Image<Bgr, byte>(Path.Combine(Global.DatDir, @"Cloud Tests\cmap1.jpg")).Convert<Rgba, byte>()) using (var mask = new Image<Gray, byte>(Path.Combine(Global.DatDir, @"Cloud Tests\dmap1.jpg"))) { var w = 100.0f; var h = 100.0f; var z = 5.0f; var pts = new VertexPositionNormalTexture[dmap.Size.Area()]; var masked = mask[0, dmap.Width - 1].Intensity; for (int y = 0; y < dmap.Height; ++y) for (int x = 0; x < dmap.Width; ++x) { var fx = x / w; var fy = (dmap.Height - y) / h; var fz = (float)dmap[y, x].Intensity / 255.0f * z; if (masked != mask[y, x].Intensity) pts[y * dmap.Width + x] = new VertexPositionNormalTexture( new Vector3(fx, fy, fz), Vector3.UnitZ, new Vector2(x / (float)dmap.Width, y / (float)dmap.Height)); } GrayScanTask.CalculateNormals(pts, dmap.Width, dmap.Height); using (var ticture = new Picture<Rgba, byte>(cmap.Width, cmap.Height)) { var texture2D = Program.Renderer.LeaseFor(ticture); cmap.CopyTo(ticture.Emgu); texture2D.SetData(ticture.Bytes); return new Cloud(Color.Pink, dmap.Size) { Points = pts, Texture2D = texture2D }; } } }
void videoCapture_NewFrame(object sender, EventArgs e) { frame = videoCapture.ReadAs<Bgr, byte>(); if (frame == null) return; long preprocessTime, matchTime; var bestRepresentatives = findObjects(frame, out preprocessTime, out matchTime); /************************************ drawing ****************************************/ foreach (var m in bestRepresentatives) { frame.Draw(m.BoundingRect, new Bgr(0, 0, 255), 1); if (m.Template is ImageTemplateWithMask) { var mask = ((ImageTemplateWithMask)m.Template).BinaryMask; if (mask == null) continue; //just draw bounding boxes var area = new Rectangle(m.X, m.Y, mask.Width, mask.Height); if (area.X < 0 || area.Y < 0 || area.Right >= frame.Width || area.Bottom >= frame.Height) continue; //must be fully inside using (var someImage = new Image<Bgr, byte>(mask.Width, mask.Height, Bgr8.Red)) { someImage.CopyTo(frame.GetSubRect(area), mask); } } else { frame.Draw(m, Bgr8.Blue, 3, true, Bgr8.Red); } Console.WriteLine("Best template: " + m.Template.ClassLabel + " score: " + m.Score); } frame.Draw(String.Format("Matching {0} templates in: {1} ms", templPyrs.Count, matchTime), font, new PointF(5, 10), new Bgr(0, 255, 0)); /************************************ drawing ****************************************/ this.pictureBox.Image = frame.ToBitmap(); //it will be just casted (data is shared) 24bpp color //frame.Save(String.Format("C:/probaImages/imgMarked_{0}.jpg", i)); b.Save(String.Format("C:/probaImages/img_{0}.jpg", i)); i++; GC.Collect(); }