假设我将图像划分为n
块。我想计算每个块的直方图,然后连接区域直方图。我研究了this page并编写了这段代码:
Map = imread("",0);
int histSize = 256;
int mapHeight = Map.rows;
int mapWidth = Map.cols;
int RegionRowNum = 9;
int RegionColNum = 9;
int regionHeightUnit = floor(mapHeight / RegionRowNum); // the height for each region
int regionWidthUnit = floor(mapWidth / RegionColNum); // the width for each region
int startHeight = floor((mapHeight - regionHeightUnit*RegionRowNum) / 2) + 1;
int startWidth = floor((mapWidth - regionWidthUnit*RegionColNum) / 2) + 1;
int sizes[] = { RegionRowNum, RegionColNum, histoDim };
Mat regionFeaMat = Mat(3, sizes, CV_8U, cv::Scalar(0));
vector<Mat> regionMapSets(RegionRowNum * RegionColNum);
vector<int> regionCoordinates(4);
Mat regionMap;
vector<Mat> regionMapHist;
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true;
bool accumulate = false;
for (int i = 0; i < RegionRowNum; i++)
{
for (int j = 0; j< RegionColNum; j++)
{
// Get the coordinates for each block first
regionCoordinates[0] = startHeight + i * regionHeightUnit;
regionCoordinates[1] = regionCoordinates[0] + regionHeightUnit - 1;
regionCoordinates[2] = startWidth + j * regionWidthUnit;
regionCoordinates[3] = regionCoordinates[2] + regionWidthUnit - 1;
if (i == 0)
regionCoordinates[0] = 1;
if (i == RegionRowNum - 1)
regionCoordinates[1] = mapHeight;
if (j == 0)
regionCoordinates[2] = 1;
if (j == RegionColNum - 1)
regionCoordinates[3] = mapWidth;
regionMap = Map(Rect(regionCoordinates[2] - 1, regionCoordinates[0] - 1, regionCoordinates[3] - regionCoordinates[2] + 1, regionCoordinates[1] - regionCoordinates[0] + 1));
regionMapSets[i*RegionColNum + j] = regionMap;
calcHist(®ionMapSets, 1, 0, Mat(), regionMapHist, 1, &histSize, &histRange, uniform, accumulate);
}
}
但我有这个错误:
Severity Code Description Project File Line Suppression State Detail Description Error (active)
no instance of overloaded function "calcHist" matches the argument list
argument types are: (std::vector<cv::Mat, std::allocator<cv::Mat>> *, int, int, cv::Mat, std::vector<cv::Mat, std::allocator<cv::Mat>>, int, int *, const float **, bool, bool)
如何解决?
答案 0 :(得分:1)
我按照以下方式编辑了我的代码: 我将此行添加为输出:
calchist
然后我编辑了calcHist(®ionMap, 1, 0, Mat(), regionMapHist[i*RegionColNum + j], 1, &histoDim, &histRange, uniform, accumulate);
的参数:
regionMapHist
{{1}}是我想要的!!