|
eLeSDenes
Mycelium Expander
Registered: 05/25/11
Posts: 955
Last seen: 6 days, 2 hours
|
Timelapse tek - with a Raspberry Pi and a webcam 9
#26351786 - 11/29/19 10:51 AM (4 years, 3 months ago) |
|
|
Hello everyone,
Not sure if there are methods for this posted here or not, but I thought many of you want to take timelapse type videos to create gifs. It not just lets you to view the shroom how it grows but it also looks more interesting than static images. There exists many professional setups for this, but here I present you a very cheap and simple solution. You only need a Raspberry Pi (any model will do, I used a really old one) and a webcam. The setup for petri dish timelapse:
The setup for mono timelapse:
If your raspberry pi is setup, connect it to your network and you can use ssh to login. You can do that from a terminal (if you have Mac or Linux) or use PuTTY on windows. To open an ssh connection, open the terminal and type: ssh pi@IP_ADDRESS_OF_PI. Then, you need to install opencv and screen. In terminal type:
- sudo apt-get install libopencv-dev
- sudo apt-get install screen
These 2 commands will install the necessary packages to run the program. Then, create a folder for the program, name it something like timelapse_video. To do this enter in terminal : mkdir timelapse_video. Then to change to that folder : cd timelapse_video. Now we have to create the program. You can use your favourite text editor if you have any or just use vim. In terminal type: vi timelapse.py This will create a file and open the editor. Copy paste the following:
import cv2 import time import sys
#reading command line arguments a = float(sys.argv[1]) b = float(sys.argv[2]) c = int(sys.argv[3])
# initialize the camera cam = cv2.VideoCapture(c)
number_of_days = a # number of days to run snapshot_frequency = b # number of seconds to wait before taking the next image total_seconds_run = 86400 * number_of_days number_of_iterations = int(total_seconds_run/snapshot_frequency)
for i in range(0,number_of_iterations) : #read camera ret, image = cam.read()
#if camera was successfully read if ret:
#get epoch time in seconds seconds = time.time()
#the file name will be S_ + the epoch time to have different filenames filestring = 'S_' + str(seconds) + '.jpg' cv2.imwrite(filestring,image)
#sleep until the next timestep time.sleep(snapshot_frequency)
cam.release()
To save the program press ESC and type :wq (with the colon) To start the program you will use this general form : python timelapse.py <number_of_days_to_run> <time_interval_in_seconds> <camera_number>. So let's say you want to run it for 5 days and want to snap an image in every half an hour you type: python timelapse.py 5 1800 0 which will run it with camera '0'. If you have multiple cameras attached via usb, you can start the program specifying the camera number.
we are also going to use 'setsid' to run the process in the background. To do this, in terminal type: setsid python timelapse.py 5 1800 0 to run the timelapse program in the background You can check your running process with (terminal) : ps -ef | grep timelapse which will give a process ID just in case you need to terminate the program just type: kill <process_id>
This program will create images in given time intervals you so you will have lots of images. You can use any gif-maker to stitch these to video and gifs.
Some examples of the recording:
Isolation of PE
Mycelium under microscope
B+
LPEU
Rusty Whyte
I hope I did not make it complicated and if you have any problem setting this up, just let me know.
Edited by eLeSDenes (03/28/21 04:45 AM)
|
bodhisatta
Smurf real estate agent
Registered: 04/30/13
Posts: 61,891
Loc: Milky way
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: eLeSDenes]
#26351801 - 11/29/19 11:05 AM (4 years, 3 months ago) |
|
|
I use magic lantern firmware on my camera
|
filthyknees
no coincidence
Registered: 03/08/13
Posts: 6,283
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: eLeSDenes]
#26351838 - 11/29/19 11:27 AM (4 years, 3 months ago) |
|
|
Nice thread
-------------------- But if you're in a hurry, and really got to go If you're in a hurry, might have to find out slow That it's one thing to try and another to fly You get there quicker just a step at a time It's one thing to bark, another to bite The show ain't over till you pack up at night
|
StygianKnight
A Mushroom
Registered: 03/12/12
Posts: 2,717
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: filthyknees]
#26351852 - 11/29/19 11:39 AM (4 years, 3 months ago) |
|
|
Awesome! This will come in handy.
For those with old school DSLR cameras, you can get a Timer Shutter release remote for $10-$20 that can be set to take a picture every time interval. The downside though is unless you have a wireless card, the only way to see your progress on camera is to touch it and possibly mess up its position. The webcam option above means you can watch the progress in ‘real time’ without needing to touch anything.
|
bodhisatta
Smurf real estate agent
Registered: 04/30/13
Posts: 61,891
Loc: Milky way
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: StygianKnight]
#26351860 - 11/29/19 11:44 AM (4 years, 3 months ago) |
|
|
Look into magic lantern for any DSLR it will do it automatically.
Edit, Looks like Canon only
|
eLeSDenes
Mycelium Expander
Registered: 05/25/11
Posts: 955
Last seen: 6 days, 2 hours
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: StygianKnight]
#26351869 - 11/29/19 11:49 AM (4 years, 3 months ago) |
|
|
Quote:
StygianKnight said: Awesome! This will come in handy.
For those with old school DSLR cameras, you can get a Timer Shutter release remote for $10-$20 that can be set to take a picture every time interval. The downside though is unless you have a wireless card, the only way to see your progress on camera is to touch it and possibly mess up its position. The webcam option above means you can watch the progress in ‘real time’ without needing to touch anything.
Exactly, I just use Filezilla to pull the images it made. In the future, I will also check how many cameras it is possible to control simultaneously so more things can be recorded.
|
Krip
Garbage Decomposer
Registered: 05/27/18
Posts: 50
Loc: Underground
Last seen: 4 months, 11 days
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: eLeSDenes] 2
#26402235 - 12/26/19 10:08 PM (4 years, 3 months ago) |
|
|
The code is wrong! You skipped an identation in Quote:
time.sleep(snapshot_frequency)
So it would shoot all the photos at the same time, wait, and end the script. Code should be:
import cv2 import time import sys
# initialize the camera cam = cv2.VideoCapture(0)
# reading command line arguments number_of_days = float(sys.argv[1]) # number of days to run snapshot_frequency = float(sys.argv[2]) # number of seconds to wait before taking the next image
# calculating iterations total_seconds_run = 86400 * number_of_days number_of_iterations = int(total_seconds_run/snapshot_frequency)
for i in range(0,number_of_iterations): #read camera ret, image = cam.read()
#if camera was successfully read if ret: #get epoch time in seconds seconds = time.time()
# file name = S_ + the epoch time --> have different filenames filestring = 'S_' + str(seconds) + '.jpg' cv2.imwrite(filestring,image)
# sleep until the next timestep time.sleep(snapshot_frequency)
cam.release()
I modified a little bit the code so it could be shorter, no change in functionality. Nice post!
-------------------- Alea iacta est.
Edited by Krip (12/26/19 10:09 PM)
|
eLeSDenes
Mycelium Expander
Registered: 05/25/11
Posts: 955
Last seen: 6 days, 2 hours
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: Krip] 1
#26402483 - 12/27/19 04:54 AM (4 years, 3 months ago) |
|
|
Hey man,
Thanks good catch, edited it! It was indented but for some reason it was not visible here, but I am happy that you spotted it, as it would break the program for anyone trying to use it.
|
Krip
Garbage Decomposer
Registered: 05/27/18
Posts: 50
Loc: Underground
Last seen: 4 months, 11 days
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: eLeSDenes]
#26407117 - 12/30/19 01:14 AM (4 years, 2 months ago) |
|
|
Clearly it was a post typo/error, i just posted it so you could check it and fix it in the original post . It would be great to have a functionality to post code, i know it's a lot to ask though, it's a mycology forum after all!
Nice idea by the way, loved it, will probably make some timelapse using this tek. Love 2 u <3
-------------------- Alea iacta est.
|
YogiBear
Registered: 08/24/19
Posts: 845
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: eLeSDenes]
#26407174 - 12/30/19 02:38 AM (4 years, 2 months ago) |
|
|
Great work! 👍🍿😎
|
Marmot
Stranger
Registered: 10/06/21
Posts: 1
Last seen: 2 years, 2 months
|
Re: Timelapse tek - with a Raspberry Pi and a webcam [Re: eLeSDenes]
#27571245 - 12/06/21 11:02 AM (2 years, 3 months ago) |
|
|
I really appreciate this
|
|