sarxos / webcam-capture

The goal of this project is to allow integrated or USB-connected webcams to be accessed directly from Java. Using provided libraries users are able to read camera images and detect motion. Main project consist of several sub projects - the root one, which contains required classes, build-in webcam driver compatible with Windows, Linux and Mac OS, which can stream images as fast as your camera can serve them (up to 50 FPS). Main project can be used standalone, but user is able to replace build-in driver with different one - such as OpenIMAJ, GStreamer, V4L4j, JMF, LTI-CIVIL, FMJ, etc.
http://webcam-capture.sarxos.pl
MIT License
2.28k stars 1.11k forks source link

Webcam discovery Listener #876

Open meeeee12 opened 2 years ago

meeeee12 commented 2 years ago

When I pull out the active webcam's USB cable it takes around 5 seconds to realise the webcam has been removed which is ok, but If I plug the webcam back in before the webcamGone discovery event is triggered, the webcamGone and webcamFound events are never triggered. The WebcamPanel no longer updates and I keep getting [frames-refresher-[0]] ERROR com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice - Timeout when requesting image!. Is it possible to avoid this behaviour?

meeeee12 commented 2 years ago

I am using Java 11.0.9 running on Windows 10

diveair commented 2 years ago

I too am looking for a solution to this issue, and am hoping to edit the library myself to include a fix but I cannot get a dev environment without dependencies issues which seems to throw the exception:

