gocv icon indicating copy to clipboard operation
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'

Open Nv7-GitHub opened this issue 3 years ago • 3 comments

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

  1. go get github.com/Nv7-Github/gestures
  2. gestures
  3. Wait for a bit, move your hand around and make various figures with your hand
  4. 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 or env.cmd script before trying to go run or go build? No.

Nv7-GitHub avatar Apr 26 '21 22:04 Nv7-GitHub

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.

deadprogram avatar May 16 '21 16:05 deadprogram

Is there a way to sort the indices using GoCV?

Nv7-GitHub avatar May 16 '21 16:05 Nv7-GitHub

maybe this could work?

...
gocv.ConvexHull(cnt, &hull, false, false)
monoHull := gocv.NewMat()
gocv.Sort(hull, &monoHull , gocv.SortEveryColumn)
gocv.ConvexityDefects(cnt, monoHull , &defects)
...

McApe avatar Jul 19 '22 18:07 McApe