gocv
gocv copied to clipboard
The convex hull indices are not monotonous, which can be in the case when the input contour contains self-intersections in function 'convexityDefects'
I am working on a modified version of the gesture detector (the gesture detector doesn't work, at least for me). You can find it at https://github.com/Nv7-Github/gestures. When using convexity defects, it mostly works, but occasionally it crashes the program with the error
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(4.5.1) /tmp/opencv-20210228-9361-r4z33j/opencv-4.5.1/modules/imgproc/src/convhull.cpp:360: error: (-5:Bad argument) The convex hull indices are not monotonous, which can be in the case when the input contour contains self-intersections in function 'convexityDefects'
Steps to Reproduce
-
go get github.com/Nv7-Github/gestures
-
gestures
- Wait for a bit, move your hand around and make various figures with your hand
- It crashes.
Your Environment
- Operating System and version: MacOS Big Sur
- OpenCV version used: 4.5.1
- How did you install OpenCV?
brew install opencv
- GoCV version used:
v0.27.0
- Go version:
go version go1.16.3 darwin/amd64
- Did you run the
env.sh
orenv.cmd
script before trying togo run
orgo build
? No.
That looks like it is OpenCV itself see https://github.com/opencv/opencv/issues/4539 which is a very long running thread. Does not look specific to GoCV.
Is there a way to sort the indices using GoCV?
maybe this could work?
...
gocv.ConvexHull(cnt, &hull, false, false)
monoHull := gocv.NewMat()
gocv.Sort(hull, &monoHull , gocv.SortEveryColumn)
gocv.ConvexityDefects(cnt, monoHull , &defects)
...