So, it seems the API changed over time.
I get as far as
import org.bytedeco.javacpp.opencv_core.{Mat, Point, Scalar}
import org.bytedeco.javacpp.{opencv_core, opencv_imgcodecs, opencv_imgproc}
val mat = opencv_imgcodecs.imread("test-in.jpg")
val greyMat = new Mat()
val lines = new Mat()
opencv_imgproc.cvtColor(mat, greyMat, opencv_imgproc.CV_BGR2GRAY, 1)
val rho = 1.0
val theta = 1.0.toRadians
val thresh = 50
val minLineLen = 80
val maxLineGap = 50
opencv_imgproc.HoughLinesP(greyMat, lines, rho, theta, thresh,
minLineLen, maxLineGap)
for (i <- 0 until lines.rows()) {
val pt1 = ??? : Point
val pt2 = ??? : Point
val colr = new Scalar(0, 0, 255, 128)
opencv_imgproc.line(mat, pt1, pt2, colr, 1, opencv_core.LINE_AA, 0)
}
opencv_imgcodecs.imwrite("test-out.jpg", mat)
But I don't know how to extract the points from the lines
matrix.
For example, this old post suggests there such thing as a MatOfInt4
which I don't find. Also, there is an answer that says I can do lines.get(0, x)
on a Mat
, a method that doesn't exist.
Then I find another variant that uses a UByteRawIndexer
, but the cells in my matrix have three instead of four elements (this is perhaps because I call HoughLinesP
and not HoughLines
).
So how the heck do I get points from the HoughLinesP
call? JavaCV is 1.2, OpenCV is 3.1.
If I query the lines
matrix for its size, I get rows = 19167, cols = 1
; I create an Indexer
which appears to be a UByteRawIndexer
, I get sizes = [1958, 2196, 3]
. None of this makes sense to me. lines
also has depth = 5
and type = 13
.