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?
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)
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