0

I am quite a noob when it comes to image processing. I choosed OpenCV to make my first steps. I was searching for a WYSIWYG editor to play around with the features OpenCV offers but I couldn't find.

My current problem is to detect the horizontal and vertical black lines in this picture going from most left to most right and from most top to most bottom:

Picture

I found out I can use HoughLinesP for this but the only parameter I am sure it is correct is the the minLineLength of the line. Actually it doesn't find any lines. I am reading the image as a grayscaled image but I am not sure if I need to make use of Canny before applying it to HoughLinesP.

Thanks for help.

Here is some C# code:

        var image = CvInvoke.Imread(filePath, Emgu.CV.CvEnum.ImreadModes.Grayscale);
        var lines = CvInvoke.HoughLinesP(image, 1, 1, 0, image.Height);

As @Micka mentioned I should invert the image and I tried further steps to make it even simpler I started with a simple cross picture:

9x9 cross

        var image = CvInvoke.Imread("cross.png", Emgu.CV.CvEnum.ImreadModes.Grayscale);
        CvInvoke.BitwiseNot(image, image);
        var lines = CvInvoke.HoughLinesP(image, rho: 1, theta: 1, 0, image.Height - 1);

But it detects only one line of length 8 but it should be 9 pixels long.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
BlackMatrix
  • 474
  • 5
  • 19
  • In every row, ignore first and last pixel, if every other pixel is black, there is a black line. – Micka Jun 01 '22 at 16:02
  • If you want to use houghlines, invert the image, so that the black lines become white instead. White is the "foreground" in most algorithms that assume active and inactive pixels. – Micka Jun 01 '22 at 16:03
  • Thanks for you help. I simplified it even more. I just tried to use a simple 9x9 cross to detect the lines but I don't get the result I thought I would get. 2 lines (1 horizonal, 1 vertical, both are of 9 pixels length) – BlackMatrix Jun 01 '22 at 16:36
  • 4
    This problem doesn't need Hough or anything else complicated. Add all pixel values along rows. Some rows will add to 0. These are the black lines. Repeat with columns. Done. – Cris Luengo Jun 01 '22 at 20:14
  • 1
    Similar approach to this... look at the green arrows https://stackoverflow.com/a/63174271/2836621 – Mark Setchell Jun 01 '22 at 21:26

0 Answers0