3

I am currently attempting to use OpenCV 2.3 and c++ to detect a hand (wearing a green glove), and distinguish between different hand gestures.

At this very moment, my next step is to acquire specific features of the hand (convex defects).

So far I've used these functions in my process:

mixChannels(); //to subtract non-green channels from green. 
threshold(); //to convert to binary
erode(); dialate(); //to get rid of any excess noise
findContours(); //to find contours of course

these have worked splendidly and I have been able to output findContours() through the use of drawContours().

Next step, and this is where I'm at, is using convexHull(), which also works in OpenCV 2.3. I have however yet to find out how the vector results of convexHull() actually look (what features they contains).

But this is where the tricky part comes.

I found that the older version of OpenCV (using c which uses IplImage), has a neat little function called cvConvexityDefects() which can give a set of deficiencies on the convex hull. These are what I need, but there seems to be no such function for the OpenCV 2.3 and I don't see how I can use the old syntax to get these results.

Here's a link to Open CV documentation on cvConvextDefects.

What I'm asking for, is either a similar OpenCV 2.3 function, or a selfwritten piece of code or algorithm for finding these defects. Or a method to use the old 2.1 syntax for a vector result or something like that.

(I know that I can use other features, rectangular bounding boxes, and fitted circles. But I'm sure that convex defects yield the most distinguishable features.)

Solution - I ended up using a c++ wrapper from this post The only thing not working for this wrapper seems to be a leek of the defects vector, which should be easily solvable.

Next step is getting some usable data from these defects. (At first glance. the data seems to be single points on the convexHull or the Contour or the count of these. I had at first expected a set of two points, or a single point and a length, which it does not seem to be. If I'm hitting 'brick wall' with this, I'll make another post)

Community
  • 1
  • 1
Sonaten
  • 502
  • 2
  • 14
  • 1
    OpenCV 2.3.1 still has this method so you must have done something wrong when looking for it. You can see for yourself in the documentation: http://opencv.itseez.com/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=defects# – Adrian Nov 16 '11 at 10:24
  • I have searched quite a bit. I do think that the answer _vasile_ has provided will solve my problem. (I have walked around in the forest that is OpenCV documentation for quite a while, but thanks for raising the question) – Sonaten Nov 16 '11 at 13:02

2 Answers2

3

The new C++ interface does not (yet) support all the functions in C. And the opposite is true, also (not everything in cpp is in c). The reasons are various, but the good news is that you can easily use whatever function you want. By example, here you have to convert contours to sequences (CvSeq) and send them to your function.

Moreover, the FindContours method is a wrapper over cvFindContours. You can call it

cvFindContours((IplImage*)matImage, ...);

and then use directly the result.

Another way would be to create a nice, clean C++ wrapper over cvConvexDefects() and submit it to OpenCV. In the findContours source you will find some help for that (the opposite transform)

Sam
  • 19,708
  • 4
  • 59
  • 82
  • Thanks for the input, I believe this can help me with my detection. I will add "answered" when I solve the problem. – Sonaten Nov 16 '11 at 13:03
  • So far I'm struggling with getting this right. I have used the c syntax only few measly times, and I am not that keen on programming in the first place. Initial approach was starting from my binary image to find the contours with c syntax, however I seem to lack some quite a bit of knowledge, and the OpenCV.WillowGarage documentation site has been down most of the day. I would like to attempt to convert my convexHull vector from the c++ syntax to the sequence which you mentioned, but I don't know where to start. Could you perhaps shed some light on this? – Sonaten Nov 17 '11 at 10:19
  • I found the wrapper which _RyanfaeScotland_ mentions in his answer to my post. – Sonaten Nov 18 '11 at 08:41
2

I would like to attempt to convert my convexHull vector from the c++ syntax to the sequence which you mentioned, but I don't know where to start. Could you perhaps shed some light on this?

Check out this question here, I beleive it goes into it.

Convexity defects C++ OpenCv

Community
  • 1
  • 1
RyanfaeScotland
  • 1,216
  • 11
  • 30
  • On the note of _vasile_ suggesting a c++ wrapper for the function, I came to find the very post you are referring to. But thanks for the effort. – Sonaten Nov 18 '11 at 08:40