0

I'm trying to detect a barcode and I would like to know if its detected with basic statistics, so I have a barcode that is detected every frame, I would like to know if its detected in 30FPS and how much is the failure in one second that is passed for example.

I wrote a simple counter and I was waiting for one second, but it seems its incorrect way of determining how much in percent is the barcode is detected for a certain distance in one second for example.

so I have 30 frames per second, and I want to determine at which frame is failed at detecting and how much is the percent for detection in one second.

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

EDITED CODE:

  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;
    }
andre
  • 155
  • 4
  • 12
  • Your example code resets frames counter every 15 and not 30 also where are your _statistical_ analysis if you are just detecting and then drawing? – Khalil Khalaf Jul 07 '16 at 15:32
  • yea in 15 FPS, how would I get stats for that is in one second a frame has been missed – andre Jul 07 '16 at 15:34
  • so you need an actual timer or [clock](http://stackoverflow.com/questions/3220477/how-to-use-clock-in-c). You set your timer to `tick` every one second and on every `tick` of that timer, you need to check your frame count. And if it is less than 15 then you know that you missed a frame. Look up timer or clock or stop watch I am not sure in c++ but it is called `timer` in c# – Khalil Khalaf Jul 07 '16 at 15:35
  • @FirstStep can you help me with the implementation please – andre Jul 07 '16 at 15:37
  • Sure I could. Start with it and I will guide you – Khalil Khalaf Jul 07 '16 at 15:38
  • I have edited the code – andre Jul 07 '16 at 15:56
  • I dont know how would I know that I missed a frame – andre Jul 07 '16 at 15:58
  • You will need something like the accepted answer here http://stackoverflow.com/questions/3220477/how-to-use-clock-in-c you need to check `duration` if it is greater than a second, if yes then check `frames` the count and you will get your result. Keep it running with your loop but don't forget to reset `frames` every time you read its value – Khalil Khalaf Jul 07 '16 at 22:35

0 Answers0