我在C#中使用EmguCV 2.4进行图片中椭圆对象的边缘检测和椭圆拟合(例如激光点)。
EmguCV已经实现了使用最小二乘法将椭圆拟合到点云的功能,但是根据它们的角度,椭圆并不适合椭球。
以下是我使用的基本代码:
CHAIN_APPROX_METHOD approxMethod = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE;
RETR_TYPE RetrType = RETR_TYPE.CV_RETR_LIST;
Bitmap Bmp = new Bitmap(@"C:\Users\pernizki\Downloads\binary2.bmp"); // read Bitmap
Image ImgIn = new Image(Bmp); // Convert to Image<>
Image ImgBin = ImgIn.Convert(); // convert Bgr to Gray
ImgBin = ImgBin.ThresholdBinary(new Gray(140), new Gray(120)).PyrDown().PyrUp(); // convert to binary and reduce noise
ImgBin = ImgBin.Canny(100, 120); // detect the edges from binary image
Contour Contour = ImgBin.FindContours(approxMethod, RetrType); // Get Contour from binary Image
int cntr = 0;
PointF[] ContourPts = new PointF[Contour.Total];