2016-11-04 1 views
0

Donc, il semble que l'API a changé au fil du temps.Une façon contemporaine de faire fonctionner HoughLinesP en JavaCV

j'aller aussi loin que

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) 

Mais je ne sais pas comment extraire des points de la matrice lines. Par exemple, this old post suggère une chose telle que MatOfInt4 que je ne trouve pas. En outre, il y a une réponse qui dit que je peux faire lines.get(0, x) sur un Mat, une méthode qui n'existe pas.

Puis-je trouver another variant qui utilise un UByteRawIndexer, mais les cellules dans ma matrice ont trois au lieu de quatre éléments (ce qui est peut-être parce que j'appelle HoughLinesP et non HoughLines).

Alors, comment puis-je obtenir des points de l'appel HoughLinesP? JavaCV est 1.2, OpenCV est 3.1.


Si je fais une recherche de la matrice lines pour sa taille, je reçois rows = 19167, cols = 1; Je crée un Indexer qui semble être un UByteRawIndexer, je reçois sizes = [1958, 2196, 3]. Rien de tout cela n'a de sens pour moi. lines a également depth = 5 et type = 13.

Répondre

0

Semble que j'ai créé l'indexeur à partir de la mauvaise matrice (image d'entrée au lieu de lines), c'est pourquoi il était si grand et de type non signé-octet.

Création de l'indexeur à partir de la matrice lines donne une IntRawIndexer avec des rangées correspondant à nombre de lignes, une colonne, et la troisième dimension est de taille 4, donnant x1, y1, x2, y2:

val indexer: IntRawIndexer = lines.createIndexer() 

    for (i <- 0 until indexer.rows().toInt /* lines.rows() */) { 
    val x1 = indexer.get(i, 0, 0) 
    val y1 = indexer.get(i, 0, 1) 
    val x2 = indexer.get(i, 0, 2) 
    val y2 = indexer.get(i, 0, 3) 

    println(s"x1 = $x1, y1 = $y1, x2 = $x2, y2 = $y2") 

    val pt1 = new Point(x1, y1) 
    val pt2 = new Point(x2, y2) 
    val colr = new Scalar(0, 0, 255, 128) 

    opencv_imgproc.line(mat, pt1, pt2, colr, 1, opencv_core.LINE_AA, 0) 
    }