Ask Your Question
0

How to represent 1 image using 10 frames?

asked 2017-02-05 01:22:40 -0600

Nuz gravatar image

updated 2017-02-05 01:33:50 -0600

I have been able to find the fps of a 6 sec video and it gives me 25 fps. However, to keep 150 frames is too heavy. How can I use 10 frames to represent 1 image, thus, giving me only 15 images to store? Any piece of code would be of great help.. Here is my code to find fps:

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

 using namespace cv;
  using namespace std;

  int main(int argc, char* argv[])
     {
VideoCapture cap("C:/Users/Desktop/Movements/Passing/2.outside of the foot.mp4");                                  
if (!cap.isOpened())  // if not success, exit program
{
    cout << "Cannot open the video file" << endl;
    return -1;
}

//cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

cout << "Frame per seconds : " << fps << endl;

namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

while (1)
{
    Mat frame;

    bool bSuccess = cap.read(frame); // read a new frame from video

    if (!bSuccess) //if not success, break loop
    {
        cout << "Cannot read the frame from video file" << endl;
        break;
    }

    imshow("MyVideo", frame); //show the frame in "MyVideo" window

    if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }
}

return 0;

    }
edit retag flag offensive close merge delete

Comments

what is your problem?

LBerger gravatar imageLBerger ( 2017-02-05 02:16:06 -0600 )edit

I want to know how to use 10 frames to represent 1 image, i don't have an idea how to do it..need help @LBerger

Nuz gravatar imageNuz ( 2017-02-05 03:05:57 -0600 )edit

I don't understand what you want exactly. may be you can try addWeighted to cumulate 10 frames in one or take only 2.5 frame per second :

bool bSuccess = cap.read(frame)
i++
if (i%10==0)
      fmyFrame[j++]=frame.clone();
LBerger gravatar imageLBerger ( 2017-02-05 07:10:11 -0600 )edit

@LBerger Actually, i want to extract frames at a rate of say 8 fps..thus, having lesser frames in my database, how could it be done? Can you please help?

Nuz gravatar imageNuz ( 2017-02-05 09:22:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-05 09:37:13 -0600

LBerger gravatar image

updated 2017-02-05 09:43:30 -0600

you can skip some frames in the video file. if ratio is 0 you keep all frames ratio equal 1/2 ratio =3 1/4... ratio 9 1/10

int main(int argc, char* argv[])
{
VideoCapture cap("C:/Users/Desktop/Movements/Passing/2.outside of the foot.mp4");                                  
if (!cap.isOpened())  // if not success, exit program
{
    cout << "Cannot open the video file" << endl;
    return -1;
}

//cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms
double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
cout << "Frame per seconds : " << fps << endl;
namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
int nbFrame=0;
int ratio=9;
vector<Mat> selectedFrame;
while (1)
{
    Mat frame;

    bool bSuccess = cap.read(frame); // read a new frame from video
    nbFrame++;
    if (!bSuccess) //if not success, break loop
    {
        cout << "Cannot read the frame from video file" << endl;
        break;
    }
    if (nbFrame==ratio)
    {
          selectedframe.push_back(frame.clone());
          nbFrame=0;
    }
    else
          nbFrame++;
    imshow("MyVideo", frame); //show the frame in "MyVideo" window

    if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }
}
return 0;
}
edit flag offensive delete link more

Comments

@LBerger thank you..is it possible to use IplImage to grab the frames?

Nuz gravatar imageNuz ( 2017-02-05 10:32:04 -0600 )edit

Which version do you use ? lpIImage is old API you should'nt use it

LBerger gravatar imageLBerger ( 2017-02-05 10:43:29 -0600 )edit

@LBerger opencv 3.0 Ok..so i should use the one that skip the frames

Nuz gravatar imageNuz ( 2017-02-05 10:59:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-05 01:22:40 -0600

Seen: 238 times

Last updated: Feb 05 '17