Android Question [SOLVED] dotpixel -> Perspective Transformation + Crop + Fit size image

scsjc

Well-Known Member
Licensed User
Longtime User
I'm working on a perspective projection that I have to TRANSFORM+CROP+FIT SIZE IMAGE
I was working with the solution in this post https://www.b4x.com/android/forum/threads/perspectivetransformation.73984/#content and I got the image to do exactly what I need.

But I need to do it with a simple point pixel X Y coordinates. I have some calculations that position the green point in a perspective, but I can't fit that projection that is the same as the image.
In the attached image the green dot has to coincide with the red dot.

Does anyone have a solution? THANK :)


1695795826231.png
 

Attachments

  • trasform-crop-fit.zip
    235.3 KB · Views: 41

scsjc

Well-Known Member
Licensed User
Longtime User
I just applied the equation within an example in B4A, but I don't know why the left corner at the bottom, it gives me a value that goes off the screen
Does anyone have any idea why this could be?
THANK YOU :)

Captura.JPG
 

Attachments

  • trasform-crop-fit.zip
    235.7 KB · Views: 39
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Find error... library MatrixOp decimals not exactly -> Create function Solve working perfectly


B4X:
Sub Solve(A(,) As Double, B() As Double) As Double()
    ' Resolución del sistema utilizando eliminación gaussiana
    Dim n As Int
    n = B.Length
    For i = 0 To n - 1
        ' Pivoteo parcial: Encuentra el elemento máximo en la columna actual
        Dim maxIdx As Int
        maxIdx = i
        For k = i + 1 To n - 1
            If Abs(A(k, i)) > Abs(A(maxIdx, i)) Then
                maxIdx = k
            End If
        Next
        ' Intercambiar filas si es necesario
        If maxIdx <> i Then
            For j = 0 To n - 1
                Dim temp As Double
                temp = A(i, j)
                A(i, j) = A(maxIdx, j)
                A(maxIdx, j) = temp
            Next
            Dim tempB As Double
            tempB = B(i)
            B(i) = B(maxIdx)
            B(maxIdx) = tempB
        End If
        ' Hacer la matriz triangular superior
        Dim pivot As Double
        pivot = A(i, i)
        For j = i To n - 1
            A(i, j) = A(i, j) / pivot
        Next
        B(i) = B(i) / pivot
        
        For k = i + 1 To n - 1
            Dim factor As Double
            factor = A(k, i)
            For j = i To n - 1
                A(k, j) = A(k, j) - factor * A(i, j)
            Next
            B(k) = B(k) - factor * B(i)
        Next
    Next
    ' Resolución del sistema triangular superior
    Dim X(n) As Double
    For i = n - 1 To 0 Step -1
        X(i) = B(i)
        For j = i + 1 To n - 1
            X(i) = X(i) - A(i, j) * X(j)
        Next
    Next
    Return X
End Sub

1695892685737.png
 
Upvote 0
Top