gocv
gocv copied to clipboard
MatchTemplate function causing exception
After using MatchTemplate function I receive an Exception.
Description
func main() {
haystack_img := gocv.IMRead("./test.png", gocv.IMReadUnchanged)
needle_img := gocv.IMRead("./test2.png", gocv.IMReadUnchanged)
result := gocv.NewMat()
gocv.MatchTemplate(haystack_img, needle_img, &result, gocv.TmCcoeffNormed, gocv.NewMat())
return
}
$ go run main.go
Exception 0x20474343 0x17d1a234390 0x7ff9ca8d59c6 0x7ff9cfaa4f99
PC=0x7ff9cfaa4f99
runtime: unknown pc 0x7ff9cfaa4f99
stack: frame={sp:0x55c7fff310, fp:0x0} stack=[0x0,0x55c7fffc40)
0x00000055c7fff210: 0x0000000000000000 0x0000017d1a120000
0x00000055c7fff220: 0x0000017d1a1202a8 0x0000000000000110
0x00000055c7fff230: 0x0000000000000020 0x0000017d1a120cc0
0x00000055c7fff240: 0x0000000000000012 0x0000000000000000
0x00000055c7fff250: 0x0000000000000000 0x0000000000000020
0x00000055c7fff260: 0x0000000000000018 0x0000000000000004
0x00000055c7fff270: 0x0000017d1a1f0000 0x00000055c7fff339
0x00000055c7fff280: 0x0000000000000002 0x00007ff9d20bb3c7
0x00000055c7fff290: 0x0000017d1a120000 0x0000017d00000000
0x00000055c7fff2a0: 0x0000000000000018 0x0000000000000000
0x00000055c7fff2b0: 0x0000017d1a237ab8 0x0000017d1a1f0000
0x00000055c7fff2c0: 0x0000000200000001 0x0000000000000001
0x00000055c7fff2d0: 0x0000017d1a1f12b8 0x0000000000000000
0x00000055c7fff2e0: 0x0000bd9c778c6f3d 0x0000000000000000
0x00000055c7fff2f0: 0x00000055c7fffb40 0x0000017d1a2343e8
0x00000055c7fff300: 0x0000017d1a234410 0x00007ff9cfaa4f99
0x00000055c7fff310: <0x0000000000000000 0x00000000681f6860
0x00000055c7fff320: 0x0000017d1a2343d0 0x00007ff9d1129dd2
0x00000055c7fff330: 0x0000000020474343 0x0000000000000000
0x00000055c7fff340: 0x00007ff9cfaa4f99 0x00007ff900000001
0x00000055c7fff350: 0x0000017d1a234390 0x00007ff9ca8d59c6
0x00000055c7fff360: 0x0000017d40c4ffff 0x00000055c7fffb40
0x00000055c7fff370: 0x000000006832e710 0x0000017d1a234530
0x00000055c7fff380: 0x0000000000000018 0x00007ff9517558c0
0x00000055c7fff390: 0x0000000000000010 0x00007ff9d1129d40
0x00000055c7fff3a0: 0x0000000000000000 0x0000000000000018
0x00000055c7fff3b0: 0x000000006832e710 0x00000055c7ff0000
0x00000055c7fff3c0: 0x0000000000000008 0x00007ff9cb05de32
0x00000055c7fff3d0: 0x000065f79fc02b9f 0x00007ff9517558c0
0x00000055c7fff3e0: 0x0000000000000000 0x00007ff9cb05d3b1
0x00000055c7fff3f0: 0x00000000681f6860 0x0000017d1a2343d0
0x00000055c7fff400: 0x0000017d1a2343e8 0x0000017d1a234410
runtime: unknown pc 0x7ff9cfaa4f99
stack: frame={sp:0x55c7fff310, fp:0x0} stack=[0x0,0x55c7fffc40)
0x00000055c7fff210: 0x0000000000000000 0x0000017d1a120000
0x00000055c7fff220: 0x0000017d1a1202a8 0x0000000000000110
0x00000055c7fff230: 0x0000000000000020 0x0000017d1a120cc0
0x00000055c7fff240: 0x0000000000000012 0x0000000000000000
0x00000055c7fff250: 0x0000000000000000 0x0000000000000020
0x00000055c7fff260: 0x0000000000000018 0x0000000000000004
0x00000055c7fff270: 0x0000017d1a1f0000 0x00000055c7fff339
0x00000055c7fff280: 0x0000000000000002 0x00007ff9d20bb3c7
0x00000055c7fff290: 0x0000017d1a120000 0x0000017d00000000
0x00000055c7fff2a0: 0x0000000000000018 0x0000000000000000
0x00000055c7fff2b0: 0x0000017d1a237ab8 0x0000017d1a1f0000
0x00000055c7fff2c0: 0x0000000200000001 0x0000000000000001
0x00000055c7fff2d0: 0x0000017d1a1f12b8 0x0000000000000000
0x00000055c7fff2e0: 0x0000bd9c778c6f3d 0x0000000000000000
0x00000055c7fff2f0: 0x00000055c7fffb40 0x0000017d1a2343e8
0x00000055c7fff300: 0x0000017d1a234410 0x00007ff9cfaa4f99
0x00000055c7fff310: <0x0000000000000000 0x00000000681f6860
0x00000055c7fff320: 0x0000017d1a2343d0 0x00007ff9d1129dd2
0x00000055c7fff330: 0x0000000020474343 0x0000000000000000
0x00000055c7fff340: 0x00007ff9cfaa4f99 0x00007ff900000001
0x00000055c7fff350: 0x0000017d1a234390 0x00007ff9ca8d59c6
0x00000055c7fff360: 0x0000017d40c4ffff 0x00000055c7fffb40
0x00000055c7fff370: 0x000000006832e710 0x0000017d1a234530
0x00000055c7fff380: 0x0000000000000018 0x00007ff9517558c0
0x00000055c7fff390: 0x0000000000000010 0x00007ff9d1129d40
0x00000055c7fff3a0: 0x0000000000000000 0x0000000000000018
0x00000055c7fff3b0: 0x000000006832e710 0x00000055c7ff0000
0x00000055c7fff3c0: 0x0000000000000008 0x00007ff9cb05de32
0x00000055c7fff3d0: 0x000065f79fc02b9f 0x00007ff9517558c0
0x00000055c7fff3e0: 0x0000000000000000 0x00007ff9cb05d3b1
0x00000055c7fff3f0: 0x00000000681f6860 0x0000017d1a2343d0
0x00000055c7fff400: 0x0000017d1a2343e8 0x0000017d1a234410
goroutine 1 [syscall]:
runtime.cgocall(0x31ee40, 0xc000121dd0)
C:/Program Files/Go/src/runtime/cgocall.go:156 +0x4a fp=0xc000121da8 sp=0xc000121d70 pc=0x1a40aa
gocv.io/x/gocv._Cfunc_MatchTemplate(0x17d1a215980, 0x17d1a2189f0, 0x17d1a1fdcf0, 0x5, 0x17d1a1fdd60)
_cgo_gotypes.go:5195 +0x52 fp=0xc000121dd0 sp=0xc000121da8 pc=0x311292
gocv.io/x/gocv.MatchTemplate.func1({0x17d1a215980, {0x0, 0x4361b0, 0x53a4a0}}, {0x17d1a2189f0, {0x0, 0x31b130, 0xc000121ea0}}, 0xc000121ea0, 0x5, ...)
C:/Users/zachw/go/pkg/mod/gocv.io/x/[email protected]/imgproc.go:673 +0xcf fp=0xc000121e20 sp=0xc000121dd0 pc=0x3118cf
gocv.io/x/gocv.MatchTemplate({0x17d1a215980, {0x0, 0x1dc932, 0xc000054000}}, {0x17d1a2189f0, {0x0, 0x300000002, 0xc000054000}}, 0xc00005bf38, 0x5, ...)
C:/Users/zachw/go/pkg/mod/gocv.io/x/[email protected]/imgproc.go:673 +0x79 fp=0xc000121ea0 sp=0xc000121e20 pc=0x311779
main.main()
C:/Users/zachw/Documents/project/god2/main.go:30 +0x151 fp=0xc000121f80 sp=0xc000121ea0 pc=0x311b31
runtime.main()
C:/Program Files/Go/src/runtime/proc.go:255 +0x217 fp=0xc000121fe0 sp=0xc000121f80 pc=0x1d8df7
runtime.goexit()
C:/Program Files/Go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000121fe8 sp=0xc000121fe0 pc=0x2036e1
rax 0x0
rbx 0x681f6860
rcx 0x17d1a21e070
rdi 0x17d1a2343e8
rsi 0x17d1a2343d0
rbp 0x17d1a234410
rsp 0x55c7fff310
r8 0xffffffffffffffff
r9 0x55c7ffed70
r10 0xfffffffe00000000
r11 0xfffffffdffffffff
r12 0x17d1a234390
r13 0x6832e710
r14 0x55c7fffb40
r15 0x17d40c4ffff
rip 0x7ff9cfaa4f99
rflags 0x206
cs 0x33
fs 0x53
gs 0x2b
exit status 2
I've tried other things I saw which solved other peoples issues -
func main() {
result := gocv.NewMat()
window := gocv.NewWindow("hello")
window.IMShow(result)
return
}
This causes the same error as above...
I've also tried this which does not display an error. Obviously, I'm wanting to do a template match or comparison of an image within a image on 2 images and not just show the image in a window. I'm not sure exactly what I am doing incorrectly with MatchTemplate function above..?
func main() {
img := gocv.IMRead("./test.png", gocv.IMReadUnchanged)
window := gocv.NewWindow("test")
window.IMShow(img)
return
}
Steps to Reproduce
- go run main.go
Your Environment
- Operating System and version: Windows 10 (Why does Microsoft make everything complicated?)
- OpenCV version used: 4.5.3
- How did you install OpenCV? using the win_build_opencv.cmd
- GoCV version used: 0.28.0
- Go version: go version go1.17.2 windows/amd64
- Did you run the
env.sh
orenv.cmd
script before trying togo run
orgo build
? no
This appears to be a window issue, I went ahead and followed the exact installation steps from my Linux machine, and the exact same code was executed and worked.
Would anybody be able to update the Windows 10 documentation on installing or suggest a build that is officially working?
I get the same error with TemplateMatch on windows10, any solutions?
@itiszac I fix it on windows by changing the IMRead options from "IMReadUnchanged" to "IMReadAnyColor", you may try it.
I changed the IMRead options from "IMReadUnchanged" to "IMReadGrayScale" and then work. You saved my day! Thanks a lot!@uglycow
@itiszac : Operating System and version: Windows 10 (Why does Microsoft make everything complicated?) I can't agree more with you opinion.