gocv
gocv copied to clipboard
undistort function does not work correctly
Description
I tried to reproduce the undistort test from gocv/calib3d_test.go / function TestUndistort with the original Image distortion.jpg and unchanged code from the repository, but I didn't got the example working.
Steps to Reproduce
- Copy gocv/calib3d_test.go / function TestUndistort to a new golang file test-distortion.go
- Copy testimage distortion.jpg to same path like go-file
- go run test-distortion.go
Your Environment
- Operating System and version: Linux ubuntu 18
- OpenCV version used:
- How did you install OpenCV? build from source
- GoCV version used: v0.31.0
- Go version: go version go1.19 linux/arm64
- Did you run the
env.sh
orenv.cmd
script before trying togo run
orgo build
? No
Code of example programm: test-distortion.go (same as gocv/calib3d_test.go / function TestUndistort)
`package main
import ( "fmt" "gocv.io/x/gocv" )
func main() {
img := gocv.IMRead("distortion.jpg", gocv.IMReadUnchanged)
if img.Empty() {
fmt.Println("#### error open file #############")
//t.Error("Invalid read of Mat test")
return
}
defer img.Close()
dest := img.Clone()
defer dest.Close()
k := gocv.NewMatWithSize(3, 3, gocv.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)
d := gocv.NewMatWithSize(1, 4, gocv.MatTypeCV64F)
defer d.Close()
d.SetDoubleAt(0, 0, 0)
d.SetDoubleAt(0, 1, 0)
d.SetDoubleAt(0, 2, 0)
d.SetDoubleAt(0, 3, 0)
knew := gocv.NewMat()
defer knew.Close()
k.CopyTo(&knew)
knew.SetDoubleAt(0, 0, 0.5*k.GetDoubleAt(0, 0))
knew.SetDoubleAt(1, 1, 0.5*k.GetDoubleAt(1, 1))
gocv.Undistort(img, &dest, k, d, knew)
if dest.Empty() {
fmt.Println("#### final image is empty #############")
//t.Error("final image is empty")
return
}
gocv.IMWrite("distortion_up.jpg", dest)
} `
output image: