I imitated the OpenCV API Reference to write some code using HoughLines(P):
Mat src = opencv_imgcodecs.imread("pic.png", 0);
Mat dst = new Mat();
Mat color_dst = new Mat();
opencv_imgproc.Canny(src, dst, 50, 200, 3, true);
// opencv_imgproc.cvtColor(dst, color_dst, CV_GRAY2BGR);
Mat lines = new Mat();
opencv_imgproc.HoughLines(dst, lines, 1, CV_PI / 180, 100);
// opencv_imgproc.HoughLinesP(dst, lines, 1, CV_PI / 180, 80, 30, 10);
So how can I get the points determining the detected lines?
They are the elements of the lines object. Try createIndexer().
Did I make wrong usage of the method HoughLines? It seems that I can't get the right result.
What results are you getting?
I wrote such code:
Mat src = opencv_imgcodecs.imread("pic.png", 0);
Mat dst = new Mat();
opencv_imgproc.Canny(src, dst, 50, 200, 3, true);
Mat lines = new Mat();
opencv_imgproc.HoughLines(dst, lines, 1, CV_PI / 180, 100);
Indexer indexer = lines.createIndexer();
System.out.println("Row: " + indexer.rows());
System.out.println("Col: " + indexer.cols());
System.out.println("Width: " + indexer.width());
System.out.println("Height: " + indexer.height());
System.out.println("[0, 0]: " + indexer.index(0, 0));
System.out.println("[1, 0]: " + indexer.index(1, 0));
System.out.println("[2, 0]: " + indexer.index(2, 0));
System.out.println("[3, 0]: " + indexer.index(3, 0));
System.out.println("[4, 0]: " + indexer.index(4, 0));
And below is the result:
Row: 3058
Col: 1
Width: 1
Height: 3058
[0, 0]: 0
[1, 0]: 2
[2, 0]: 4
[3, 0]: 6
[4, 0]: 8
How do you see it ?
Call get(), not index().
Yes, what you said is exactly right. Thank you so much for your reply~