Hi
I am trying to use webcam using the Java library from a git - https://github.com/sarxos/webcam-capture.
When I try to run the Scala equivivalent of Java code, I am getting empty result.
Returns:
[JavaFX Application Thread] INFO com.github.sarxos.webcam.Webcam - WebcamDefaultDriver capture driver will be used - "Webcam: FaceTime HD Camera CC253577UNXG1HNAL"
It works perfectly alright with Java.
However, if try the samething with scala as follows,
import com.github.sarxos.webcam.Webcam
Webcam webcam = Webcam.getDefault() // FaceTime HD Camera CC253577UNXG1HNAL
println (webcam)
I get the result -
[JavaFX Application Thread] INFO com.github.sarxos.webcam.Webcam - WebcamDefaultDriver capture driver will be used.
The only thing I can think of (I don’t know java) is that you may need some java dependency in your classpath, which is injected at runtime - I got bitten this way once.
You don’t have the equivalent of that in your Scala code.
If that’s not it you might want to show the complete code that you’re trying to run and the exact output that you get. Seeing as your first Scala snippet wasn’t even valid Scala code I suspect you didn’t do that.
I just tried this, and here is code that seems to work in the ammonite REPL.
Welcome to the Ammonite Repl 1.0.1
(Scala 2.12.3 Java 1.8.0_101)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ import $ivy.`com.github.sarxos:webcam-capture:0.3.11`
import $ivy.$
@ import com.github.sarxos.webcam.Webcam
import com.github.sarxos.webcam.Webcam
@ val webcam = Webcam.getDefault()
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
webcam: Webcam = Webcam Venus USB2.0 Camera /dev/video0
@ println(webcam)
Webcam Venus USB2.0 Camera /dev/video0
It captures images as well. I suggest you:
download ammonite REPL for scala experimentations
check your classpaths, and share them when you have questions.
This reminds me of an issue I had with the Java sound API. More specifically SBT has its own class loader that can wreak havoc with some libraries. Look at the following suggestion that may help you:
Just a note here — things might move more quickly if you prepare an example project that demonstrates the issues you’re having and post the link to it on GitHub. Cheers!