sudo44
Posts: 2
Joined: Sat Mar 02, 2019 5:04 am

store image raspberry pi - c language

Sat Mar 02, 2019 5:19 am

Hi, I am new to this forum and I am also new to raspberry pi. I am programming in C language.

I built this little system that is comprised of a pir sensor and a camera. Basically when the pir sensor picks up some motion it commands the camera to take picture.

I have a problem with the storing the pictures taken by the camera. Every time it takes a pictures it deletes the old one and replaces it with the new one. I want to store all the pictures taken by the camera.

The code below is what I am executing to store the pictures. Someone help.

system("raspistill -vf -hf -o /home/pi/Desktop/Camera.pig");

Remember my code is in C language

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: store image raspberry pi - c language

Sat Mar 02, 2019 2:48 pm

You are asking "raspistill" to use the same name every time so it should not be a surprise that it overwrites the file.

I see two quite simple ways..
- You either change the string used as parameter to sytem() every time. ( clue: snprintf() )
- Or you rename the file to a unique name before capturing again. ( clue: http://man7.org/linux/man-pages/man2/rename.2.html )

jahboater
Posts: 5825
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: store image raspberry pi - c language

Sat Mar 02, 2019 2:55 pm

topguy wrote:
Sat Mar 02, 2019 2:48 pm
- You either change the string used as parameter to system() every time. ( clue: snprintf() )
See also strftime() (man strftime)
So you could incorporate a data/time stamp into each file name.

Return to “Beginners”