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?
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