Reputation: 428
I am using calcBackProject to find an object in a frame and it works somehow well scanning all the frame. but I need to enhance it
In my code at some point I have a motion detection mask and based on it I generated contours for candidate objects (objects that move and might be the target)
could I utilise this to calculate histogram for each contour and match it to the histogram of the target?
Upvotes: 1
Views: 667
Reputation: 3200
Convert your contour to a mask and use the mask in calcHist.
In C++ it would be done like this :
/**
* Converts a contour to a binary mask.
* The parameter mask should be a matrix of type CV_8UC1 with proper
* size to hold the mask.
* @param contour The contour to convert.
* @param mask The Mat where the mask will be written. Must have proper size
* and type before callign convertContourToMask.
*/
void convertContourToMask( const std::vector<cv::Point>& contour, cv::Mat& mask )
{
std::vector<std::vector<cv::Point>> contoursVector;
contoursVector.push_back( contour );
cv::Scalar white = cv::Scalar(255);
cv::Scalar black = cv::Scalar(0);
mask.setTo(black);
cv::drawContours(mask, contoursVector, -1, white, CV_FILLED);
}
Upvotes: 1