2
pygame module for camera use
4
Pygame currently supports only Linux and v4l2 cameras.
6
EXPERIMENTAL!: This api may change or disappear in later
7
pygame releases. If you use this, your code will very likely
8
break with the next pygame release.
12
The Bayer to RGB function is based on:
13
Sonix SN9C101 based webcam basic I/F routines
14
Copyright (C) 2004 Takafumi Mizuno <taka-qce@ls-a.jp>
16
Redistribution and use in source and binary forms, with or without
17
modification, are permitted provided that the following conditions
19
1. Redistributions of source code must retain the above copyright
20
notice, this list of conditions and the following disclaimer.
21
2. Redistributions in binary form must reproduce the above copyright
22
notice, this list of conditions and the following disclaimer in the
23
documentation and/or other materials provided with the distribution.
25
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42
Surface colorspace conversion
43
pygame.camera.colorspace(Surface, format, DestSurface = None): return Surface
45
Allows for conversion from "RGB" to a destination colorspace of "HSV" or "YUV".
46
The source and destination surfaces must be the same size and pixel depth.
47
This is useful for computer vision on devices with limited processing power.
48
Capture as small of an image as possible, transform.scale() it even smaller,
49
and then convert the colorspace to YUV or HSV before doing any processing on it.
53
returns a list of available cameras
54
pygame.camera.list_cameras(): return [cameras]
56
Checks the computer for available cameras and returns a list of strings of
57
camera names, ready to be fed into pygame.camera.Camera.
62
pygame.camera.Camera(device, (width, height), format): return Camera
64
Loads a v4l2 camera. The device is typically something like "/dev/video0".
65
Default width and height are 640 by 480. Format is the desired colorspace of
66
the output. This is useful for computer vision purposes. The default
67
is RGB. The following are supported:
69
* RGB - Red, Green, Blue
70
* YUV - Luma, Blue Chrominance, Red Chrominance
71
* HSV - Hue, Saturation, Value
76
opens, initializes, and starts capturing
77
Camera.start(): return None
79
Opens the camera device, attempts to initialize it, and begins recording
80
images to a buffer. The camera must be started before any of the below
81
functions can be used.
86
stops, uninitializes, and closes the camera
87
Camera.stop(): return None
89
Stops recording, uninitializes the camera, and closes it. Once a camera
90
is stopped, the below functions cannot be used until it is started again.
95
gets current values of user controls
96
Camera.get_controls(): return (hflip = bool, vflip = bool, brightness)
98
If the camera supports it, get_controls will return the current settings for
99
horizontal and vertical image flip as bools and brightness as an int. If
100
unsupported, it will return the default values of (0, 0, 0).
101
Note that the return values here may be different than those returned by
102
set_controls, though these are more likely to be correct.
106
changes camera settings if supported by the camera
107
Camera.set_controls(hflip = bool, vflip = bool, brightness): return (hflip = bool, vflip = bool, brightness)
109
Allows you to change camera settings if the camera supports it. The return
110
values will be the input values if the camera claims it succeeded or the values
111
previously in use if not. Each argument is optional, and the desired one
112
can be chosen by supplying the keyword, like hflip. Note that the actual
113
settings being used by the camera may not be the same as those returned by
119
returns the dimensions of the images being recorded
120
Camera.get_size(): return (width, height)
122
Returns the current dimensions of the images being captured by the camera.
123
This will return the actual size, which may be different than the one
124
specified during initialization if the camera did not support that size.
128
checks if a frame is ready
129
Camera.query_image(): return bool
131
If an image is ready to get, it returns true. Otherwise it returns false. Note
132
that some webcams will always return False and will only queue a frame when
133
called with a blocking function like get_image(). This is useful to
134
separate the framerate of the game from that of the camera without having to
140
captures an image as a Surface
141
Camera.get_image(Surface = None): return Surface
143
Pulls an image off of the buffer as an RGB Surface. It can optionally reuse an
144
existing Surface to save time. The bit depth of the surface is either 24bits or
145
the same as the optionally supplied Surface.
150
returns an unmodified image as a string
151
Camera.get_raw(): return string
153
Gets an image from a camera as a string in the native pixelformat of the camera.
154
Useful for integration with other libraries.