c++ - CV4.1 : Failed Assertion in function detectAndCompute level>=0

标签 c++ opencv assert feature-tracking

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

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

关键点2边界框:

//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);

最佳答案

正如您在 source code 中看到的那样:

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

你需要修正你计算octave的方式

关于c++ - CV4.1 : Failed Assertion in function detectAndCompute level>=0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57053377/

相关文章:

c++ - 在以下情况下,您将如何声明参数类型

opencv - 如何使用opencv flann,尤其是设置距离算法?

java - 为什么 JUnit 不提供 assertNotEquals 方法?

c++ - 如何将单元测试与 assert() 相结合

ruby - 正确的 Assert_Raise 单元测试和异常类的使用

c++ - Windows 中的麦克风列表(输入设备列表)

c++ - 嵌套循环语句结果不正确

c++ - 为什么用cin做数值变量是 "bad"?

python - 使用 OpenCV 的 VideoCapture 方法进行高效链接处理? {编辑}

opencv - OpenCV 中训练有素的级联