-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUtility.java
executable file
·51 lines (43 loc) · 1.57 KB
/
Utility.java
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
package Camera;
import java.awt.Image;
import javax.media.Buffer;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.Processor;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
public class Utility {
private static Player player=null;
public static boolean findCameraByURL(String url){
boolean return_value=false;
try {
MediaLocator ml = new MediaLocator(url);
Processor p = Manager.createProcessor(ml);
System.out.println("Found camera at: " + url);
return_value=true;
} catch (Exception e) {
System.out.println("Can not find camera at:" + url + ",or problem with JMF install.");
}
return return_value;
}
public static void initCamera(String url){
try{
player=Manager.createRealizedPlayer( new MediaLocator(url));
Thread.sleep(2500);
}catch(Throwable ex){
System.out.println("initCamera Exception:"+ex.getMessage());
}
}
public static Image getAwtImage() throws Exception {
FrameGrabbingControl frameGrabber = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
Buffer buf = frameGrabber.grabFrame();
Image img = (new BufferToImage((VideoFormat) buf.getFormat()).createImage(buf));
if (img == null) {
//throw new Exception("Image Null");
System.exit(1);
}
return img;
}
}