Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

53
LINES

< > BotCompany Repo | #1008989 // Take screenshot from all web cams & save [WORKS]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 2596K of libraries. Click here for Pure Java version (716L/6K).

1  
!7
2  
3  
lib 1008985 // webcam
4  
lib 1008987 // bridj
5  
lib 1004016 // slf4j api
6  
7  
import com.github.sarxos.webcam.Webcam;
8  
9  
/**
10  
 * @author Bartosz Firyn (SarXos)
11  
 */
12  
13  
p {
14  
  List<Webcam> webcams = Webcam.getWebcams();
15  
  
16  
  // NOTE!
17  
  /*
18  
   * Yes, I know we could do this in one loop, but I wanted to prove here
19  
   * that it's possible to have many native webcams open in the same time.
20  
   * I tested this example with 4 webcams simultaneously connected to the
21  
   * USB bus - 1 x PC embedded device, and 3 x UVC devices connected to
22  
   * the USB concentration hub, which was connected to the USB 2.0 port.
23  
   * It's working like a charm.
24  
   */
25  
  
26  
  // USB BANDWIDTH!
27  
  /*
28  
   * As you probably know the USB has limited bandwidth and therefore it
29  
   * may not be possible to transfer images from as many cameras as you
30  
   * would like to wish. This example works when I'm using QQVGA (176x144)
31  
   * but fails with the error message when I want to fetch VGA (640x480).
32  
   */
33  
  
34  
  // open all at once (this is the most time-consuming operation, all
35  
  // others are executed instantly)
36  
  for (Webcam webcam : webcams) {
37  
  	System.out.format("Opening %s\n", webcam.getName());
38  
  	webcam.open();
39  
  }
40  
  
41  
  // capture picture from all of them
42  
  for (int i = 0; i < webcams.size(); i++) {
43  
  	Webcam webcam = webcams.get(i);
44  
  	System.out.format("Capturing %s\n", webcam.getName());
45  
  	ImageIO.write(webcam.getImage(), "PNG", print(prepareProgramFile(String.format("test-%d.png", i))));
46  
  }
47  
  
48  
  // close all
49  
  for (Webcam webcam : webcams) {
50  
  	System.out.format("Closing %s\n", webcam.getName());
51  
  	webcam.close();
52  
  }
53  
}

Author comment

See https://github.com/sarxos/webcam-capture

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008989
Snippet name: Take screenshot from all web cams & save [WORKS]
Eternal ID of this version: #1008989/6
Text MD5: 977b55d78221986b2555668a91dbd52e
Transpilation MD5: b8f866e366bd1ac8d9ffe3040556db1f
Author: stefan
Category: javax / desktop / camera
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-06-24 18:36:18
Source code size: 1652 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 593 / 1271
Version history: 5 change(s)
Referenced in: [show references]