Forums Register Login

using Java CV to control a Nikon 3100 DSLR

+Pie Number of slices to send: Send
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 [0]: Logitech HD Pro Webcam C920
camera [1]: Monitor Webcam #3
...

Is there some way I can use Java CV to control this camera?
Regards, Joe
+Pie Number of slices to send: Send
What OS are you running it on?
The layers are
JavaCV (java) -> OpenCV libraries (native) -> camera interface libraries (native, OS specific) -> OS -> drivers.

So you need the right camera interface native library, and it should be linked from the OpenCV libraries that are bundled with JavaCV.

Some searching says Nikon DSLRs talk PTP protocol over USB, and libgphoto2 supports it (atleast on Linux). So if the bundled OpenCV is linked with libgphoto2, perhaps it's possible.

Not sure about Win or Mac though.
+Pie Number of slices to send: Send
Thanks very much for the reply.
1) I am running on Windows 7
2) I need some help understanding this statement:

The layers are
JavaCV (java) -> OpenCV libraries (native) -> camera interface libraries (native, OS specific) -> OS -> drivers.



-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?
Regards,
Joe
+Pie Number of slices to send: Send
 

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.


Another way may be to build your own latest OpenCV 3.x and OpenCV-java (not the bytedeco version, but the original one) and set HAVE_GPHOTO2 flag while doing so. You will need some knowledge of cmake, make and C++ building to do this. Then you can do vc = new VideoCapture( Videoio.CAP_GPHOTO2). See http://docs.opencv.org/java/3.1.0/index.html?org/opencv/videoio/VideoCapture.html
+Pie Number of slices to send: Send
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.
Regards
Joe
+Pie Number of slices to send: Send
 

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.


+Pie Number of slices to send: Send
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.)
Regards,
Joe
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1723 times.
Similar Threads
JMF driving me crazy, help! and are there easier ways of capturing still images?
JMF on linux
capturing high-resolution video frames from a Logitech C920 WebCam
A good SLR
web camera -- java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:13:42.