java.io.FileNotFoundException: Library 'OpenIMAJGrabber' was not found in path '[., C:/Program Files/Java/jre1.8.0_161/bin/server, C:/Program Files/Java/jre1.8.0_161/bin, C:/Program Files/Java/jre1.8.0_161/lib/amd64, C:\ProgramData\Oracle\Java\javapath, C:\Windows\system32, C:\Windows, C:\Windows\System32\Wbem, C:\Windows\System32\WindowsPowerShell\v1.0\, C:\Windows\System32\OpenSSH\, C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL, C:\Program Files\Intel\Intel(R) Management Engine Components\DAL, C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common, C:\WINDOWS\system32, C:\WINDOWS, C:\WINDOWS\System32\Wbem, C:\WINDOWS\System32\WindowsPowerShell\v1.0\, C:\WINDOWS\System32\OpenSSH\, C:\Program Files\Intel\WiFi\bin\, C:\Program Files\Common Files\Intel\WirelessCommon\, C:\Program Files (x86)\Schneider Electric\SoMachine Software\Tools\ConfigurationManager\, C:\Program Files (x86)\QuickTime\QTSystem\, C:\Program Files\Java\jdk1.8.0_161, C:\Program Files\Java\jdk1.8.0_161\bin, C:\Program Files\WorldPainter, C:\Program Files\TortoiseSVN\bin, C:\Program Files\dotnet\, C:\Users\PC\AppData\Local\Microsoft\WindowsApps, C:\Users\PC\Desktop\eclipse, C:\Program Files\Java\jre1.8.0_161\bin, C:\WINDOWS\system32, C:\WINDOWS, C:/Program Files/Java/jre1.8.0_161/bin/server, C:/Program Files/Java/jre1.8.0_161/bin, C:/Program Files/Java/jre1.8.0_161/lib/amd64, C:\ProgramData\Oracle\Java\javapath, C:\Windows\system32, C:\Windows, C:\Windows\System32\Wbem, C:\Windows\System32\WindowsPowerShell\v1.0\, C:\Windows\System32\OpenSSH\, C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL, C:\Program Files\Intel\Intel(R) Management Engine Components\DAL, C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common, C:\WINDOWS\system32, C:\WINDOWS, C:\WINDOWS\System32\Wbem, C:\WINDOWS\System32\WindowsPowerShell\v1.0\, C:\WINDOWS\System32\OpenSSH\, C:\Program Files\Intel\WiFi\bin\, C:\Program Files\Common Files\Intel\WirelessCommon\, C:\Program Files (x86)\Schneider Electric\SoMachine Software\Tools\ConfigurationManager\, C:\Program Files (x86)\QuickTime\QTSystem\, C:\Program Files\Java\jdk1.8.0_161, C:\Program Files\Java\jdk1.8.0_161\bin, C:\Program Files\WorldPainter, C:\Program Files\TortoiseSVN\bin, C:\Program Files\dotnet\, C:\Users\PC\AppData\Local\Microsoft\WindowsApps, C:\Users\PC\Desktop\eclipse, ., C:\Program Files\Java\jre1.8.0_161\bin, C:\Program Files\Java\jre1.8.0_161\bin]' at org.bridj.BridJ.getNativeLibrary(BridJ.java:1074) at org.bridj.BridJ.getNativeLibrary(BridJ.java:1049) at org.bridj.BridJ.getNativeLibrary(BridJ.java:602) at org.bridj.cpp.CPPRuntime.newCPPInstance(CPPRuntime.java:771) at org.bridj.cpp.CPPRuntime$CPPTypeInfo.initialize(CPPRuntime.java:1022) at org.bridj.cpp.CPPRuntime$CPPTypeInfo.initialize(CPPRuntime.java:904) at org.bridj.CRuntime$CTypeInfo.initialize(CRuntime.java:271) at org.bridj.BridJ.initialize(BridJ.java:1128) at org.bridj.NativeObject.(NativeObject.java:50) at org.bridj.StructObject.(StructObject.java:46) at org.bridj.cpp.CPPObject.(CPPObject.java:55) at com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber.(OpenIMAJGrabber.java:62) at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver$WebcamNewGrabberTask.handle(WebcamDefaultDriver.java:55) at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:81) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Exception in thread "main" com.github.sarxos.webcam.WebcamException: java.util.concurrent.ExecutionException: com.github.sarxos.webcam.WebcamException: Cannot execute task at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:124) at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:893) at com.github.sarxos.webcam.Webcam.getDefault(Webcam.java:956) at com.github.sarxos.webcam.Webcam.getDefault(Webcam.java:933) at com.github.sarxos.webcam.Webcam.getDefault(Webcam.java:911) at guitest.Widgets.WebcamWidget.(WebcamWidget.java:60) at guitest.MainApp.main(MainApp.java:75) Caused by: java.util.concurrent.ExecutionException: com.github.sarxos.webcam.WebcamException: Cannot execute task at java.util.concurrent.FutureTask.report(Unknown Source) at java.util.concurrent.FutureTask.get(Unknown Source) at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:116) ... 6 more Caused by: com.github.sarxos.webcam.WebcamException: Cannot execute task at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.process(WebcamProcessor.java:72) at com.github.sarxos.webcam.WebcamProcessor.process(WebcamProcessor.java:140) at com.github.sarxos.webcam.WebcamTask.process(WebcamTask.java:46) at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver$WebcamNewGrabberTask.newGrabber(WebcamDefaultDriver.java:45) at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver.getDevices(WebcamDefaultDriver.java:117) at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:36) at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:1) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.RuntimeException: Failed to allocate new instance of type class com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber at org.bridj.cpp.CPPRuntime.newCPPInstance(CPPRuntime.java:812) at org.bridj.cpp.CPPRuntime$CPPTypeInfo.initialize(CPPRuntime.java:1022) at org.bridj.cpp.CPPRuntime$CPPTypeInfo.initialize(CPPRuntime.java:904) at org.bridj.CRuntime$CTypeInfo.initialize(CRuntime.java:271) at org.bridj.BridJ.initialize(BridJ.java:1128) at org.bridj.NativeObject.(NativeObject.java:50) at org.bridj.StructObject.(StructObject.java:46) at org.bridj.cpp.CPPObject.(CPPObject.java:55) at com.github.sarxos.webcam.ds.buildin.natives.OpenIMAJGrabber.(OpenIMAJGrabber.java:62) at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDriver$WebcamNewGrabberTask.handle(WebcamDefaultDriver.java:55) at com.github.sarxos.webcam.WebcamProcessor$AtomicProcessor.run(WebcamProcessor.java:81) ... 3 more Caused by: java.io.FileNotFoundException: Library 'OpenIMAJGrabber' was not found in path '[., C:/Program Files/Java/jre1.8.0_161/bin/server, C:/Program Files/Java/jre1.8.0_161/bin, C:/Program Files/Java/jre1.8.0_161/lib/amd64, C:\ProgramData\Oracle\Java\javapath, C:\Windows\system32, C:\Windows, C:\Windows\System32\Wbem, C:\Windows\System32\WindowsPowerShell\v1.0\, C:\Windows\System32\OpenSSH\, C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL, C:\Program Files\Intel\Intel(R) Management Engine Components\DAL, C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common, C:\WINDOWS\system32, C:\WINDOWS, C:\WINDOWS\System32\Wbem, C:\WINDOWS\System32\WindowsPowerShell\v1.0\, C:\WINDOWS\System32\OpenSSH\, C:\Program Files\Intel\WiFi\bin\, C:\Program Files\Common Files\Intel\WirelessCommon\, C:\Program Files (x86)\Schneider Electric\SoMachine Software\Tools\ConfigurationManager\, C:\Program Files (x86)\QuickTime\QTSystem\, C:\Program Files\Java\jdk1.8.0_161, C:\Program Files\Java\jdk1.8.0_161\bin, C:\Program Files\WorldPainter, C:\Program Files\TortoiseSVN\bin, C:\Program Files\dotnet\, C:\Users\PC\AppData\Local\Microsoft\WindowsApps, C:\Users\PC\Desktop\eclipse, C:\Program Files\Java\jre1.8.0_161\bin, C:\WINDOWS\system32, C:\WINDOWS, C:/Program Files/Java/jre1.8.0_161/bin/server, C:/Program Files/Java/jre1.8.0_161/bin, C:/Program Files/Java/jre1.8.0_161/lib/amd64, C:\ProgramData\Oracle\Java\javapath, C:\Windows\system32, C:\Windows, C:\Windows\System32\Wbem, C:\Windows\System32\WindowsPowerShell\v1.0\, C:\Windows\System32\OpenSSH\, C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL, C:\Program Files\Intel\Intel(R) Management Engine Components\DAL, C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common, C:\WINDOWS\system32, C:\WINDOWS, C:\WINDOWS\System32\Wbem, C:\WINDOWS\System32\WindowsPowerShell\v1.0\, C:\WINDOWS\System32\OpenSSH\, C:\Program Files\Intel\WiFi\bin\, C:\Program Files\Common Files\Intel\WirelessCommon\, C:\Program Files (x86)\Schneider Electric\SoMachine Software\Tools\ConfigurationManager\, C:\Program Files (x86)\QuickTime\QTSystem\, C:\Program Files\Java\jdk1.8.0_161, C:\Program Files\Java\jdk1.8.0_161\bin, C:\Program Files\WorldPainter, C:\Program Files\TortoiseSVN\bin, C:\Program Files\dotnet\, C:\Users\PC\AppData\Local\Microsoft\WindowsApps, C:\Users\PC\Desktop\eclipse, ., C:\Program Files\Java\jre1.8.0_161\bin, C:\Program Files\Java\jre1.8.0_161\bin]' at org.bridj.BridJ.getNativeLibrary(BridJ.java:1074) at org.bridj.BridJ.getNativeLibrary(BridJ.java:1049) at org.bridj.BridJ.getNativeLibrary(BridJ.java:602) at org.bridj.cpp.CPPRuntime.newCPPInstance(CPPRuntime.java:771) ... 13 more