Question

i want to form an irregular shape of the hand using its edges so that i can find the centroid of this hand using http://opencv.itseez.com/doc/tutorials/imgproc/shapedescriptors/moments/moments.html?highlight=moment#code. the canny function cuts the edges so i can't get a good contour out of it. here's a sample of the output http://imageshack.us/photo/my-images/208/cannywithblur.png/ and code.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;

int main(){

    cv::Mat image= cv::imread("open_1a.jpg");
    cv::Mat contours_mat;
    cv::Mat gray_image;

    blur( image, image, Size(3,3) );

    cv::Canny(image,
        contours_mat,
        40,
        120);
    cv::namedWindow("Image");
    cv::imshow("Image",image);
    cv::namedWindow("Canny");
    cv::imshow("Canny",contours_mat);
    cv::waitKey(0);
}

i want to get a contour that is closed shaped and only one contour. how can i do this?

Was it helpful?

Solution

You can try to apply a morphological closing of your binary image, which should connect the edges that have a gap wich is less than the size of your structuring element.

Corresponding function in the documentation

Tutorial on morphological operations

OTHER TIPS

You might try mean shift clustering, which can yield a nice, large connected region for the hand. Trying to identify a shape based only on edges can be tricky, especially if the shape isn't a simple polygon.

http://my.safaribooksonline.com/book/programming/opencv/9780596516130/tracking-and-motion/mean-shift_and_camshift_tracking

If mean shift (or a similar algorithm) can yield a nice segmentation between the hand and other objects, then it would be simple to find the geometric center or the center of mass.

Can you change your lighting? That could help quite a bit. The end of the finger and the fingernail on the middle finger present a problem because the contrast is low: there is little difference between the color of the background and the color of the middle fingernail.

Collimated lighting from the front would eliminate shadowing. Another option would be to use backlighting.

If for some reason you have to work with edges, then one of the most promising techniques to join broken edges ("shape completion") relies on "natural" or "aesthetic" curves such as the Euler spiral. Given two end points and tangents at those end points, a natural connecting curve can be found.

http://www.lems.brown.edu/vision/researchAreas/EulerSpiral/index.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top