opencv 或 C++
向下取整的时候,会把0取整为 -1
int a = (int)asiftKeypoints_query[i].pt.x;
int b = cvFloor(asiftKeypoints_query[i].pt.x);
int c = cvRound(asiftKeypoints_query[i].pt.x);
int d = floor(asiftKeypoints_query[i].pt.x);
从而导致了访问特征点位置,出现(0,298.249251)取整变成了(-1,298)
还有创建矩阵时候,如果矩阵内的数字大于255,就不能使用uchar
比如:
Mat statisticsLeft(queryImage.size().height, queryImage.size().width, CV_8U, Scalar::all(0));
上面是博客中经常看到的,如果不加思索,直接照搬
如果你的值大于255,放入矩阵某个位置,就会出错了
应该改为float
Mat statisticsLeft(queryImage.size().height, queryImage.size().width, CV_32F, Scalar::all(0));
不仅如此,
访问此矩阵时候,也要改为float
float* data = NULL;
for (size_t i = 0; i < mNumberMatches; i++)
{
x_statisticsLeft = mvKeyPoint1[i].first;
y_statisticsLeft = mvKeyPoint1[i].second;
data = statisticsLeft.ptr<float>(y_statisticsLeft);
data[x_statisticsLeft] = 1;
}