Android Question OCV Library / Declaration of a line/lines


Active Member
Licensed User
Hi, can someone show me how to declare a line. I am trying to do a Hough translation
'now do the Hough

        Dim lines As [B]OCVMatOfPoint2f[/B]
        Dim K As Int
        Dim Threshold As Int = CannyMax

        mImgProc.HoughLines1(tmpMat, lines, 1.0, one_degree, Threshold )
        Dim allLines() As [B]OCVPoint [/B]= lines.toArray()
        ToastMessageShow("Number of Lines"&allLines.Length,True)
        For K = 0 To allLines.Length-1
            Log (K&" "&allLines(K))
Obviously the Dim lines declaration is wrong, it just defines an object with points rather than a line with two points. The code works, but shows only the first coordinate in the log. I could not figure out the declaration in b4a. In other languages there's a vector definition, but that does not exist in B4a. Thanks for help and explanation, Georg


Active Member
Licensed User
OK, found out with trial and error. This may not be the most elegant code, however it does what it should. For anyone else using the OCVLibrary-Wrapper of Jordi:
The original OCV Library in Java change the calls and parameters nearly with any new version. This code uses the OCVLibrary version 3.4.1. For other versions, the calls have to be adapted.

'        Linesarray is declared as Dim Linesarray(1000,4) as Int in the Globals section. Could be a List as well       
        Dim myColorScalar As OCVScalar
        Dim onedegree As Float = 3.1415/180
        Dim LinesP As OCVMat
        Log("Lines: "&LinesP.rows)

        For i = 0 To LinesP.rows-1
            Dim l() As Double = LinesP.get5(i,0) 'This is crucial to access data in the LinesP OCVMat
            Log ("Line i :"&i&"   "&l(0)&","&l(1)&" to "&l(2)&","&l(3))
            Linesarray(i,0) = l(0)
            Linesarray(i,1) = l(1)
            Linesarray(i,2) = l(2)
            Linesarray(i,3) = l(3)

        NumberofLines = LinesP.rows

    ' Draw lines detected in 
        srcMat.copyTo( tmpMat)                                                                    
        If NumberofLines > 0 Then 
            Dim myColorScalar As OCVScalar
            myColorScalar.Initialize3(255,0,0) 'thats red
            For i = 0 To NumberofLines-1        
                Dim p1 As OCVPoint
                Dim p2 As OCVPoint
                p1 = CreatePoint(Linesarray(i,0),Linesarray(i,1))
                p2 = CreatePoint(Linesarray(i,2),Linesarray(i,3))
                Sleep(100) 'show progress
                mImgProc.line(tmpMat,p1,p2,myColorScalar,2,1,0) 'p1 and p2 must be passed on as above
        End If
Upvote 0


Active Member
Licensed User
Still problems with OCVMat. I try to do the following:
    M = mImgProc.getPerspectiveTransform(pts_src,pts_dst)
I have the source corner points both as OCVPoints or as bitmap coordinates. The destination corner points are the four corners of a 640x640 bitmap. But I have not found out how to make pts_src and pts_dst. They should be of type OCVMat, but how to convert the points into OCVMat?
Thanks for advice!
Upvote 0