I've searched the web nd I already found a few methods to do what I want, but these methods fail in efficiency compared to what I need.
I have a kinect(using Microsoft SDK) which iscurrently acquiring a person removing the background, saving the result in a 3 channel Mat with the person removed from the background. Now I need crop the image to fit only that person, ignoring the black region.
Here's the tricky part: I don't have many time to waste on every operation (I also need to do several other operations and this is supossed to work on real time. What I have currently implemented is a contours finder which give only this region, but it's really slow on real time. Since I only have a white region do detect and that region is really big (50% of the image area) I think there is some faster way to do this, as I only want the minimum and maximum values of x and y of this white area to crop it.
This is my currently my cropping function:
cv::Mat thresh_canny;
cv::vector<cv::vector<cv::Point> > contours;
cv::vector<cv::Vec4i> hierarchy;
cv::threshold(src, thresh_canny, 0, 255, 0);
cv::Canny(thresh_canny, thresh_canny, 20, 80, 3);
cv::findContours(thresh_canny, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
if (contours.size() != 1)
return false;
cv::Rect r = cv::boundingRect(contours.at(0));
src(r).copyTo(dst);
return true;
Many thanks!!
EDIT: Input image