简体   繁体   中英

Write frames from camera to a single image in OpenCV

I am trying to grab frames from camera and add them into a single image to get the effect as in this image: http://www.danheller.com/images/California/DeathValley/Nite/tent-star-trails.jpg

But my image turns white after a couple of seconds. Here is the code:

#!/usr/bin/python
import cv
stream = cv.CaptureFromCAM(0)
cv.NamedWindow("Stream",1)
out = cv.CreateImage((640, 480), 8, 3)
while True:
  frame = cv.QueryFrame(stream)
  cv.Add(frame, out, out, None)
  cv.ShowImage("Stream", out)
  cv.WaitKey(25)

Can anyone help?

Yes, your image will turn white after a few frames because adding images pixel by pixel increases the brightness by quite a lot. You'll have to come up with a better algorithm to merge the images together.

One way you can do that is add the two images then normalize the resulting image before adding more images on, or if you're adding lots of frames, add only a small multiple (0.01) of the pixel value of the image to the resulting image each frame, but again, normalize the resulting image so dark pixels stay dark. This effectively simulates the long exposure effect that is created using real cameras.

Real cameras create that effect by having a very low exposure setting so only a few photons enter the lens at once, so when you leave the camera stationary for a while, more and more photos hit the film and eventually brightens up the picture. If you left the camera long enough. If you left the camera out for too long, the same thing will happen to the picture, it will go white. Adding pictures together directly is like having a very high exposure, lots of light enters the lens at once and the picture turns white.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM