CV4.1:函数detectAndCompute 级别>=0 中的断言失败

Posted

技术标签:

【中文标题】CV4.1:函数detectAndCompute 级别>=0 中的断言失败【英文标题】:CV4.1: Failed Assertion in function detectAndCompute level>=0 【发布时间】:2019-07-16 08:43:05 【问题描述】:

我目前正在研究一个使用 ORB 的小算法。它必须在某个时候重新计算关键点和描述符,因为它们的位置和大小会发生变化。但是,在“useExistingKepoints”标志打开的情况下调用detectAndCompute,在断言“级别> = 0”处失败。我很困惑,因为在关键点或描述符中没有称为“级别”的属性。我的问题是究竟是什么导致断言失败以及如何避免这种情况?

仅供参考:由于跟踪器使用矩形边界框而不是圆形关键点,因此我必须将一个转换为另一个。

Keypoint2BoundingBox:

//Create Rect2d with data from the keypoint. 
//Orientation and octave don't need to be saved, since  the object gets reused
//kp: KeyPoint
Rect2d(round(kp.pt.x - kp.size / 2), round(kp.pt.y - kp.size / 2)
       round(kp.size), round(kp.size)));

BoundingBox2Keypoint(此方法的结果被传递给 ORB 导致问题)

//obtain previous kp object and update it accordingly
//kp: KeyPoint;   rect: Rect2d
kp->size = int(round(max(rect->height,rect->width)));
kp->octave = int(round(size2Octave(kp->size, patchsize, scale)));
kp->pt = Point2f(int(round(rect->x-(rect->width/2))),
int(round(rect->y-(rect->height/2))));

Size2Octave

//Uses keypoint size and some ORB parameters to compute the octave 
//the keypoint would have
//size: Keypoint Size;   patchsize: size of keypoints at octave 0;
//scale: stepsize to next octave
//returns fraction if Keypoint size is not multiple of patchsize
log10(size/patchsize)/log(scale);

【问题讨论】:

【参考方案1】:

正如您在source code 中看到的:

 level = keypoints[i].octave;
 CV_Assert(level >= 0);

您需要修正计算 octave 的方式

【讨论】:

以上是关于CV4.1:函数detectAndCompute 级别>=0 中的断言失败的主要内容,如果未能解决你的问题,请参考以下文章