On 06/21/2012 02:53 PM, [email protected] wrote:
>
> Can anyone give me a bit of advice ... I'm trying to set up a webcam.
> When I connect to the camera using cheese, lucview or xcam, the
> picture is black for the first few frames, and gradually adjusts until
> the picture is visible.
>
> v4lctl snap gives me a black picture.
>
> I suspect that during the first few frames after opening the device the
> camera is doing some auto-exposure adjustment.
>
> Is there any way anyone knows of getting a picture (programmatically)
> and allowing the camera to adjust its aperture/shutter speed or
> whatever it does? I've tried webcam and webcamd but they just deliver
> black pictures.
>
> The obvious attempt to take two pictures in a row gives two black
> pictures.
>
> $ v4lctl snap jpeg 320x240; v4lctl snap jpeg 320x240
>
They are mainly designed for video, so yep they will do that..
You could use v4l2-ctl to find the exposure setting and set it manually.
But I have found that when a program "opens" the camera it will
sometimes have its settings reset to default.
Otherwise, you could try the pygame camera library and discard the first
half-dozen frames.
http://www.pygame.org/docs/ref/camera.html
I attached a short script which takes 10 frames and saves as jpg, it
needs a couple of python libraries which should be in any distro.
On Ubuntu/Debian it's:
apt-get install python-imaging python-pygame
--
Felix
import pygame, sys
import pygame.camera
from pygame.locals import *
import Image
import time
camresolutions = (
(320, 240),
(352, 288),
(640, 480),
(800, 600),
(960, 544),
(1024, 768),
(1280, 720),
)
screenres = (1440,920)
camres = camresolutions[2]
CAMERA_DEVICE = '/dev/video0'
pygame.init()
pygame.camera.init()
screen = pygame.display.set_mode(
screenres,
#pygame.FULLSCREEN |
pygame.DOUBLEBUF |
pygame.HWSURFACE )
cam = pygame.camera.Camera(CAMERA_DEVICE, camres)
cam.start()
for i in range(10):
time.sleep(1)
image = cam.get_image()
screen.blit(image, (20, 20))
pygame.display.flip()
imgstring = pygame.image.tostring(image, "RGB")
PILimg = Image.fromstring("RGB", camres, imgstring)
PILimg.save("camimage.%03d.jpg" % i)
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html