title: How to detect lines using HoughLines in OpenCV (Java)?
body: <p>I'm currently trying to detect whether a level crossing barrier has been deployed on an image using <code>HoughLines</code> in <code>OpenCV</code>. I thought my code would draw a line on my image, so long as the barrier appears in it - but instead I get an error message saying "Mat data type is not compatible". Can show me how to detect lines in Java with OpenCV?</p>
  
  <pre><code>public class DetectLines {
  
  public static void main(String args[]) {
  
      System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  
      Mat eventless = Highgui.imread("files/eventless.png");
      Mat barrier = Highgui.imread("files/barrier/lc-00201.png");
      Mat difference = new Mat();
      Mat lines = new Mat();
  
      Core.absdiff(eventless, barrier, difference);
  
      Mat grey = new Mat();
      Imgproc.cvtColor(difference, grey, Imgproc.COLOR_BGR2GRAY);
  
      Imgproc.HoughLines(grey, lines, 5.0, 4.0, 7);
  
      Imshow ims1 = new Imshow("Lines");
      ims1.showImage(lines);
  
  }
  
  }
  </code></pre>