Опитвам се да напиша приложение, което открива монети в изображението. Намерих част от кода, който използва HoughCircles на Emgu CV. Не мога обаче да задам параметрите така, че да връщам всяка монета (кръгчета). Имате ли опит с този проблем? Благодаря за съвета.
Това е код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
namespace INZO_Sem_Pr3_ST28605
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Bitmap bitmap = new Bitmap(pictureBox1.Image);
//Load the image from file
Image<Bgr, Byte> img = new Image<Bgr, byte>(bitmap);
//Get and sharpen gray image (don't remember where I found this code; prob here on SO)
Image<Gray, Byte> graySoft = img.Convert<Gray, Byte>().PyrDown().PyrUp();
Image<Gray, Byte> gray = graySoft.SmoothGaussian(3);
gray = gray.AddWeighted(graySoft, 1.5, -0.5, 0);
Image<Gray, Byte> bin = gray.ThresholdBinary(new Gray(70), new Gray(255));
Gray cannyThreshold = new Gray(200);
Gray cannyThresholdLinking = new Gray(100);
Gray circleAccumulatorThreshold = new Gray(1000);
Image<Gray, Byte> cannyEdges = bin.Canny(cannyThreshold.Intensity, cannyThresholdLinking.Intensity);
pictureBox1.Image = cannyEdges.ToBitmap();
//Circles
CircleF[] circles = cannyEdges.HoughCircles(
cannyThreshold,
circleAccumulatorThreshold,
1.0, //Resolution of the accumulator used to detect centers of the circles
cannyEdges.Height / 8, //min distance
0, //min radius
2000 //max radius
)[0]; //Get the circles from the first channel
//draw circles (on original image)
foreach (CircleF circle in circles)
img.Draw(circle, new Bgr(Color.Brown), 2);
}
}
}
Прочетох повече обяснения какво означават тези аргументи, но не мога да задам добри стойности. Това е резултат след откриване на край на употреба: