# Trying to make a time lapse but camera capturing too fast

**URL:** <https://forum.opencv.org/t/trying-to-make-a-time-lapse-but-camera-capturing-too-fast/3133>\
**Category:** Uncategorized\
**Created:** [May 4, 2021, 5:15pm UTC](https://forum.opencv.org/t/trying-to-make-a-time-lapse-but-camera-capturing-too-fast/3133 "2021-05-04T17:15:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandrian1](https://avatars.discourse-cdn.com/v4/letter/c/d78d45/32.png) [@chandrian1](https://forum.opencv.org/u/chandrian1)\
**Post date:** [May 4, 2021, 5:15pm UTC](https://forum.opencv.org/t/trying-to-make-a-time-lapse-but-camera-capturing-too-fast/3133/1 "2021-05-04T17:15:52Z")

</div>

My images are coming in a few milliseconds after another even with a long delay. I am using a for loop with a delay and then I am using other software to convert the type.

 ![2021-05-04-111416_1920x1080_scrot](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/2/2bade9b7c8e953af0b4b7a384a23dbab51bdc329.jpeg)

```
#include <opencv2/core.hpp>

```

#include \<opencv2/highgui.hpp\>  
#include \<opencv2/videoio.hpp\>  
#include \<stdio.h\>  
#include   
#include \<string.h\>  
#include \<unistd.h\>

using namespace cv;  
using namespace std;

int main( int argc, char\*\* argv )  
{  
cv::namedWindow(“Capture Example”,cv::WINDOW\_AUTOSIZE);  
cv::VideoCapture capture(0);

capture.set(CAP\_PROP\_FRAME\_HEIGHT,480);  
capture.set(CAP\_PROP\_FRAME\_WIDTH,720);

cout \<\< “helloworld” \<\< endl;

struct timespec start;  
struct timespec delay\_time = {1,0};  
struct timespec remaining\_time;  
clock\_gettime(CLOCK\_MONOTONIC, &start);

```
string filename;
string jpg = ".jpg";
string ppm = ".ppm";
string space = " ";
string command;
cv::Mat frame;

```

for(int i=0; i\<5; i++)  
{

```
bool ret = capture.read(frame);

if(!ret) break;

cv::imshow("Capture Example", frame);
char c = cv::waitKey(33);
if( c == 27 ) break;

filename = "image_";
filename += to_string(i);
    
cout << "hell world" << filename << endl;

imwrite(filename + jpg, frame);

command = "convert " + filename + jpg + space + filename + ppm;

cout << "shell world" << command << endl;

system(command.c_str());
sleep(3);
//nanosleep(&delay_time, &remaining_time);

```

}

struct timespec end;

clock\_gettime(CLOCK\_MONOTONIC, &end);

long time = end.tv\_nsec - start.tv\_nsec;

cout \<\< “helloworld” \<\< time \<\< endl;

}

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [May 4, 2021, 7:03pm UTC](https://forum.opencv.org/t/trying-to-make-a-time-lapse-but-camera-capturing-too-fast/3133/2 "2021-05-04T19:03:30Z")

</div>

discard frames or blend them. for a timelapse, I would **highly recommend** blending frames. that simulates a long exposure time. blending means adding/averaging. create a matrix of type CV\_32FC3 or CV\_32UC3 or similar, add frames on top, divide by number at the end.

the camera makes frames to its own fixed frequency (frames per second).

it doesn’t care if you try to throttle that. the frames will just queue up.

as you see, you can’t simply delay this.

---

<div class="post-metadata">

**Author:** ![chandrian1](https://avatars.discourse-cdn.com/v4/letter/c/d78d45/32.png) [@chandrian1](https://forum.opencv.org/u/chandrian1)\
**Post date:** [May 4, 2021, 8:36pm UTC](https://forum.opencv.org/t/trying-to-make-a-time-lapse-but-camera-capturing-too-fast/3133/3 "2021-05-04T20:36:09Z")

</div>

Thank you for the feedback. The difficult part is the requirement that I have to take an image every second with little error. I can fill a buffer and see how fast they are coming in and only take every (ig) 30th sample maybe?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [May 5, 2021, 6:19am UTC](https://forum.opencv.org/t/trying-to-make-a-time-lapse-but-camera-capturing-too-fast/3133/4 "2021-05-05T06:19:49Z")

</div>

you can `set` the frame rate (FPS), same as you set the width and height properties of the VideoCapture.

read it back (`get`) to make sure the device accepted the value.
