我遇到以下问题,我在尝试打印变量时会遇到访问冲突异常,但只有在循环运行了特定次数后才会出现。
特别是在第211次迭代中,行:
cout << "Frame " << i << ", Recall: " << recall << ", Precision: " << precision << ", IoU: " << iou << endl;
给出错误:
0xC0000005: Access violation reading location 0x3F09C003.
奇怪的是,这只会在我打印变量时出现,而且总是在第211次迭代时发生。如果我完全删除print语句,或者甚至只是打印一个字符串,它工作正常。但是如果我打印任何变量(i,召回,精度等),它会抛出此异常。如果我完全从循环中删除打印,并且在循环外部只有一个打印语句,它也会抛出相同的异常。有什么建议吗?
以下代码:
template <typename T>
template <typename T2>
void Rect<T>::GetPerformance(const Rect<T2>& actual,
float &iou, float &precision, float &recall) const {
float numDetections = Area();
float numActual = actual.Area();
iou = Overlap(actual);
float numCorrect = iou *(actual.Area() + Area()) / (1 + iou);
precision = numCorrect / numDetections;
recall = numCorrect / numActual;
}
...
In Main
...
Mat frame;
Mat newFrame;
int i = 0;
float recall;
float precision;
float iou;
float avgRecall = 0;
float avgPrecision = 0;
float avgIoU = 0;
while (1)
{
iFrame = cvQueryFrame(capture);
if (!iFrame) break;
frame = iFrame;
FloatRect bb = carTracker.Track(frame);
bb.GetPerformance(gts[i], iou, precision, recall);
avgRecall += recall;
avgPrecision += precision;
avgIoU += iou;
cout << "Frame " << i << ", Recall: " << recall << ", Precision: " << precision << ", IoU: " << iou << endl;
i++;
}