Using the camera in Python to achieve a simple time-lapse photographic technique _python

Source: Internet
Author: User
Tags in python

Time-lapse photography (English: Time-lapse photography) is a camera that takes pictures or videos at a lower frame rate and then plays the picture at a normal or faster rate. In a time-lapse photographic video, the process of slow changes in objects or scenes is compressed into a shorter period of time, presenting a bizarre and wonderful sight that is usually imperceptible to the unaided eye. Time-lapse photography can be considered as a process contrary to high speed photography. Time-lapse photography is often used to shoot urban landscapes, natural landscapes, astronomical phenomena, biological evolution and so on. ”

Plant grass

Recently bought things got a small gift, is a kind of fast growing grass, get back on the plant on the desk. Today germination, a whim to do a time delay photography, the office just has a very old 640x480 camera, so there is the following delay photography (in order to upload compressed screen size):

Realize


to be prepared for:

1) Computer
2 The camera (if the computer does not), Taobao a lot of 20 below the package of mail
3 Python 2.7, because of the need to use OPENCV, so use Python2
4 OpenCV python binding, to the official online download, if you do not want to compile, as long as the \build\python\2.7\ below can find 32-bit and 64-bit cv2.pyd, the file directly copied to the \python27\lib\ Site-packages\ can

The code is as follows:

Import cv2
import time

interval =  # seconds
num_frames = Out_fps
= Capture =

. Videocapture (0)
size = (int (capture.get (Cv2.cv.CV_CAP_PROP_FRAME_WIDTH)),
    Int (capture.get cv2.cv.CV_CAP_ prop_frame_height))) Video
= Cv2. Videowriter ("Time_lapse.avi", Cv2.cv.CV_FOURCC (' I ', ' 4 ', ' 2 ', ' 0 '), out_fps, size)

# for low quality webcams, Discard the starting unstable frames for
I in Xrange (a):
  capture.read ()

# capture frames to video
fo R i in Xrange (num_frames):
  _, frame = Capture.read ()
  video.write (frame)

  # # Optional, in case for you need the F Rames for GIF or
  so filename = ' {: 4}.png '. Format (i)-replace (', ' 0 ')
  cv2.imwrite (filename, frame)

  print (' Frame {} is captured. '. Format (i))
  time.sleep (interval)

video.release ()
capture.release ()



Since it is a simple time-lapse photography, the code is also very simple. Set the shooting interval, the total frame number and the output frame rate, use videocapture to get the camera image, write the video with Videowriter, taking into account that some of the inferior camera in the initialization of the unstable (such as I used this vintage camera), In the formal capture chart forward you can consider skipping the initial dozens of frames, the capture process can also directly output pictures to facilitate the production of GIF or other purposes.

And finally, the whole process of droplet evaporation on a tin box:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.