我试图检测条形码,我想知道它是否通过基本统计检测到,所以我每个帧都检测到条形码,我想知道它是否在30FPS中检测到了多少是一秒钟失败的例子。
我写了一个简单的计数器,我等了一秒钟,但似乎不正确的方法是确定在一秒钟内检测到一定距离的条形码的百分比是多少。
所以我每秒有30帧,我想确定在检测时哪个帧失败,以及在一秒钟内检测的百分比是多少。
while(1){
frames++;
MDetector.setDictionary(aruco::Dictionary::ARUCO);
iThresParam1 = MDetector.getParams()._thresParam1;
iThresParam2 = MDetector.getParams()._thresParam2;
MDetector.setThresholdParams(7, 7);
MDetector.setThresholdParamRange(2, 0);
if(frames >15)
{
frames = 0;
//Ok, let's detect
MDetector.detect(input,Markers,CamParam,-1);
//for each marker, draw info and its boundaries in the image
for (unsigned int i=0;i<Markers.size();i++) {
Markers[i].draw(input,cv::Scalar(0,0,255),2);
}
cv::imshow("thres", MDetector.getThresholdedImage());
}
cv::imshow("in",input);
sleep(1);
}
编辑代码:
clock_t this_time;
clock_t last_time;
int count = 1;
double time_counter = 0;
ArucoLib(){
this_time = clock();
last_time = this_time;
}
cv::Mat operator()(cv::Mat input)
{
this_time = clock();
time_counter += (double)(this_time - last_time);
last_time = this_time;
// 1 second
if(time_counter > (double)(1 * CLOCKS_PER_SEC))
{
time_counter -= (double)(1 * CLOCKS_PER_SEC);
count++;
if(count >15)
count = 0;
MDetector.setDictionary(aruco::Dictionary::ARUCO);
iThresParam1 = MDetector.getParams()._thresParam1;
iThresParam2 = MDetector.getParams()._thresParam2;
MDetector.setThresholdParams(7, 7);
MDetector.setThresholdParamRange(2, 0);
//Ok, let's detect
MDetector.detect(input,Markers,CamParam,-1);
//for each marker, draw info and its boundaries in the image
for (unsigned int i=0;i<Markers.size();i++) {
Markers[i].draw(input,cv::Scalar(0,0,255),2);
}
cv::imshow("thres", MDetector.getThresholdedImage());
}
cv::imshow("in",input);
return input;
}