Here I have written some code to capture the image from USBcam using java.
Below is the code:
Webcam webcam = Webcam.getDefault();
webcam.open();
try {
ImageIO.write(webcam.getImage(), "PNG", new File("d:/hello-world1.png"));
System.out.println(Thread.currentThread().getName());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
And I have added 3 jars what ever required, but when running the application, image is not getting, Exception is raised.
Below is the Exception:
Exception in thread "main" com.github.sarxos.webcam.WebcamException: Cannot execute task
at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.process(WebcamProcessor.java:57)
at com.github.sarxos.webcam.WebcamProcessor.process(WebcamProcessor.java:120)
at com.github.sarxos.webcam.WebcamTask.process(WebcamTask.java:35)
at com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.open(WebcamOpenTask.java:20)
at com.github.sarxos.webcam.Webcam.open(Webcam.java:187)
at com.github.sarxos.webcam.Webcam.open(Webcam.java:147)
at ImageCapture.main(ImageCapture.java:16)
Caused by: com.github.sarxos.webcam.WebcamException: Cannot start native grabber!
at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice.open(WebcamDefaultDevice.java:220)
at com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.handle(WebcamOpenTask.java:38)
at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:66)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Please suggest me any idea where am putting wrong.
If you look at the source code, the message Cannot start native grabber
is raised if grabber.openSession(...)
returns false
where grabber=new OpenIMAJGrabber();
which is a native Bridj
proxy. This catch makes diagnosing difficult, as the real exception is hidden. There seems to be a native library access problem, so you should check if the .so
or the .dll
is indeed in your classpath. You should consider debugging to see if grabber
is well instantiated...
Here I have written some code to capture the image from USBcam using java.
Below is the code:
Webcam webcam = Webcam.getDefault();
webcam.open();
try {
ImageIO.write(webcam.getImage(), "PNG", new File("d:/hello-world1.png"));
System.out.println(Thread.currentThread().getName());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
And I have added 3 jars what ever required, but when running the application, image is not getting, Exception is raised.
Below is the Exception:
Exception in thread "main" com.github.sarxos.webcam.WebcamException: Cannot execute task
at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.process(WebcamProcessor.java:57)
at com.github.sarxos.webcam.WebcamProcessor.process(WebcamProcessor.java:120)
at com.github.sarxos.webcam.WebcamTask.process(WebcamTask.java:35)
at com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.open(WebcamOpenTask.java:20)
at com.github.sarxos.webcam.Webcam.open(Webcam.java:187)
at com.github.sarxos.webcam.Webcam.open(Webcam.java:147)
at ImageCapture.main(ImageCapture.java:16)
Caused by: com.github.sarxos.webcam.WebcamException: Cannot start native grabber!
at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice.open(WebcamDefaultDevice.java:220)
at com.github.sarxos.webcam.ds.cgt.WebcamOpenTask.handle(WebcamOpenTask.java:38)
at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:66)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Please suggest me any idea where am putting wrong.
If you look at the source code, the message Cannot start native grabber
is raised if grabber.openSession(...)
returns false
where grabber=new OpenIMAJGrabber();
which is a native Bridj
proxy. This catch makes diagnosing difficult, as the real exception is hidden. There seems to be a native library access problem, so you should check if the .so
or the .dll
is indeed in your classpath. You should consider debugging to see if grabber
is well instantiated...
0 commentaires:
Enregistrer un commentaire