Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to get FPS in OpenCV live capture

Hi guys,

how to get frame rate per second in openCv live capture face detection. I have tried using capture property (VideoCapture.get(5)). but it doesnt work and give me 0 as the result. I also tried answer given in this question and i get approx 1000++ fps. i dont think this the correct fps because my live capture quite lag. by the way i am using java.

here is snipped of my code

    //-- 2. Read the video stream  
      Mat webcam_image=new Mat();  
      VideoCapture capture =new VideoCapture(0);   
      Thread.sleep(1000);
  if( capture.isOpened())  
         {  
          while( true )  
          {
              double t = (double)Core.getTickCount();  
               capture.read(webcam_image);  
            if( !webcam_image.empty() )  
             {   
                  frame.setSize(webcam_image.width()+40,webcam_image.height()+60);  
                  //-- 3. Apply the classifier to the captured image  
                  webcam_image=faceDetect.detect(webcam_image);  
                 //-- 4. Display the image  
                  framePanel.MatToBufferedImage(webcam_image);   
                  framePanel.repaint();   
             }  
             else  
             {   
                  System.out.println(" Image is empty. Break!");   
                  break;   
             }
            t = ((double)Core.getTickCount() - t) / Core.getTickFrequency();
            System.out.println("FPS "+ 1000.0/t);
            }  
           }  
           return;  
    }

I also tried technique from this blog, but i get 0.00 fps.

Any suggestion or what technique i should use to solve the problem?

How to get FPS in OpenCV live capture

Hi guys,

how to get frame rate per second in openCv live capture face detection. I have tried using capture property (VideoCapture.get(5)). but it doesnt work and give me 0 as the result. I also tried answer given in this question and i get approx 1000++ fps. i dont think this the correct fps because my live capture quite lag. by the way i am using java.

here is snipped of my code

    //-- 2. Read the video stream  
      Mat webcam_image=new Mat();  
      VideoCapture capture =new VideoCapture(0);   
      Thread.sleep(1000);
  if( capture.isOpened())  
         {  
          while( true )  
          {
              double t = (double)Core.getTickCount();  
               capture.read(webcam_image);  
            if( !webcam_image.empty() )  
             {   
                  frame.setSize(webcam_image.width()+40,webcam_image.height()+60);  
                  //-- 3. Apply the classifier to the captured image  
                  webcam_image=faceDetect.detect(webcam_image);  
                 //-- 4. Display the image  
                  framePanel.MatToBufferedImage(webcam_image);   
                  framePanel.repaint();   
             }  
             else  
             {   
                  System.out.println(" Image is empty. Break!");   
                  break;   
             }
            t = ((double)Core.getTickCount() - t) / Core.getTickFrequency();
            System.out.println("FPS "+ 1000.0/t);
            }  
           }  
           return;  
    }

I also tried technique from this blog, but i get 0.00 fps.

Any suggestion or what technique i should use to solve the problem?