Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV HoughLines only ever returning one line

Tags:

java

opencv

I've shifted my OpenCV development from Python to Java, to work with it on an Android device. The first step was to port a fairly straightforward Canny/HoughLines algorithm. With some research, I wound up with:

    Mat lines = inputFrame.gray();

    Mat cny=new Mat();

    Imgproc.Canny(lines,cny,100,150);

    Mat lns = new Mat();

    Imgproc.HoughLinesP(cny, lns, 1, Math.PI/180, 50, 20, 20);
    Log.w("MainActivity",String.valueOf(lns.cols()));


    return cny;

The problem with this code is that it always prints '1' or '0' lines. From the same angle as my Python code, which returned 100s of lines with the same threshold and other values, this code returns one.

I've tried tuning all of the parameters, with no luck. The returned Mat from Canny shows reasonable edges, but HoughLines (both standard, and probabilistic) will always return only one line.

What am I missing?

like image 779
magmastonealex Avatar asked Apr 26 '15 00:04

magmastonealex


1 Answers

The rows and columns are different in the Java wrapper. Instead of .cols use .rows and when you want to get the data instead of lines.get(0, i) use lines.get(i, 0)

like image 102
Srinath Sridhar Avatar answered Nov 05 '22 02:11

Srinath Sridhar