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

70
LINES

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

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

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

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  
  time "list webcams" {
15  
    L<Webcam> webcams = new L(Webcam.getWebcams());
16  
  }
17  
  
18  
  // NOTE!
19  
  /*
20  
   * Yes, I know we could do this in one loop, but I wanted to prove here
21  
   * that it's possible to have many native webcams open in the same time.
22  
   * I tested this example with 4 webcams simultaneously connected to the
23  
   * USB bus - 1 x PC embedded device, and 3 x UVC devices connected to
24  
   * the USB concentration hub, which was connected to the USB 2.0 port.
25  
   * It's working like a charm.
26  
   */
27  
  
28  
  // USB BANDWIDTH!
29  
  /*
30  
   * As you probably know the USB has limited bandwidth and therefore it
31  
   * may not be possible to transfer images from as many cameras as you
32  
   * would like to wish. This example works when I'm using QQVGA (176x144)
33  
   * but fails with the error message when I want to fetch VGA (640x480).
34  
   */
35  
  
36  
  // open all at once (this is the most time-consuming operation, all
37  
  // others are executed instantly)
38  
  for i, Webcam webcam over webcams: { try {
39  
  	System.out.format("Opening %s\n", webcam.getName());
40  
  	time "Opening webcam" {
41  
  	  webcam.open();
42  
  	}
43  
  } catch e {
44  
    print("Can't open webcam " + webcam.getName() + " - " + silentException(e));
45  
    webcams.remove(i--);
46  
  }}
47  
  
48  
  new L<Pair<S, BufferedImage>> images;
49  
  
50  
  // capture picture from all of them
51  
  for (int i = 0; i < webcams.size(); i++) pcall {
52  
  	Webcam webcam = webcams.get(i);
53  
  	S name = webcam.getName();
54  
  	System.out.format("Capturing %s\n", name);
55  
  	time "Capturing image" {
56  
  	  images.add(pair(name, webcam.getImage()));
57  
  	}
58  
  }
59  
  
60  
  // close all
61  
  time "Closing webcams" {
62  
    for (Webcam webcam : webcams) {
63  
    	System.out.format("Closing %s\n", webcam.getName());
64  
  	  webcam.close();
65  
    }
66  
  }
67  
  
68  
  for (Pair<S, BufferedImage> p : images)
69  
    showImage(p.a, p.b);
70  
}

Author comment

Began life as a copy of #1008989

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: #1008996
Snippet name: Take screenshot from all web cams & display [WORKS]
Eternal ID of this version: #1008996/10
Text MD5: f0a9a655fe171244e87154c92f92b937
Transpilation MD5: f8e82b5d70db6ba4afb80c912e0f5ccc
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-28 15:46:12
Source code size: 2022 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 705 / 1369
Version history: 9 change(s)
Referenced in: [show references]