1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
6
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
<title>pygame.camera — Pygame v1.9.2 documentation</title>
9
<link rel="stylesheet" href="../_static/pygame.css" type="text/css" />
10
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
11
<script type="text/javascript">
12
var DOCUMENTATION_OPTIONS = {
15
COLLAPSE_INDEX: false,
20
<script type="text/javascript" src="../_static/jquery.js"></script>
21
<script type="text/javascript" src="../_static/underscore.js"></script>
22
<script type="text/javascript" src="../_static/doctools.js"></script>
23
<link rel="shortcut icon" href="../_static/pygame.ico"/>
24
<link rel="top" title="Pygame v1.9.2 documentation" href="../index.html" />
25
<link rel="next" title="pygame.cdrom" href="cdrom.html" />
26
<link rel="prev" title="Pygame Front Page" href="../index.html" />
30
<div class="document">
36
<a href="http://www.pygame.org/">
37
<img src="../_static/pygame_tiny.png"/>
39
<h5>pygame documentation</h5>
41
<td class="pagelinks">
44
<a href="http://www.pygame.org/">Pygame Home</a> ||
45
<a href="../index.html">Help Contents</a> ||
46
<a href="../genindex.html">Reference Index</a> ||
49
<a href="camera.html">camera</a> ||
50
<a href="cdrom.html">cdrom</a> ||
51
<a href="color.html">Color</a> ||
52
<a href="cursors.html">cursors</a> ||
53
<a href="display.html">display</a> ||
54
<a href="draw.html">draw</a> ||
55
<a href="event.html">event</a> ||
56
<a href="examples.html">examples</a> ||
57
<a href="font.html">font</a> ||
58
<a href="freetype.html">freetype</a> ||
59
<a href="gfxdraw.html">gfxdraw</a> ||
60
<a href="image.html">image</a> ||
61
<a href="joystick.html">joystick</a> ||
62
<a href="key.html">key</a> ||
63
<a href="locals.html">locals</a> ||
64
<a href="mask.html">mask</a> ||
65
<a href="math.html">math</a> ||
66
<a href="midi.html">midi</a> ||
67
<a href="mixer.html">mixer</a> ||
68
<a href="mouse.html">mouse</a> ||
69
<a href="movie.html">movie</a> ||
70
<a href="music.html">music</a> ||
71
<a href="overlay.html">Overlay</a> ||
72
<a href="pixelarray.html">PixelArray</a> ||
73
<a href="pixelcopy.html">pixelcopy</a> ||
74
<a href="pygame.html">pygame</a> ||
75
<a href="rect.html">Rect</a> ||
76
<a href="scrap.html">scrap</a> ||
77
<a href="sndarray.html">sndarray</a> ||
78
<a href="sprite.html">sprite</a> ||
79
<a href="surface.html">Surface</a> ||
80
<a href="surfarray.html">surfarray</a> ||
81
<a href="tests.html">tests</a> ||
82
<a href="time.html">time</a> ||
83
<a href="transform.html">transform</a> ||
84
<a href="pygame.html#module-pygame.version">version</a>
91
<div class="documentwrapper">
94
<div class="sectionwrapper">
95
<div class="section" id="module-pygame.camera">
96
<span id="pygame-camera"></span><dl class="definition module">
97
<dt class="title module">
98
<tt class="docutils literal"><span class="pre">pygame.camera</span></tt></dt>
99
<dd><div class="line-block">
100
<div class="line"><span class="summaryline">pygame module for camera use</span></div>
102
<table border="1" class="toc docutils">
109
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.colorspace">pygame.camera.colorspace</a></td>
111
<td>Surface colorspace conversion</td>
113
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.list_cameras">pygame.camera.list_cameras</a></td>
115
<td>returns a list of available cameras</td>
117
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera">pygame.camera.Camera</a></td>
119
<td>load a camera</td>
123
<p>Pygame currently supports only Linux and v4l2 cameras.</p>
124
<p>EXPERIMENTAL!: This api may change or disappear in later pygame releases. If
125
you use this, your code will very likely break with the next pygame release.</p>
126
<p>The Bayer to <tt class="docutils literal"><span class="pre">RGB</span></tt> function is based on:</p>
127
<div class="highlight-python"><pre>Sonix SN9C101 based webcam basic I/F routines
128
Copyright (C) 2004 Takafumi Mizuno <taka-qce@ls-a.jp>
129
Redistribution and use in source and binary forms, with or without
130
modification, are permitted provided that the following conditions
132
1. Redistributions of source code must retain the above copyright
133
notice, this list of conditions and the following disclaimer.
134
2. Redistributions in binary form must reproduce the above copyright
135
notice, this list of conditions and the following disclaimer in the
136
documentation and/or other materials provided with the distribution.
137
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
138
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
139
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
140
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
141
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
142
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
143
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
144
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
145
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
146
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
149
<p>New in pygame 1.9.0.</p>
150
<dl class="definition function">
151
<dt class="title" id="pygame.camera.colorspace">
152
<tt class="descclassname">pygame.camera.</tt><tt class="descname">colorspace</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.colorspace" title="Permalink to this definition">¶</a></dt>
153
<dd><div class="line-block">
154
<div class="line"><span class="summaryline">Surface colorspace conversion</span></div>
155
<div class="line"><span class="signature">colorspace(Surface, format, DestSurface = None) -> Surface</span></div>
157
<p>Allows for conversion from “RGB” to a destination colorspace of “HSV” or
158
“YUV”. The source and destination surfaces must be the same size and pixel
159
depth. This is useful for computer vision on devices with limited processing
160
power. Capture as small of an image as possible, <tt class="docutils literal"><span class="pre">transform.scale()</span></tt> it
161
even smaller, and then convert the colorspace to <tt class="docutils literal"><span class="pre">YUV</span></tt> or <tt class="docutils literal"><span class="pre">HSV</span></tt> before
162
doing any processing on it.</p>
165
<dl class="definition function">
166
<dt class="title" id="pygame.camera.list_cameras">
167
<tt class="descclassname">pygame.camera.</tt><tt class="descname">list_cameras</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.list_cameras" title="Permalink to this definition">¶</a></dt>
168
<dd><div class="line-block">
169
<div class="line"><span class="summaryline">returns a list of available cameras</span></div>
170
<div class="line"><span class="signature">list_cameras() -> [cameras]</span></div>
172
<p>Checks the computer for available cameras and returns a list of strings of
173
camera names, ready to be fed into <a class="tooltip reference internal" href="#pygame.camera.Camera" title=""><tt class="xref py py-class docutils literal"><span class="pre">pygame.camera.Camera</span></tt><span class="tooltip-content">load a camera</span></a>.</p>
176
<dl class="definition class">
177
<dt class="title" id="pygame.camera.Camera">
178
<em class="property">class </em><tt class="descclassname">pygame.camera.</tt><tt class="descname">Camera</tt><a class="headerlink" href="#pygame.camera.Camera" title="Permalink to this definition">¶</a></dt>
179
<dd><div class="line-block">
180
<div class="line"><span class="summaryline">load a camera</span></div>
181
<div class="line"><span class="signature">Camera(device, (width, height), format) -> Camera</span></div>
183
<table border="1" class="toc docutils">
190
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera.start">pygame.camera.Camera.start</a></td>
192
<td>opens, initializes, and starts capturing</td>
194
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera.stop">pygame.camera.Camera.stop</a></td>
196
<td>stops, uninitializes, and closes the camera</td>
198
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera.get_controls">pygame.camera.Camera.get_controls</a></td>
200
<td>gets current values of user controls</td>
202
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera.set_controls">pygame.camera.Camera.set_controls</a></td>
204
<td>changes camera settings if supported by the camera</td>
206
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera.get_size">pygame.camera.Camera.get_size</a></td>
208
<td>returns the dimensions of the images being recorded</td>
210
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera.query_image">pygame.camera.Camera.query_image</a></td>
212
<td>checks if a frame is ready</td>
214
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera.get_image">pygame.camera.Camera.get_image</a></td>
216
<td>captures an image as a Surface</td>
218
<tr><td><a class="toc reference external" href="camera.html#pygame.camera.Camera.get_raw">pygame.camera.Camera.get_raw</a></td>
220
<td>returns an unmodified image as a string</td>
224
<p>Loads a v4l2 camera. The device is typically something like “/dev/video0”.
225
Default width and height are 640 by 480. Format is the desired colorspace of
226
the output. This is useful for computer vision purposes. The default is
227
<tt class="docutils literal"><span class="pre">RGB</span></tt>. The following are supported:</p>
230
<li><tt class="docutils literal"><span class="pre">RGB</span></tt> - Red, Green, Blue</li>
231
<li><tt class="docutils literal"><span class="pre">YUV</span></tt> - Luma, Blue Chrominance, Red Chrominance</li>
232
<li><tt class="docutils literal"><span class="pre">HSV</span></tt> - Hue, Saturation, Value</li>
235
<dl class="definition method">
236
<dt class="title" id="pygame.camera.Camera.start">
237
<tt class="descname">start</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.Camera.start" title="Permalink to this definition">¶</a></dt>
238
<dd><div class="line-block">
239
<div class="line"><span class="summaryline">opens, initializes, and starts capturing</span></div>
240
<div class="line"><span class="signature">start() -> None</span></div>
242
<p>Opens the camera device, attempts to initialize it, and begins recording
243
images to a buffer. The camera must be started before any of the below
244
functions can be used.</p>
247
<dl class="definition method">
248
<dt class="title" id="pygame.camera.Camera.stop">
249
<tt class="descname">stop</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.Camera.stop" title="Permalink to this definition">¶</a></dt>
250
<dd><div class="line-block">
251
<div class="line"><span class="summaryline">stops, uninitializes, and closes the camera</span></div>
252
<div class="line"><span class="signature">stop() -> None</span></div>
254
<p>Stops recording, uninitializes the camera, and closes it. Once a camera
255
is stopped, the below functions cannot be used until it is started again.</p>
258
<dl class="definition method">
259
<dt class="title" id="pygame.camera.Camera.get_controls">
260
<tt class="descname">get_controls</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.Camera.get_controls" title="Permalink to this definition">¶</a></dt>
261
<dd><div class="line-block">
262
<div class="line"><span class="summaryline">gets current values of user controls</span></div>
263
<div class="line"><span class="signature">get_controls() -> (hflip = bool, vflip = bool, brightness)</span></div>
265
<p>If the camera supports it, get_controls will return the current settings
266
for horizontal and vertical image flip as bools and brightness as an int.
267
If unsupported, it will return the default values of (0, 0, 0). Note that
268
the return values here may be different than those returned by
269
set_controls, though these are more likely to be correct.</p>
272
<dl class="definition method">
273
<dt class="title" id="pygame.camera.Camera.set_controls">
274
<tt class="descname">set_controls</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.Camera.set_controls" title="Permalink to this definition">¶</a></dt>
275
<dd><div class="line-block">
276
<div class="line"><span class="summaryline">changes camera settings if supported by the camera</span></div>
277
<div class="line"><span class="signature">set_controls(hflip = bool, vflip = bool, brightness) -> (hflip = bool, vflip = bool, brightness)</span></div>
279
<p>Allows you to change camera settings if the camera supports it. The
280
return values will be the input values if the camera claims it succeeded
281
or the values previously in use if not. Each argument is optional, and
282
the desired one can be chosen by supplying the keyword, like hflip. Note
283
that the actual settings being used by the camera may not be the same as
284
those returned by set_controls.</p>
287
<dl class="definition method">
288
<dt class="title" id="pygame.camera.Camera.get_size">
289
<tt class="descname">get_size</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.Camera.get_size" title="Permalink to this definition">¶</a></dt>
290
<dd><div class="line-block">
291
<div class="line"><span class="summaryline">returns the dimensions of the images being recorded</span></div>
292
<div class="line"><span class="signature">get_size() -> (width, height)</span></div>
294
<p>Returns the current dimensions of the images being captured by the
295
camera. This will return the actual size, which may be different than the
296
one specified during initialization if the camera did not support that
300
<dl class="definition method">
301
<dt class="title" id="pygame.camera.Camera.query_image">
302
<tt class="descname">query_image</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.Camera.query_image" title="Permalink to this definition">¶</a></dt>
303
<dd><div class="line-block">
304
<div class="line"><span class="summaryline">checks if a frame is ready</span></div>
305
<div class="line"><span class="signature">query_image() -> bool</span></div>
307
<p>If an image is ready to get, it returns true. Otherwise it returns false.
308
Note that some webcams will always return False and will only queue a
309
frame when called with a blocking function like <tt class="docutils literal"><span class="pre">get_image()</span></tt>. This is
310
useful to separate the framerate of the game from that of the camera
311
without having to use threading.</p>
314
<dl class="definition method">
315
<dt class="title" id="pygame.camera.Camera.get_image">
316
<tt class="descname">get_image</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.Camera.get_image" title="Permalink to this definition">¶</a></dt>
317
<dd><div class="line-block">
318
<div class="line"><span class="summaryline">captures an image as a Surface</span></div>
319
<div class="line"><span class="signature">get_image(Surface = None) -> Surface</span></div>
321
<p>Pulls an image off of the buffer as an <tt class="docutils literal"><span class="pre">RGB</span></tt> Surface. It can optionally
322
reuse an existing Surface to save time. The bit depth of the surface is
323
either 24bits or the same as the optionally supplied Surface.</p>
326
<dl class="definition method">
327
<dt class="title" id="pygame.camera.Camera.get_raw">
328
<tt class="descname">get_raw</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.camera.Camera.get_raw" title="Permalink to this definition">¶</a></dt>
329
<dd><div class="line-block">
330
<div class="line"><span class="summaryline">returns an unmodified image as a string</span></div>
331
<div class="line"><span class="signature">get_raw() -> string</span></div>
333
<p>Gets an image from a camera as a string in the native pixelformat of the
334
camera. Useful for integration with other libraries.</p>
346
<div class="clearer"></div>
348
<div class="related">
351
<li class="right" style="margin-right: 10px">
352
<a href="../genindex.html" title="General Index"
353
accesskey="I">index</a></li>
355
<a href="cdrom.html" title="pygame.cdrom"
356
accesskey="N">next</a> |</li>
358
<a href="../index.html" title="Pygame Front Page"
359
accesskey="P">previous</a> |</li>
360
<li><a href="../index.html">Pygame v1.9.2 documentation</a> »</li>
361
<script type="text/javascript" src="jquery.plugin.docscomments.js"></script>
366
© Copyright 2011, Pygame Developers.
b'\\ No newline at end of file'