我使用calcBackProject在一个框架中找到一个对象,它在某种程度上可以很好地扫描所有的帧。但我需要加强它
在我的代码中,我有一个运动检测掩码,并在此基础上为候选对象(移动和可能是目标的对象)生成等高线。
我能用这个来计算每个轮廓的直方图并将其与目标的直方图相匹配吗?
发布于 2015-10-13 06:27:53
将您的轮廓转换为掩码,并在calcHist中使用该掩码。
在C++中,可以这样做:
/**
* 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);
}https://stackoverflow.com/questions/33092921
复制相似问题