I have a images like below

Here there is a line. This line is not straight everywhere. In the middle part of the line there is a curve. My work is to calculate that how much the line is straight or how much the line is curved ??? How can i do that using C# . I searched everywhere but cant get any idea how to do that. Have anyone any idea how to do that?? My aim is not only to detect a line but also to calculate how much curve the line is??
This is just a sample using the EmguCV wrapper over OpenCV image processing library detecting the lines. Of course this is not 100% accurate, you will have to tweak a little more. When you get the lines you may calculate the curve.
Or another way is to implement your own algorithm to detect the lines.
Using this algorithm I got 16 lines from the provided image. With some tweak you can get more accurate number.
var bmp = new Bitmap(pathToImage);
//Load the image from file and resize it for display
using (Image<Bgr, Byte> img = new Image<Bgr, byte>(bmp))
{
//Convert the image to grayscale and filter out the noise
using (Image<Gray, Byte> gray = img.Convert<Gray, Byte>().PyrDown().PyrUp())
{
Gray cannyThreshold = new Gray(180);
#region Canny and edge detection
Gray cannyThresholdLinking = new Gray(120);
Image<Gray, Byte> cannyEdges = gray.Canny(cannyThreshold, cannyThresholdLinking);
LineSegment2D[] lines = cannyEdges.HoughLinesBinary(
1, //Distance resolution in pixel-related units
Math.PI/60.0, //Angle resolution measured in radians.
20, //threshold
30, //min Line width
10 //gap between lines
)[0]; //Get the lines from the first channel
#endregion
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With