-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
index.html
608 lines (478 loc) · 20.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Webcam Capture in Java</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="javascripts/main.js"></script>
<script src="examples/google-code-prettify/prettify.js"></script>
<link rel="stylesheet" href="examples/google-code-prettify/sons-of-obsidian-2.css">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>
<body>
<a href="https://github.com/sarxos/webcam-capture"><img style="position: absolute; top: 0; right: 0; border: 0; z-index: 100;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
<header>
<h1>Webcam Capture</h1>
<p>Generic Webcam Java Utility</p>
</header>
<div id="banner">
<span id="logo"></span>
<a href="https://github.com/sarxos/webcam-capture" class="button fork"><strong>GitHub</strong></a>
<div class="downloads">
<span>Download:</span>
<ul>
<li><a href="http://repo.sarxos.pl/maven2/com/github/sarxos/webcam-capture/0.3.8/webcam-capture-0.3.8-dist.zip" class="button">ZIP</a></li>
</ul>
</div>
</div><!-- end banner -->
<div class="wrapper">
<nav>
<ul></ul>
</nav>
<section>
<h1>Webcam Capture</h1>
<p>
The goal of this project is to provide really simple webcam API allowing you to use your
build-in, external (USB-connected) webcams or IP / network cameras directly from Java code.
It provides basic webcam
interface and a set of additional <i>drivers</i> which can be used to replace default build-in
drivers to extend and/or replace default functionality.
</p>
<p>Continous Integration build status (Travis CI):</p>
<p>
<a href="http://travis-ci.org/sarxos/webcam-capture"><img src="https://secure.travis-ci.org/sarxos/webcam-capture.png?branch=master" alt="Build Status" title="" /></a>
</p>
<a class="anchor" name="requirements"></a>
<h3>Requirements</h3>
<p>
<ul>
<li>Java 6 (or higher) installed,</li>
<li>Webcam connected and configured,</li>
<li>In case of IP / network cameras, Internet access is required,</li>
</ul>
</p>
<a class="anchor" name="core-features"></a>
<h3>Core Features</h3>
<p>
<ul>
<li><b>Simple and thread-safe API</b> - write only few lines of code is enough to start capturing images.</li>
<li><b>Standalone</b> - no additional software has to be installed to use it.</li>
<li><b>System independent</b> - it will run without problems on most widely used operating systems - Windows (2k/XP/Vista/7, both 32- and 64-bit), Linux (x86, x64), ARM devices (e.g. Raspberry Pi at Arch Linux), and Mac OS X.</li>
<li><b>Implementation independent</b> - write your code once and if you find better driver in future, just wrap it in WebcamDriver class and don't care about any code changes.</li>
<li><b>Resources management</b> - you do not have to remember to deallocate resources used by your capturing device, library will always do that for you.</li>
<li><b>Motion detector</b> - build in motion detector makes it easy to implement motion detecting features.</li>
<li><b>Available from Maven Central</b> - it is available in Maven Central and therefore will not suddenly disappear.</li>
<li><b>Re-streamer</b> - simple JPEG/MJPEG re-streamer is build in, just run it and enjoy hosting your live stream.</li>
<li><b>Swing ready</b> - contains Swing component to display images, together with painter API and thread-safe API which prevents Swing EDT from blocking issues when using camera.</li>
</ul>
</p>
<a class="anchor" name="contribute"></a>
<h2>Contribute</h2>
<p>
If you have spare time, knownledge or even some small money amount
to spent, you can help developing awesome Webcam Capture API and make
it even better! Several kinds of contributions are very welcome:
</p>
<p>
<ul>
<li><b>Report</b> - if you've found a bug or you've came-up with
some fantastic feature which
can make Webcam Capture a better API to use, don't hesitate to
<a href="https://github.com/sarxos/webcam-capture/issues/new">create new issue</a>
where you can describe in details what the problem is, or what would you
like to improve.</li>
<li><b>Test</b> - since Webcam Capture use native code, it's very
hard to cover all supported operating systems. I'm always testing it
on 64-bit Ubuntu Linux, Windows XP and Vista (both 32-bit), but I
have no possibility to test on Raspberry Pi, Mac OS and 32-bit Linux.</li>
<li><b>Code</b> - if you know Java or C++ you can help developing
Webcam Capture by <a href="https://github.com/sarxos/webcam-capture">forking repository</a>
and sending pull requests. </li>
<li><b>Donate</b> - people have expressed a wish to donate a little
money. Donating won't get you anything special, other than a warm
feeling inside, and possibly urge me to produce more freely
available material for Webcam Capture project. You can
donate via PayPal by sending money to songo.bercik@interia.pl, or
by the donation button below.<br/><br/>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="UYMENK76CSYZU">
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/pl_PL/i/scr/pixel.gif" width="1" height="1">
</form>
</li>
</ul>
</p>
<a class="anchor" name="how-to-start"></a>
<h2>How To Start</h2>
<p>
<i>Webcam Capture</i> is avilable in Maven Central, so if you can add its dependency to your
project if you are using one of the dependency manager:
</p>
<h3>Maven</h3>
<pre class="prettyprint prettyprinted language-xml linenums">
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>0.3.8</version>
</dependency>
</pre>
<h3>No Dependency Manager?</h3>
<p>
Download ZIP file containing complete API reference, required JARs, sources and examples
(link is visible at the right top corner of this page), uncompress, and add <i>webcam-capture-[version].jar</i>
and all JARs under <i>libs</i> directory to your project's classpath:
</p>
<h2>Additional Drivers</h2>
<p>
Currently <i>Webcam Capture</i> supports the following drivers:
</p>
<h3>IP / Network Camera Driver</h3>
<p>
This is IP camera driver for Webcam Capture project. It allows Webcam Capture to
handle pictures from IP cameras supporting JPEG and MJPEG (Motion JPEG) compression.
For more information about supported models, how to extend, examples, use-cases, please
follow to the Github project available <b><a href="https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-driver-ipcam">here</a></b>.
</p>
<p>
This driver is available in Maven Central.
</p>
<h3>JMF / FMJ Driver</h3>
<p>
This is driver containing video grabber for Webcam Capture project. It utilizes JMF
capabilities to access PC webcam (those USB-connected too) and can be used as a replacement
for default build-in driver. Its advantage is the fact it's pretty fast, but unformtunately,
from the other hand, it requires <a href="http://www.oracle.com/technetwork/java/javase/download-142937.html">JMF</a>
to be installed on your PC.
</p>
<p>
If you do not want to use JMF (due to e.g. licensing issues), you can choose
<a href="http://fmj-sf.net/">FMJ</a>, which is a freeware replacement for JMF.
</p>
<p>
<b>NOTE!</b> Be aware of the fact that both JMF and FMJ are not being maintained any more!
</p>
<p>
This driver is available in Maven Central.
</p>
<h3>OpenIMAJ Driver</h3>
<p>
This is driver containing video grabber for Webcam Capture project. It utilizes
<a href="http://sourceforge.net/p/openimaj/home/OpenIMAJ/">OpenIMAJ</a> framework
capabilities to access PC webcam and can be used as a replacement
for default build-in driver. Its advantage is the fact it's pretty fast, supports
multiple platforms, but disadventage is the size of required 3<sup>rd</sup> party
JARs (around ~20MB). Default build-in driver uses OpenIMAJ natives to support video grabbing,
but id does not require all those additional JARs.
</p>
<p>
This driver is <b>NOT</b> available in Maven Central, but it can be used in Maven build.
In such a case user has to add those repositories to project's POM:
</p>
<pre class="prettyprint prettyprinted language-xml linenums">
<repositories>
<repository>
<id>OpenIMAJ maven repository</id>
<url>http://maven.openimaj.org/</url>
</repository>
<repository>
<id>Octopussy thirdparty maven repository</id>
<url>http://octopussy.ecs.soton.ac.uk/m2/thirdparty/</url>
</repository>
<repository>
<id>OpenIMAJ Snapshots maven repository</id>
<url>http://octopussy.ecs.soton.ac.uk/m2/snapshots/</url>
</repository>
</repositories>
</pre>
<h3>LTI-CIVIL Driver</h3>
<p>
This is driver containing video grabber for Webcam Capture project. It utilizes
<a href="http://lti-civil.org/">LTI-CIVIL</a> project
capabilities to access PC webcam and can be used as a replacement
for default build-in driver. LTI-CIVIL supports Windows, Linux and MAC OS platforms.
For Mac OS it utilizes QTJ framework capabilities. For other ones it uses precompiled
natives.
</p>
<p>
This driver is <b>NOT</b> available in Maven Central, but it can be used in Maven build.
In such a case user has to add those repositories to project's POM:
</p>
<pre class="prettyprint prettyprinted language-xml linenums">
<repositories>
<repository>
<id>sarxos-repo</id>
<url>http://repo.sarxos.pl/maven2</url>
</repository>
</repositories>
</pre>
<p>
<b>NOTE!</b> Be aware of the fact that LTI-CIVIL not being maintained any more by its owner!
</p>
<h3>OpenCV Driver</h3>
<p><b>EXPERIMENTAL STUFF!</b></p>
<p>
This is driver containing video grabber for Webcam Capture project. It utilizes
<a href="http://code.google.com/p/javacv/">JavaCV</a> Java wrapper for
<a href="http://opencv.willowgarage.com/wiki/">OpenCV</a> project
capabilities to access PC webcam and can be used as a replacement
for default build-in driver. Its advantage is quite stable interface, but unfortunately
it requires quite huge (around ~100MB) pre-installed OpenCV bundle.
</p>
<p>
This driver is <b>NOT</b> available in Maven Central, but it can be used in Maven build.
In such a case user has to add those repositories to project's POM:
</p>
<pre class="prettyprint prettyprinted language-xml linenums">
<repositories>
<repository>
<id>javacv</id>
<url>http://maven2.javacv.googlecode.com/git</url>
</repository>
<repository>
<id>kevoree</id>
<url>http://maven.kevoree.org/release</url>
</repository>
</repositories>
</pre>
<h3>VLCj Driver</h3>
<p><b>EXPERIMENTAL STUFF!</b></p>
<p>
This is driver containing video grabber for Webcam Capture project. It utilizes
<a href="https://github.com/caprica/vlcj">VLCj</a> Java wrapper for Videolan
<a href="http://www.videolan.org/vlc/">VLC</a> project
capabilities to access PC webcam and can be used as a replacement
for default build-in driver. Unfortunately it require VLC media player to be
pre-installed on the system where driver will be used.
</p>
<p>
This driver is <b>NOT</b> available in Maven Central, but it can be used in Maven build.
In such a case user has to add those repositories to project's POM:
</p>
<pre class="prettyprint prettyprinted language-xml linenums">
<repositories>
<repository>
<id>caprica</id>
<url>http://www.capricasoftware.co.uk/repo</url>
</repository>
</repositories>
</pre>
<h1>Examples</h1>
<p>
Confirmed to be perfectly running on the following systems (please
report at the project page if you tested it on other system, just
create new issue for that purpose):
</p>
<p>
<ul>
<li>Windows XP 32-bit</li>
<li>Windows Vista 32-bit</li>
<li>Windows 7 64-bit</li>
<li>Ubuntu 12.04 64-bit</li>
<li>Mac OS Snow Leopard</li>
<li>Raspberry Pi @ Arch Linux</li>
</ul>
</p>
<p>
Problems detected on those configurations:
</p>
<p>
<ul>
<li>Raspberry Pi @ Wheezy</li>
</ul>
</p>
<h3>Capture Image</h3>
<p>To capture single image and save it to disk:</p>
<pre class="prettyprint prettyprinted language-java linenums">
Webcam webcam = Webcam.getDefault();
webcam.open();
BufferedImage image = webcam.getImage();
ImageIO.write(image, "PNG", new File("test.png"));
</pre>
<p>If you have more then one webcam connected to your computer:</p>
<pre class="prettyprint prettyprinted language-java linenums">
Webcam laptop = Webcam.getWebcams().get(0);
Webcam kitchen = Webcam.getWebcams().get(1);
Webcam roof = Webcam.getWebcams().get(2);
</pre>
<h3>Detect Motion</h3>
<p>To detect motion with your webcam - loop solution:</p>
<pre class="prettyprint prettyprinted language-java linenums">
WebcamMotionDetector detector = new WebcamMotionDetector(Webcam.getDefault());
detector.setInterval(100); // one check per 100 ms (10 FPS)
detector.start();
while (true) {
if (detector.isMotion()) {
System.out.println("Detected motion I, alarm turn on you have");
}
Thread.sleep(500);
}
</pre>
<p>To detect motion with webcam - listener solution:</p>
<pre class="prettyprint prettyprinted language-java linenums">
public class DetectMotionExample implements WebcamMotionListener {
WebcamMotionDetector detector = new WebcamMotionDetector(Webcam.getDefault());
public DetectMotionExample() {
detector.setInterval(100); // one check per 100 ms (10 FPS)
detector.addMotionListener(this);
detector.start();
}
@Override
public void motionDetected(WebcamMotionEvent wme) {
System.out.println("Detected motion I, alarm turn on you have");
}
public static void main(String[] args) throws IOException {
new DetectMotionExample();
System.in.read(); // keeps your program open
}
}
</pre>
<h3>Swing Support</h3>
<p>
You can display image from webcam in Swing JPanel. There is a special component
designed for this.
</p>
<pre class="prettyprint prettyprinted language-java linenums">
JFrame window = new JFrame("Test Webcam Panel");
window.add(new WebcamPanel(Webcam.getDefault()));
window.pack();
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
</pre>
<h3>Display Image From IP / Network Camera</h3>
<p>
To use Webcam Capture together with IP or network camera you have to add
<a href="https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-driver-ipcam">IP / network camera driver</a>
to your Webcam Capture project.
</p>
<pre class="prettyprint prettyprinted language-java linenums">
IpCamDevice ipcam = new B7210("B7210", "114.32.216.24");
ipcam.setAuth(new IpCamAuth("demo", "demo"));
ipcam.setSize(B7210.SIZE_QVGA);
IpCamDriver driver = new IpCamDriver();
driver.register(ipcam);
Webcam.setDriver(driver);
WebcamPanel panel = new WebcamPanel(Webcam.getDefault());
panel.setFPS(0.5); // 1 frame per 2 seconds
JFrame f = new JFrame("Night Tree Somewhere");
f.add(panel);
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
</pre>
<p>
More IP / network camera examples are available in Github project's page.
</p>
<h3>Development Troubleshooting</h3>
<p>
In the development phase you will probably kill running application many
time (by stop button in Eclipse, Netbeans or other IDE), or by calling
<i>kill -TERM <pid></i> command from CLI. You have to be aware that
killing running application when Webcam Capture is already running can have
unwanted side-effects, such as:
</p>
<ul>
<li>Devices cannot be discovered,</li>
<li>Devices discovery hangs applciation or operating system,</li>
<li>Cannot open webcam device,</li>
<li>Cannot capture image from webcam,</li>
<li>Webcam found but later does not exists,</li>
<li>Etc.</li>
</ul>
<p>
All those issues arose from the same root cause - memory has not been
properly deallocated in the native layer. That's because you killed application
instead of closing it gracefully.
</p>
<p>
However, there is a solution for this problem. For such purpose special TERM
signal handler has been implemented, and you can enable it before you actually
start using Webcam Capture API. This can be done by calling this code (please
<b>make sure</b> to call it before you use any other method!):
</p>
<pre class="prettyprint prettyprinted language-java linenums">
Webcam.setTermSignalHandler(true);
</pre>
<p>
<b>IMPORTANT NOTE!</b> This is development setting and <b>shall not</b> be used
in production code!!! It modified the way of how JVM terminates its process, so
depending on the system there can be some unknown side-effects. Also features used
in this handler are undocumented and can be removed in further Java releases
without prior notification.
</p>
<h3>Logging</h3>
<p>
Logging has been implemented via SLF4J API, so all you need to do
is to add specific implementation and create configuration file.
</p>
<h4>Logging Example With Logback Library</h4>
<p>
This paragraph describes in short how to use <a href="http://logback.qos.ch/">Logback</a>
to enable logs from Webcam Capture API.
</p>
<p>
Go to <a href="http://logback.qos.ch/">Logback home page</a> and download
ZIP files containing all required JARs. Extract ZIP and add those files into
your classpath:
</p>
<ul>
<li>logback-classic-<b>[version]</b>.jar</li>
<li>logback-core-<b>[version]</b>.jar</li>
</ul>
<p>
NOTE! The <b>[version]</b> is current Logback release signature (e.g. 1.0.9).
</p>
<p>
Create <b>logback.xml</b> file and put this content inside:
</p>
<pre class="prettyprint prettyprinted language-xml linenums">
<configuration scan="true" scanPeriod="30 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
</pre>
<p>
When you include this file in your classpath, it will be discovered
automatically, but you can also load it manually by calling:
</p>
<pre class="prettyprint prettyprinted language-java linenums">
WebcamLogConfigurator.configure("path/to/logback.xml");
</pre>
<h2>More Examples?</h2>
<p>
There are more examples available in <b>src/example</b>, don't forget to
check them - please follow to the <a href="https://github.com/sarxos/webcam-capture">Github Project's Page</a> where <i>Webcam Capture</i>
source code is stored! Here are the examples links:
</p>
<ul>
<li><a href="https://github.com/sarxos/webcam-capture/tree/master/webcam-capture/src/example/java/com/github/sarxos/webcam">Small examples</a></li>
<li><a href="https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-examples">Large examples</a></li>
</ul>
<h1>License</h1>
<p>Copyright (C) 2012 - 213 Bartosz Firyn</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</section>
<footer>
<p>Maintained by <a href="https://github.com/sarxos">SarXos</a></p>
</footer>
</div>
<!--[if !IE]><script>fixScale(document);</script><!--<![endif]-->
<script type="text/javascript">
prettyPrint();
</script>
</body>
</html>