«Features2DToolbox.GetHomographyMatrixFromMatchedFeatures» восстанавливает матрицу гомографии, используя randsa c (отслеживание объектов серфинга) - PullRequest
0 голосов
/ 09 марта 2020

Я копирую этот код, чтобы проверить его для проекта, но у меня есть эта ошибка: «Тип значения« HomographyMatrix »не может быть преобразован в« Матрицу гомографии »». И у меня тоже есть это сообщение: «восстановить матрицу гомографии, используя randsa c». Я использую Visual Studio 2019 и emgu.cv2.40 для этого проекта. Если кто-то может решить это, я буду благодарен, спасибо. Вот код: (отслеживание объектов серфинга)

Public Class Form1

    Dim capturez As Capture = New Capture
    Dim setz As Boolean
    Dim savedimage As Image(Of Gray, Byte)
    Dim imagez1 As Image(Of Gray, Byte)
    Dim resultimage As Image(Of Bgr, Byte)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        savedimage = capturez.RetrieveGrayFrame.Copy(New MCvBox2D(New PointF(75, 75), New Size(150, 150), 0))
        setz = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        imagez1 = capturez.RetrieveGrayFrame

        If setz = True Then

            Dim CPUsurfDz As SURFDetector = New SURFDetector(500, False)
            Dim homography As HomographyMatrix = Nothing
            Dim modelkeypoints As VectorOfKeyPoint
            Dim observedkeypoints As VectorOfKeyPoint
            Dim indices As Matrix(Of Integer)
            Dim dist As Matrix(Of Single)
            Dim mask As Matrix(Of Byte)

            modelkeypoints = CPUsurfDz.DetectKeyPointsRaw(savedimage, Nothing)
            Dim modeldescriptors As Matrix(Of Single) = CPUsurfDz.ComputeDescriptorsRaw(savedimage, Nothing, modelkeypoints)

            observedkeypoints = CPUsurfDz.DetectKeyPointsRaw(imagez1, Nothing)
            Dim observeddescriptors As Matrix(Of Single) = CPUsurfDz.ComputeDescriptorsRaw(imagez1, Nothing, observedkeypoints)

            Dim matcher As BruteForceMatcher(Of Single) = New BruteForceMatcher(Of Single)(DistanceType.L2)

            matcher.Add(modeldescriptors)

            indices = New Matrix(Of Integer)(observeddescriptors.Rows, 2)
            dist = New Matrix(Of Single)(observeddescriptors.Rows, 2)
            matcher.KnnMatch(observeddescriptors, indices, dist, 2, Nothing)

            mask = New Matrix(Of Byte)(dist.Rows, 1)
            mask.SetValue(255)

            Features2DToolbox.VoteForUniqueness(dist, 0.8, mask)

            Dim nonzerocount As Integer = CvInvoke.cvCountNonZero(mask)
            If nonzerocount = 4 Then 'Change to Greater-than-or-equal-to
                nonzerocount = Features2DToolbox.VoteForSizeAndOrientation(modelkeypoints, observedkeypoints, indices, mask, 1.5, 20)
                If nonzerocount = 4 Then 'Change to Greater-than-or-equal-to
                    homography = Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(modelkeypoints, observedkeypoints, indices, mask, 3)
                End If
            End If

            resultimage = Features2DToolbox.DrawMatches(savedimage, modelkeypoints, imagez1, observedkeypoints, indices, New Bgr(255, 255, 255), New Bgr(255, 255, 255), mask, Features2DToolbox.KeypointDrawType.NOT_DRAW_SINGLE_POINTS)

            Try
                Dim rect As Rectangle = savedimage.ROI

                Dim P1f As PointF = New PointF(rect.Left, rect.Bottom)
                Dim P2f As PointF = New PointF(rect.Right, rect.Bottom)
                Dim P3f As PointF = New PointF(rect.Right, rect.Top)
                Dim P4f As PointF = New PointF(rect.Left, rect.Top)

                Dim pts() As PointF = {P1f, P2f, P3f, P4f}

                homography.ProjectPoints(pts)

                Dim P1 As Point = New Point(pts(0).X, pts(0).Y)
                Dim P2 As Point = New Point(pts(1).X, pts(1).Y)
                Dim P3 As Point = New Point(pts(2).X, pts(2).Y)
                Dim P4 As Point = New Point(pts(3).X, pts(3).Y)

                Dim pointz() As Point = {P1, P2, P3, P4}

                resultimage.DrawPolyline(pointz, True, New Bgr(Color.Blue), 3)

            Catch ex As Exception
            End Try

            PictureBox3.Image = resultimage.ToBitmap

        End If

        Dim rectz As Rectangle = New Rectangle(0, 0, 150, 150)
        imagez1.Draw(rectz, New Gray(255), 2)
        PictureBox1.Image = imagez1.ToBitmap
    End Sub
End Class
...