Hello,
here i am working on C# WinForms desktop application where i have to do some image processing on the images. there is the lines between an object that showing in the image.
here i am adding some reference images in links.
image1
image2
image3
image4
image5
image6
What I have tried:
i am doing some image processing using EmguCV library for C#. i have not getting the output i want and it supposed to be.
here are some images of output i am getting.
see all the output images. there are in many images are not detecting the lines on the object and some images are get line but half. i want to detect whole black line on the object are. if there's black line of 40px then the draw line at least 90% on the detected black line.
output1
output2
output3
output4
output5
the code i have tried is given below.
if (img_path != null)
{
try
{
Image<Bgr, byte> imgInput = new Image<Bgr, byte>(img_path);
Image<Gray, byte> gray = imgInput.Convert<Gray, byte>();
gray = gray.ThresholdBinary(new Gray(100), new Gray(255));
Image<Gray, byte> edges = gray.Canny(100, 50);
VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
Mat hierarchy = new Mat();
CvInvoke.FindContours(edges, contours, hierarchy, RetrType.List, ChainApproxMethod.ChainApproxSimple);
List<VectorOfPoint> filteredContours = new List<VectorOfPoint>();
for (int i = 0; i < contours.Size; i++)
{
VectorOfPoint contour = contours[i];
double area = CvInvoke.ContourArea(contour);
if (area > 500 && area < 10000)
{
filteredContours.Add(contour);
}
}
LineSegment2D[] lines = CvInvoke.HoughLinesP(
edges,
1,
Math.PI / 180,
100,
3,
10
);
foreach (LineSegment2D line in lines)
{
imgInput.Draw(line, new Bgr(Color.Red), 2);
}
pictureBox2.Image = imgInput.ToBitmap();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}