I have a Java program that controls a WebCam using Java CV. It works fine for WebCams built into monitors or for the Logitech C920. However, when I tried to control a Nikon 3100 DSLR connected to my computer by USB with the video turned on, the camera is not found.
Here is some of the Java code:
and the output: (3 cameras: built-in WebCam, Logitech C920 USB, Nikon 3100 USB)
camera : Logitech HD Pro Webcam C920
camera : Monitor Webcam #3
Is there some way I can use Java CV to control this camera?
Joe Nikki wrote:
-by "OpenCV libraries" you mean the DLLs bundled with JavaCV, yes? Aren't these also OS specific?
-By "camera interface libraries" do you mean DLLs provided by the manufacturer?
Yes, I mean the OpenCV DLLs (or .SOs in Linux) bundled with JavaCV.
By OS specific camera interface libraries, I mean this way:
- on Linux, OpenCV uses linux specific camera libraries like video4linux (which is not available in Windows), lib1394
and libgphoto (which AFAIK is not available in Windows update: no it looks like it's available from 3rd parties, but not widely used).
- on WIndows, I think OpenCV uses WinMM API or DirectX API to interface to camera. It's certainly not video4linux. It seems it's possible to use libgphoto on Win too.
The programming logic used by these camera libraries to interface with USB are very different on these 2 OSes because each OS has its own USB API.
OTH, the OpenCV DLLs (or .SOs) are not OS specific to the same extent as the camera libraries above. I'd say about 90% of OpenCV logic is common to all OSes.
For example, the OpenCV logic to detect faces or lines or edges is the exact same programming logic on both OSes.
Only the parts where they have to interface with OS specific libraries like video4linux or WinMM are different.
For your problem, I think one way is this but not exactly easy and possibly too many landmines to cross:
- Build libgphoto on Windows, or download it from somebody who's already built it - Use a java layer over libgphoto like libgphoto2-java - Translate code like this into java to capture image using libgphoto and process it using JavaCV.
Thanks for the detailed reply. Unfortunately, I don't think I know enough to successfully carry out the procedures you describe. So, I am trying an alternate way to accomplish what I need and, of course, I'm running into some problems. I will post about this in a different thread.
Joe Nikki wrote:Unfortunately, I don't think I know enough to successfully carry out the procedures you describe.
I suggest submitting a feature request to bytedeco's JavaCV github repo, requesting support for PTP protocol or libgphoto. Who knows...perhaps they may see the value in your suggestion and integrate it.
They may even give you a much better solution than mine. Unlike me, those people probably work with OpenCV everyday and know the perfect solution.
They will definitely have all the build infrastructure ready to do the building part in a jiffy.
A question in OpenCV forums may also be a good idea for the same reasons.
posted 4 years ago
Good idea. I will do that. In the meantime, I think I will be able to progress by installing and running some camera control software that is programmable with a lot of keystroke definitions and using Java robot. (This looks very promising: control my Nikon (See my other thread in this forum.)
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...