Use Python and cameras to create simple Time-Delay photography and python camera latency

Source: Internet
Author: User

Use Python and cameras to create simple Time-Delay photography and python camera latency

"Delayed photography (English: Time-lapse photography) is a photography technique that uses normal or fast speed to play pictures at a low frame rate or video. In a delayed photography video, the process of slow changes of objects or scenes is compressed into a short period of time, showing a strange and wonderful scene that cannot be noticed by the naked eye at ordinary times. Delayed photography can be considered as a process opposite to high-speed photography. Delayed photography is usually applied to shooting urban scenery, natural scenery, astronomical phenomena, biological evolution, and other theme ."

-- Imported from Baidu encyclopedia

Grass Planting

Recently, I got a small gift for shopping. It was a fast-growing grass. I got it back and got it on my desk. Today, I plan to create a delayed photography. There is a very old 640xlarge camera in the office, so I have the following delayed photography animation (to upload and compress the image size):

1 import cv2 2 2 import time 3 4 interval = 20 # seconds 5 num_frames = 500 6 out_fps = 24 7 8 capture = cv2.VideoCapture (0) 9 size = (int (capture. get (cv2.cv. CV_CAP_PROP_FRAME_WIDTH), 10 int (capture. get (cv2.cv. CV_CAP_PROP_FRAME_HEIGHT) 11 video = cv2.VideoWriter ("time_lapse.avi", cv2.cv. CV_FOURCC ('I', '4', '2', '0'), out_fps, size) 12 13 # for low quality webcams, discard the starting unstable frames14 for I in xrange (42): 15 capture. read () 16 17 # capture frames to video18 for I in xrange (num_frames): 19 _, frame = capture. read () 20 video. write (frame) 21 22 # Optional, in case you need the frames for GIF or so23 filename = '{: 42.16.png '. format (I ). replace ('', '0') 24 cv2.imwrite (filename, frame) 25 26 print ('frame {} is captured. '. format (I) 27 time. sleep (interval) 28 29 video. release () 30 capture. release ()

Since it is a simple, delayed photography, the Code is also very simple. Set the shooting interval, the total number of frames, and the output frame rate. Use VideoCapture to get the image of the camera, and use VideoWriter to write the video, considering that some inferior cameras are unstable during initialization (for example, the old-fashioned camera I used), you can consider skipping the initial dozens of frames when capturing the image, during the capture process, you can also directly output images for easy GIF or other purposes.

Finally, the whole process of evaporation from water drops in an iron case is as follows:

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.