public static Emgu.CV.Image <Bgr, Byte> RemovePictures(string path, List <CropperViewModel> CropperList) { var image1 = new Emgu.CV.Image <Bgr, Byte>(path); var newImage = image1.Copy(); if (CropperList != null) { foreach (var cropper in CropperList) { //setPixelsWhite(ref image1, cropper); for (int v = cropper.Y; v < cropper.Height + cropper.Y; v++) { for (int u = cropper.X; u < cropper.Width + cropper.X; u++) { newImage.Data[v, u, 0] = 0; //Set Pixel Color | fast way newImage.Data[v, u, 1] = 0; //Set Pixel Color | fast way newImage.Data[v, u, 2] = 0; //Set Pixel Color | fast way } } } return(newImage); } else { return(image1); } }
private unsafe void ReaderThread() { IRMetaData irMD = new IRMetaData(); while (this.shouldRun) { try { this.context.WaitOneUpdateAll(this.ir); } catch (Exception) { } this.ir.GetMetaData(irMD); MapData <ushort> irMap = this.ir.GetIRMap(); if (isRoiSet == false) { defaultWidth = irMap.XRes; defaultHeight = irMap.YRes; } int w = irMap.XRes; int h = irMap.YRes; lock (this) { int stride = w * 2; if (stride % 2 != 0) { stride += (2 - (stride % 2)); } if (roi.Size.Width != 0) { Emgu.CV.Image <Gray, UInt16> tmp = new Emgu.CV.Image <Gray, UInt16>(irMap.XRes, irMap.YRes, stride, ir.GetIRMapPtr()); tmp.ROI = new Rectangle(roi.X, roi.Y, roi.Width, roi.Height); grayImage = tmp.Copy(); } else { grayImage = new Emgu.CV.Image <Gray, UInt16>(w, h, stride, ir.GetIRMapPtr()); } } if (FrameCaptureComplete != null) { FrameCaptureComplete(); } } }
public static Emgu.CV.Image <Rgb, byte> DrawGrid(Emgu.CV.Image <Rgb, byte> source) { Image <Rgb, byte> imageToShow = source.Copy(); for (int i = 0; i < source.Width; i += 32) { for (int j = 0; j < source.Height; j += 32) { Rectangle match = new Rectangle(i, j, 32, 32); imageToShow.Draw(match, new Rgb(Color.White), 1); } } return(imageToShow); }
public static Texture2D ToTex(this Emgu.CV.Image <Bgr, Byte> img, GraphicsDevice gd) { img = img.Copy(); int w = img.Width; int h = img.Height; Texture2D tex = new Texture2D(gd, w, h); //byte[] rgba = new byte[w * h * 4]; //int i = 0; //for (int y = 0; y < h; y++) // for (int x = 0; x < w; x++) // { // rgba[i++] = img.Data[y, x, 2]; // rgba[i++] = img.Data[y, x, 1]; // rgba[i++] = img.Data[y, x, 0]; // rgba[i++] = 255; // } //tex.SetData<byte>(rgba); byte[] rgba = new byte[w * h * 4]; int i = 0; var bytes = img.Bytes; for (int k = 0; k < bytes.Length; k += 3) { rgba[i++] = bytes[k + 2]; rgba[i++] = bytes[k + 1]; rgba[i++] = bytes[k + 0]; rgba[i++] = 255; } tex.SetData <byte>(rgba); return(tex); }
public static Emgu.CV.Image <Rgb, byte> MatchBestTemplate(Emgu.CV.Image <Rgb, byte> source, Emgu.CV.Image <Rgb, byte> template, Color matchHighlight) { Image <Rgb, byte> imageToShow = source.Copy(); using (Image <Gray, float> result = source.MatchTemplate(template, Emgu.CV.CvEnum.TemplateMatchingType.CcoeffNormed)) { double[] minValues, maxValues; Point[] minLocations, maxLocations; result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations); if (maxValues[0] > 0.4) { // This is a match. Do something with it, for example draw a rectangle around it. Rectangle match = new Rectangle(maxLocations[0], template.Size); imageToShow.Draw(match, new Rgb(matchHighlight), 3); } } // Show imageToShow in an ImageBox (here assumed to be called imageBox1) return(imageToShow); }
public static Emgu.CV.Image <Rgb, byte> MatchAllTemplate(Emgu.CV.Image <Rgb, byte> source, Emgu.CV.Image <Rgb, byte> template, Color matchHighlight) { Image <Rgb, byte> imageToShow = source.Copy(); using (Image <Gray, float> result = source.MatchTemplate(template, Emgu.CV.CvEnum.TemplateMatchingType.CcoeffNormed)) { for (int i = 0; i < result.Height; i++) { for (int j = 0; j < result.Width; j++) { var a = result.Data.GetValue(i, j, 0); if ((float)a > 0.4) { // This is a match. Do something with it, for example draw a rectangle around it. Rectangle match = new Rectangle(new Point(j, i), template.Size); imageToShow.Draw(match, new Rgb(matchHighlight), 3); } } } } // Show imageToShow in an ImageBox (here assumed to be called imageBox1) return(imageToShow); }
private unsafe void ReaderThread() { IRMetaData irMD = new IRMetaData(); while (this.shouldRun) { try { this.context.WaitOneUpdateAll(this.ir); } catch (Exception) { } this.ir.GetMetaData(irMD); MapData<ushort> irMap = this.ir.GetIRMap(); if(isRoiSet == false) { defaultWidth = irMap.XRes; defaultHeight = irMap.YRes; } int w = irMap.XRes; int h = irMap.YRes; lock (this) { int stride = w*2; if (stride%2 != 0) stride += (2 - (stride%2)); if(roi.Size.Width != 0) { Emgu.CV.Image<Gray, UInt16> tmp = new Emgu.CV.Image<Gray, UInt16>(irMap.XRes, irMap.YRes, stride, ir.GetIRMapPtr()); tmp.ROI = new Rectangle(roi.X, roi.Y, roi.Width, roi.Height); grayImage = tmp.Copy(); } else { grayImage = new Emgu.CV.Image<Gray, UInt16>(w, h, stride, ir.GetIRMapPtr()); } } if (FrameCaptureComplete != null) FrameCaptureComplete(); } }
private void processImageFile(Emgu.CV.Image <Bgr, Byte> framepic) { using (var alpr = new AlprNet("eu", config_file, runtime_data_dir)) { if (!alpr.IsLoaded()) { txtPlaka.Text = "Yüklenirken hata oldu.Tekrar deneyin"; return; } Image <Bgr, byte> resultx = null; resultx = framepic.Copy(); var results = alpr.Recognize(framepic.Bitmap); bool bulundu = false; var images = new List <Image>(results.Plates.Count()); foreach (var result in results.Plates) { var rect = boundingRectangle(result.PlatePoints); Image <Bgr, Byte> img = framepic; Image <Bgr, Byte> cropped = cropImage(img.Bitmap, rect); images.Add(cropped.Bitmap); //Plakanın etrafına kırmızı dikdörtgen çiziyor Point p = new Point(result.PlatePoints[0].X - 4, result.PlatePoints[0].Y - 25); p.Offset(0, cropped.Size.Height); resultx.Draw(new Rectangle(p, cropped.Size), new Bgr(12, 12, 214), 3); resultx.ROI = new Rectangle(p, cropped.Size); // picOriginResim.Image = resultx; //if içinden aldım try { cropped.CopyTo(resultx); } catch (Exception e) { continue; } resultx.ROI = Rectangle.Empty; String t = GetMatchedPlate(result.TopNPlates); picOriginResim.Image = resultx; Regex regex = new Regex(@"^(0[0-9]|[1-7][0-9]|8[01])(([A-Z])(\d{4,5})|([A-Z]{2})(\d{3,4})|([A-Z]{3})(\d{2,3}))$"); Match match = regex.Match(t.Replace(" ", "")); if (match.Success) { txtPlaka.Text = t; picOriginResim.Image = resultx; bulundu = true; } } if (images.Any()) { picPlakaResmi.Image = combineImages(images); picOriginResim.Image = resultx; } if (!bulundu) { picOriginResim.Image = framepic; } } }