Skip to content

Commit

Permalink
calib3d: adjust function signatures for Rodrigues and SolvePnP per co…
Browse files Browse the repository at this point in the history
…nvention, add smoketests

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Oct 18, 2023
1 parent faccc7f commit af1958a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
4 changes: 2 additions & 2 deletions calib3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ func ConvertPointsFromHomogeneous(src Mat, dst *Mat) {
//
// For further details, please see:
// https://docs.opencv.org/4.0.0/d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac
func Rodrigues(src, dst *Mat) {
func Rodrigues(src Mat, dst *Mat) {
C.Rodrigues(src.p, dst.p)
}

// SolvePnP finds an object pose from 3D-2D point correspondences.
//
// For further details, please see:
// https://docs.opencv.org/4.0.0/d9/d0c/group__calib3d.html#ga549c2075fac14829ff4a58bc931c033d
func SolvePnP(objectPoints Point3fVector, imagePoints Point2fVector, cameraMatrix, distCoeffs, rvec, tvec *Mat, useExtrinsicGuess bool, flags int) bool {
func SolvePnP(objectPoints Point3fVector, imagePoints Point2fVector, cameraMatrix, distCoeffs Mat, rvec, tvec *Mat, useExtrinsicGuess bool, flags int) bool {
return bool(C.SolvePnP(objectPoints.p, imagePoints.p, cameraMatrix.p, distCoeffs.p, rvec.p, tvec.p, C.bool(useExtrinsicGuess), C.int(flags)))
}
71 changes: 71 additions & 0 deletions calib3d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,3 +713,74 @@ func TestConvertPointsFromHomogeneous(t *testing.T) {
t.Errorf("ConvertPointsFromHomogeneous(): euclidean Z - got %v, want %v", pts[0].Z, 2)
}
}

func TestRodrigues(t *testing.T) {
k := NewMatWithSize(3, 3, MatTypeCV64F)
defer k.Close()

k.SetDoubleAt(0, 0, 689.21)
k.SetDoubleAt(0, 1, 0)
k.SetDoubleAt(0, 2, 1295.56)

k.SetDoubleAt(1, 0, 0)
k.SetDoubleAt(1, 1, 690.48)
k.SetDoubleAt(1, 2, 942.17)

k.SetDoubleAt(2, 0, 0)
k.SetDoubleAt(2, 1, 0)
k.SetDoubleAt(2, 2, 1)

dest := NewMat()
defer dest.Close()

Rodrigues(k, &dest)

if dest.Empty() {
t.Error("final result is empty")
return
}
}

func TestSolvePnP(t *testing.T) {
pts := []Point3f{
{10.0, 10.0, 0.1},
{10.0, 20.0, 1.0},
{20.5, 21.5, 2.0},
{10.0, 20.0, 1.0},
}

objectPointsVector := NewPoint3fVectorFromPoints(pts)
defer objectPointsVector.Close()

pts2 := []Point2f{
{10.0, 10.0},
{10.0, 20.0},
{20.5, 21.5},
{25.5, 30.5},
}

imagePointsVector := NewPoint2fVectorFromPoints(pts2)
defer imagePointsVector.Close()

cameraMatrix := Eye(3, 3, MatTypeCV64F)
defer cameraMatrix.Close()
distCoeffs := NewMat()
defer distCoeffs.Close()
rvecs := NewMat()
defer rvecs.Close()
tvecs := NewMat()
defer tvecs.Close()

SolvePnP(objectPointsVector, imagePointsVector, cameraMatrix, distCoeffs,
&rvecs, &tvecs, false, 0)

if rvecs.Empty() {
t.Error("rvecs result is empty")
return
}

if tvecs.Empty() {
t.Error("tvecs result is empty")
return
}
}

0 comments on commit af1958a

Please sign in to comment.