public void drawOnImg(ref Emgu.CV.Image <Hsv, byte> img) { foreach (LineSegment2D segment in lineSegments) { img.Draw(segment, new Hsv((int)type, 240, 240), 2); } if (previousPosition != null)//klappt nicht hat immer nen wert { img.Draw(new LineSegment2D(previousPosition, pos), new Hsv((int)type, 255, 255), 2); } }
/// <summary> /// Process rocks in the image. /// </summary> private void ProcessSand() { // TODO: Make image be saved in MyDocs/Pictures. if (this.inputImage == null) { return; } Thread workerThread = new Thread(() => { /* * string path = @"C:\Users\POLYGONTeam\Documents\GitHub\Androbot\Androbot\Androbot\bin\Debug\Images\2D_20160728170358.PNG"; */ //Emgu.CV.Image<Bgr, byte> inpImg = new Emgu.CV.Image<Bgr, byte>(this.inputImage); Emgu.CV.Image <Bgr, byte> inpImg = new Emgu.CV.Image <Bgr, byte>(inputImage); Emgu.CV.Image <Gray, byte> water = inpImg.InRange(new Bgr(0, 100, 0), new Bgr(255, 255, 255)); //TODO: To check does we need mask? //water = water.Add(mask); //water._Dilate(1); // Create the blobs. Emgu.CV.Cvb.CvBlobs blobs = new Emgu.CV.Cvb.CvBlobs(); // Create blob detector. Emgu.CV.Cvb.CvBlobDetector dtk = new Emgu.CV.Cvb.CvBlobDetector(); // Detect blobs. uint state = dtk.Detect(water, blobs); foreach (Emgu.CV.Cvb.CvBlob blob in blobs.Values) { //Console.WriteLine("Center: X:{0:F3} Y:{1:F3}", blob.Centroid.X, blob.Centroid.Y); //Console.WriteLine("{0}", blob.Area); if (blob.Area >= 4500 && blob.Area < 34465) { //Console.WriteLine("{0}", blob.Area); inpImg.Draw(new CircleF(blob.Centroid, 5), new Bgr(Color.Red), 2); inpImg.Draw(blob.BoundingBox, new Bgr(Color.Blue), 2); } } if (this.outputImage != null) { this.outputImage.Dispose(); } // Dump the image. this.outputImage = inpImg.ToBitmap(); // Show the nwe mage. this.pbMain.Image = this.FitImage(this.outputImage, this.pbMain.Size); }); workerThread.Start(); }
private void button4_Click(object sender, EventArgs e) { Emgu.CV.Image <Hsv, byte> outImg = (Emgu.CV.Image <Hsv, byte>)im2.Image; foreach (ShapeColorObject shp in trackedshapes) { shp.drawOnImg(ref outImg); } foreach (ShapeColorObject s in trackedshapes) { outImg.Draw(s.getLabel(), ref font, s.pos, new Hsv(0, 255, 255)); outImg.Draw(new Cross2DF(new PointF((float)s.pos.X, (float)s.pos.Y), (float)5.0, (float)5.0), new Hsv(0, 200, 200), 2); } im2.Image = outImg; im2.Update(); }
public Bitmap Findcircles(double cannyThreshold, double circleAccumulatorThreshold) { Bitmap bmp; CircleF[] circles = CvInvoke.HoughCircles(imgEdgesROI, HoughType.Gradient, 1.0, 5, cannyThreshold, circleAccumulatorThreshold); Emgu.CV.Image <Bgr, byte> imgWithCircles = img.Convert <Bgr, byte>(); foreach (CircleF circle in circles) { imgWithCircles.Draw(circle, new Bgr(0, 0, 255), 1, LineType.EightConnected); } bmp = imgWithCircles.Bitmap; return(bmp); }
public Bitmap SetEdgesCirlceROI(int X, int Y, double radius) { Bitmap bmp = new Bitmap(1280, 1024); Emgu.CV.Image <Gray, byte> imgRoi = new Emgu.CV.Image <Gray, byte>(bmp); imgRoi.SetZero(); Emgu.CV.Image <Gray, byte> imgCircleFilter = new Emgu.CV.Image <Gray, byte>(1280, 1024); imgCircleFilter.SetZero(); PointF centerPoint = new PointF((float)X, (float)Y); SizeF size = new SizeF((float)(radius * 2.0), (float)(radius * 2.0)); Ellipse circle = new Ellipse(centerPoint, size, 0.0f); imgCircleFilter.Draw(circle, new Gray(255), -1, LineType.EightConnected); imgEdgesROI = imgEdges.And(imgCircleFilter); imgRoi = imgEdgesROI; return(imgRoi.Bitmap); }
static void Main() { // download sample photo WebClient client = new WebClient(); Bitmap image = null; using (MemoryStream ms = new MemoryStream(client.DownloadData(SAMPLE_IMAGE))) image = new Bitmap(Image.FromStream(ms)); // convert to Emgu image, convert to grayscale and increase brightness/contrast Emgu.CV.Image <Bgr, byte> emguImage = new Emgu.CV.Image <Bgr, byte>(image); var grayScaleImage = emguImage.Convert <Gray, byte>(); grayScaleImage._EqualizeHist(); // load eye classifier data string eye_classifier_local_xml = @"c:\temp\haarcascade_eye.xml"; client.DownloadFile(@EYE_DETECTION_XML, eye_classifier_local_xml); CascadeClassifier eyeClassifier = new CascadeClassifier(eye_classifier_local_xml); // perform detection which will return rectangles of eye positions var eyes = eyeClassifier.DetectMultiScale(grayScaleImage, 1.1, 4); // draw those rectangles on original image foreach (Rectangle eye in eyes) { emguImage.Draw(eye, new Bgr(255, 0, 0), 3); } // save image and show it string output_image_location = @"c:\temp\output.png"; emguImage.ToBitmap().Save(output_image_location, ImageFormat.Png); Process.Start(output_image_location); }
public Bitmap FindEllipseArc() { Bitmap bmp; Emgu.CV.Util.VectorOfVectorOfPoint contour = new Emgu.CV.Util.VectorOfVectorOfPoint(); Emgu.CV.Util.VectorOfPoint arcOfEllipse = new Emgu.CV.Util.VectorOfPoint(); List <Point> ptsOfArc = new List <Point>(); //List<Emgu.CV.Util.VectorOfPoint> listOfArcOfEllipse = new List<Emgu.CV.Util.VectorOfPoint>(); // Find of contours of ellipse CvInvoke.FindContours(imgEdgesROI, contour, null, RetrType.List, ChainApproxMethod.ChainApproxNone); for (int i = 0; i < contour.Size; i++) { if (contour[i].Size > 50) { int length; arcOfEllipse.Push(contour[i]); //listOfArcOfEllipse.Add(contour[i]); length = contour[i].Size; //System.Windows.Forms.MessageBox.Show("Size:" + contour[i].Size.ToString()); /* * for (int j = 0; j < contour[i].Size; j++) * { * Console.WriteLine(contour[i][j].X.ToString() + "\t" + contour[i][j].Y.ToString()); * } * * Console.WriteLine("--------------------------------"); */ } } //System.Windows.Forms.MessageBox.Show(endPtsOfArc.Count.ToString()); rRect = CvInvoke.FitEllipse(arcOfEllipse); // Transfer the point vector(EMGU) to List(System) and get sorted for (int i = 0; i < arcOfEllipse.Size; i++) { ptsOfArc.Add(arcOfEllipse[i]); } ptsOfArc.Sort(SortRadianCompare); /* * for (int i = 0; i < ptsOfArc.Count; i++) * { * Console.WriteLine(ptsOfArc[i].X.ToString() + "\t" + ptsOfArc[i].Y.ToString()); * } */ Point beginPoint = new Point(); Point endPoint = new Point(); double maxRadian = 0.0; // Find the gap for (int i = 0; i < ptsOfArc.Count - 1; i++) { double deltaY1 = (double)(ptsOfArc[i + 1].Y - rRect.Center.Y); double deltaX1 = (double)(ptsOfArc[i + 1].X - rRect.Center.X); double deltaY2 = (double)(ptsOfArc[i].Y - rRect.Center.Y); double deltaX2 = (double)(ptsOfArc[i].X - rRect.Center.X); if (System.Math.Atan2(deltaY1, deltaX1) - System.Math.Atan2(deltaY2, deltaX2) > maxRadian) { maxRadian = System.Math.Atan2(deltaY1, deltaX1) - System.Math.Atan2(deltaY2, deltaX2); beginPoint = ptsOfArc[i]; endPoint = ptsOfArc[i + 1]; } } Emgu.CV.Image <Bgr, byte> imgWithRect = img.Convert <Bgr, byte>(); /* * List<Point>[] pointslistOfElliSegment = new List<Point>[listOfArcOfEllipse.Count]; * * // Transfer the point vector(EMGU) to List(System) and get sorted * for(int i = 0; i < listOfArcOfEllipse.Count; i ++) * { * for(int j = 0; j < listOfArcOfEllipse[i].Size; j++) * { * pointslistOfElliSegment[i].Add(listOfArcOfEllipse[i][j]); * } * * pointslistOfElliSegment[i].Sort(SortRadianCompare); * } */ Point gapCenter = new Point((beginPoint.X + endPoint.X) / 2, (beginPoint.Y + endPoint.Y) / 2); Point rectCenter = new Point((int)rRect.Center.X, (int)rRect.Center.Y); imgWithRect.Draw(new Ellipse(rRect), new Bgr(0, 0, 255), 2, LineType.EightConnected); imgWithRect.Draw(new LineSegment2D(gapCenter, rectCenter), new Bgr(0, 0, 255), 2, LineType.EightConnected); bmp = imgWithRect.Bitmap; return(bmp); }
private async void button1_Click(object sender, EventArgs e) { await Task.Run(() => { while (true) { string imagePath = @"C:\\xampp\\htdocs\\frs2018\\db\\floor\\floor14.jpg"; Image imag = Image.FromFile(imagePath); System.IO.FileInfo file = new System.IO.FileInfo(imagePath); Bitmap img = new Bitmap(imagePath); pictureBox1.Invoke(new Action(() => pictureBox1.Image = img)); pictureBox1.Invoke(new Action(() => pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage)); Image <Bgr, Byte> CapturedImage = new Emgu.CV.Image <Bgr, byte>(imagePath); Rectangle rec = new Rectangle(15, 650, 10, 10); CapturedImage.Draw(rec, new Bgr(Color.Red), 2);//accepts byte array CvInvoke.Resize(CapturedImage, CapturedImage, new Size(pictureBox1.Width, pictureBox1.Height), 0, 0, Emgu.CV.CvEnum.Inter.Linear); pictureBox1.Invoke(new Action(() => pictureBox1.Image = CapturedImage.Bitmap)); //Rectangle rect=new Rectangle (150,650,6,6); ////Rectangle rect2 = new Rectangle(100, 100, 5, 5); //using (Graphics gfx = Graphics.FromImage(this.pictureBox1.Image)) //{ // gfx.DrawEllipse(Pens.Blue, rect); // this.pictureBox1.Refresh(); //} //SQL Connection try { string connectionString = "datasource=127.0.0.1;port=3306;username=root;password=;database=frs_school;SslMode = none;"; MySqlConnection mcon = new MySqlConnection(connectionString); mcon.Open(); MySqlDataAdapter MyDA = new MySqlDataAdapter(); string sqlSelectAll = "SELECT bleuid,ble_location from frs_blelocation"; MyDA.SelectCommand = new MySqlCommand(sqlSelectAll, mcon); DataTable table = new DataTable(); MyDA.Fill(table); BindingSource bSource = new BindingSource(); bSource.DataSource = table; for (int i = 0; i < table.Rows.Count; i++) { string b_location = table.Rows[i]["ble_location"].ToString(); Console.Write(table.Rows[i]["ble_location"]); string[] splitString = b_location.Split('(', ',', ')'); //separates into 0,1,2 Console.WriteLine("BLE X-Value: " + splitString[1]); //gives the x values Console.WriteLine("BLE y-Value: " + splitString[2]); //gives the y values int x = Convert.ToInt32(splitString[1]); int y = Convert.ToInt32(splitString[2]); Rectangle newrect = new Rectangle(x, y, 6, 6); //Rectangle rect2 = new Rectangle(100, 100, 5, 5); using (Graphics gfx = Graphics.FromImage(pictureBox1.Image))//shows error--> object is used somewhere else { gfx.DrawEllipse(Pens.Blue, newrect); } } pictureBox1.Invoke(new Action(() => pictureBox1.Refresh())); mcon.Close(); } catch (Exception) { //MessageBox.Show(ex.ToString()); } } }); }
public void findChips() { try { //CudaImage<Bgr,Byte> gpuImg = new CudaImage<Bgr,Byte>(sourceImage); //VectorOfGpuMat outVec = new VectorOfGpuMat(); //CudaGaussianFilter gaussFilter = new CudaGaussianFilter(DepthType.new Size(11,11),0.8,0.8,BorderType.Constant,BorderType.Constant); //gaussFilter.Apply(gpuImg, gpuImg, null); diagnosticImage = sourceImage.Clone(); Rectangle[] rects = cc.DetectMultiScale(sourceImage.Convert <Gray, Byte>(), 1.1, 4, new System.Drawing.Size(10, 10)); //cc.ScaleFactor = 1.1; //cc.MinNeighbors = 4; //cc.MinObjectSize = new Size(10, 10); //cc.DetectMultiScale(gpuImg.Convert<Gray, Byte>(), outVec); //Rectangle[] rects = cc.Convert(outVec); foreach (Rectangle rect in rects) { StackRegistry.stackFound(rect); } List <Stack> processedStacks = StackRegistry.processFrame(sourceImage); if (foundChipColor != null) { if (processedStacks.Count == 1) { ColorFinder.trainChip(sourceImage, processedStacks[0].samplePoints, (Stack.Color)foundChipColor); } } foreach (Stack stack in processedStacks) { Bgr col = new Bgr(Color.Magenta); switch (stack.color) { case Stack.Color.Black: col = new Bgr(Color.Black); break; case Stack.Color.Blue: col = new Bgr(Color.Blue); break; case Stack.Color.Red: col = new Bgr(Color.Red); break; case Stack.Color.Green: col = new Bgr(Color.Green); break; case Stack.Color.White: col = new Bgr(Color.White); break; } diagnosticImage.Draw(stack.location, col, 2); foreach (Point sample in stack.samplePoints) { diagnosticImage.Draw(new Rectangle(sample, new Size(1, 1)), new Bgr(System.Drawing.Color.Yellow), 2); } } } catch (Exception ex) { MessageBox.Show(ex.StackTrace.ToString()); } }
/// <summary> /// Find the chessboard corners /// </summary> /// <param name="InputImage">Input image commpping from video camera.</param> /// <param name="OutputImage">Output image comming from image processor.</param> public BoardConfiguration FindBoard(Bitmap InputImage, out Bitmap OutputImage) { #region Local variables // Figure Center Point figureCenter; // Figure BGR color Color figureColor; // Figure index int figureIndex; // Vector image of figure CircleF circleFigure; // Board configuration BoardConfiguration currentConfiguration = new BoardConfiguration(); // Image ! Image <Bgr, Byte> WorkingImage; #endregion // Create working image. WorkingImage = new Image <Bgr, Byte>(InputImage); // Equlize the image. WorkingImage = this.Equalize(WorkingImage, this.SC.ImageLightnes); // Convert the image back to BGR range Emgu.CV.Image <Bgr, Byte> DrawingImage = WorkingImage; // Create the font. MCvFont TextFont = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0); try { // Get bord marker points, MarkersList = this.GetBoardMarkers(new Image <Hls, Byte>(InputImage)[1].Convert <Gray, Byte>().ToBitmap(), this.SC); // If repers are 4 the proseed to describe the board. if (MarkersList.Length == MARKERS_COUNT) { // Draw the points foreach (PointF markerPoint in MarkersList) { // Create figure to draw. circleFigure = new CircleF(markerPoint, 5.0f); // Draw circle DrawingImage.Draw(circleFigure, new Bgr(Color.Orange), 10); } // Show the image //CvInvoke.cvShowImage("Test", DrawingImage); #region Get perspective flat image. // Get perspective flat image. Image <Bgr, Byte> flatImage = this.GetPerspectiveFlatImage(WorkingImage, BoardSize, MarkersList); #endregion for (int indexFigure = 0; indexFigure < 24; indexFigure++) { // Set the figure center figureCenter = this.FigurePosition(indexFigure); // figureColor = this.GetFigureColor(flatImage, this.GetBoundingBox(figureCenter)); // Tell that there is no figure figureIndex = 0; // If the luminosity is greater then 0.5. if (figureColor.GetSaturation() > this.SaturationTreshFigureLevel) { // Find the playr figureIndex = FigureColorDefinitions.WhoIsThePlayer(figureColor); } // Fill the board configuration currentConfiguration.Figure[indexFigure] = figureIndex; #region Draw if (figureIndex != 0) { // Create figure to draw. //circleFigure = new CircleF(figureCenter, 10.0f); // Draw circle //newImage.Draw(circleFigure, bgrInFigureColor, 5); // Write text // #region Draw label to the processed image. flatImage.Draw(String.Format("{0}", FigureColorDefinitions.WhoIsThePlayer(figureColor)), ref TextFont, figureCenter, new Bgr(Color.DarkOrange)); //drawingImage.Draw(vectorWithSmallestY, RedColor, 2); #endregion } #endregion } // Show unperspective image //CvInvoke.cvShowImage("Perspective", flatImage); DrawingImage = flatImage; } } catch (Exception exception) { Console.WriteLine("Exception: {0}", exception.Message); Loging.Log.CreateRecord("VisionSystm.Board.FindBoard", String.Format("Exception: {0}", exception.Message), Loging.LogMessageTypes.Error); } // Apply the output image. DrawingImage.ROI = new Rectangle(new Point(0, 0), new Size(400, 400)); OutputImage = DrawingImage.ToBitmap(); return(currentConfiguration); }