Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCvCamera Preferred Height and Width Fails on Linux #395

Closed
vonnieda opened this issue Dec 30, 2016 · 16 comments
Closed

OpenCvCamera Preferred Height and Width Fails on Linux #395

vonnieda opened this issue Dec 30, 2016 · 16 comments

Comments

@vonnieda
Copy link
Member

vonnieda commented Dec 30, 2016

User reports that no matter what preferred height and width are set to the camera always returns images at 640x480. Native resolution is 1920x1080. Report is for Debian Jessie. Says that doing the same thing with Python bindings works fine.

See discussion at https://groups.google.com/d/msgid/openpnp/CA%2BQw0jwGyRBWXpvvG%3D%2BY-UqHn_MQvS9%2B%2BvaXOjve99-T%2BCY4vg%40mail.gmail.com?utm_medium=email&utm_source=footer.

I suspect that the version of OpenCV that we're distributing is linked against a camera driver that does not handle property setting properly while his local copy of opencv does. Need to run some tests on a Linux based system.

It would be helpful if others can verify this issue. To do, follow these steps:

  1. Set up an OpenCvCamera camera in OpenPnP.
  2. Set preferred width and preferred height to something other than the camera's native resolution.
  3. Right click the the camera view and select Show Image Info. See if the resolution shown matches the values you set.
@vonnieda
Copy link
Member Author

I have released a test version at http://openpnp.org/test-downloads/ that sets the value both before and after. Please test and see if this works for you.

@dzach
Copy link
Contributor

dzach commented Dec 30, 2016

I can confirm the problem on a Linux AMD64 machine running Kubuntu 16.04, with a 1280x1024 Philips SPZ5000 Webcam:

$ uname -a
Linux desk 4.4.0-36-generic #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

$ dpkg -l | grep libopencv
ii  libopencv-core2.4v5:amd64                       2.4.9.1+dfsg-1.5ubuntu1                           amd64        computer vision core library
ii  libopencv-highgui2.4v5:amd64                    2.4.9.1+dfsg-1.5ubuntu1                           amd64        computer vision High-level GUI and Media I/O library
ii  libopencv-imgproc2.4v5:amd64                    2.4.9.1+dfsg-1.5ubuntu1                           amd64        computer vision Image Processing library


$ dpkg -l | grep v4l2ucp
ii  v4l2ucp                                         2.0.2-4                                           amd64        Video for Linux 2 Universal Control Panel

$ java -version
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)

Could the fact that openpnp cannot recognize a CCD Philips SPC 900NC webcam be of relevance?

I'll try to run the test branch and report back.

@vonnieda
Copy link
Member Author

vonnieda commented Dec 30, 2016 via email

@dzach
Copy link
Contributor

dzach commented Dec 30, 2016

The SPC 900NC is recognized by the OS without any driver installation, v4l2ucp control panel shows all controls,the same way it does for all other webcams, and seems to be able to control the camera. Cheeze and VLC and other multimedia/communications apps that I tried it with do recognize it and work properly. I like this CCD camera for its low light sensitivity and the absense of the rolling shutter effect, despite its mere 640x480 px resolution.

@vonnieda
Copy link
Member Author

vonnieda commented Dec 30, 2016 via email

@dzach
Copy link
Contributor

dzach commented Dec 30, 2016

Thanks for giving it a thought Jason.
You are right about it been peculiar. If I remember correctly I had troubles getting it to work with mjpg_streamer some (long) time ago, when moving from v4l to v4l2. And, I just tried it again, and still, no luck with mjpg_streamer.

@nanodude
Copy link

Jason, I've tested the the version you released and the problem persists. Setting the resolution before or after opening the device has no effect. The only difference is that prior to opening, cap.get returns (0, 0) and after opening it returns (640.0, 480.0). I'm going to try to compile the latest opencv2 jar and use it to see if it works. I'll keep you posted. Thanks!

@vonnieda
Copy link
Member Author

vonnieda commented Dec 30, 2016 via email

vonnieda added a commit that referenced this issue Dec 30, 2016
* test:
  Testing setting camera width and height before and after open to see if it helps with #395.

# Conflicts:
#	src/main/java/org/openpnp/machine/reference/camera/OpenCvCamera.java
vonnieda added a commit that referenced this issue Dec 30, 2016
* develop:
  Trace open cv camera properties on initialize to make it easier to debug issues with this feature.
  Added a button to read the current property value on the open cv camera wizard.
  Adds support for setting opencv camera properties. Fixes #328.
  Testing setting camera width and height before and after open to see if it helps with #395.
  Added links to documentation in Help menu.
  Added support for boolean actuators in ReferenceAutoFeeder. Added support for post pick actuator in ReferenceAutoFeeder. Added post pick support to Feeders tab pick operation. Updated CHANGES.md for recent changes.
  Remove accidental import.
  Adds "Check For Updates..." menu item in Help menu. Fixes #391.
  Fix git config which was breaking api doc uploads.
  ReferenceCamera changes to fix performance issues in #392 and infinite loop: Added safeInternalCapture() which has retry on null images and returns a default image on failure, guaranteeing we never see a null image. While loops on getWidth(), getHeight(), and capture() replaced with safeInternalCapture()

# Conflicts:
#	src/main/java/org/openpnp/machine/reference/camera/OpenCvCamera.java
@nanodude
Copy link

Quick question: should it be enough to replace the opencv jar file and make the new dynamic opencv java lib known to the OS? I did exactly this (for the lib I set LD_LIBRARY_PATH) but OpenPnP bombs... I may be doing something wrong. Thanks!

@vonnieda
Copy link
Member Author

vonnieda commented Dec 30, 2016 via email

@nanodude
Copy link

Well, it seems the problem is that OpenCV doesn't include the nu.pattern thing...

@vonnieda
Copy link
Member Author

vonnieda commented Dec 31, 2016 via email

@nanodude
Copy link

Jason, following your explanantion, I deleted libopencv_java from the jar file (to be sure) and made available my version (via LD_LIBRARY_PATH). Result was the same. There's something strange going on with the java interface. At this point, I don't see what else I can do. Thanks for your help, though!

@dzach
Copy link
Contributor

dzach commented Jan 6, 2017

@vonnieda

If you can get the camera working with OpenCV and tell me how you did it I will be happy to make sure it's supported. OpenCV is the limiting factor. That's how we talk to the cameras. Unfortunately we don't have a native v4l driver.

I was able to solve the problem with the Philips SPC 900NC CCD camera by turning on WITH_V4L and WITH_LIBV4L when running cmake. I created this opencv issue, that shows more about the process.

I don't know whether it is feasible to do the same in openpnp. In the process I learned that one could also use GStramer plugins to pass video/image frames to opencv.

@vonnieda
Copy link
Member Author

vonnieda commented Jan 7, 2017

Thanks for checking into this @dzach. I build and distribute OpenCV for OpenPnP, and it looks like the current build did not include V4L. You can see the results from the build here: https://github.com/openpnp/opencv/blob/v2.4.13-0/src/main/resources/nu/pattern/opencv/linux/x86_64/cmake.log#L353

I've added an issue for myself to see if I can include V4L and GStreamer in the next build: openpnp/opencv#13. I will update this ticket once I investigate further.

vonnieda added a commit that referenced this issue Jan 7, 2017
* develop: (97 commits)
  Adds a new ScriptRun CvPipeline stage that allows for custom programming of CvPipelines.
  Rearranged baclash fields a bit to clean up the GcodeDriverWizard.
  made textfields a bit more narrow
  moved form elements into two grid rows
  documentation
  form and keyword fixes
  more blackslah compensation GUI process - still need to fix form
  Fixes #398: Feeder exceptions are no longer swallowed during job processing. When reporting there are no feeders available, if a feed was previously attempted we store the error and forward it on.
  minor fix for NaN cases
  initial slack compensation experiments
  Trace open cv camera properties on initialize to make it easier to debug issues with this feature.
  Added a button to read the current property value on the open cv camera wizard.
  Adds support for setting opencv camera properties. Fixes #328.
  Testing setting camera width and height before and after open to see if it helps with #395.
  Added links to documentation in Help menu.
  Added support for boolean actuators in ReferenceAutoFeeder. Added support for post pick actuator in ReferenceAutoFeeder. Added post pick support to Feeders tab pick operation. Updated CHANGES.md for recent changes.
  Remove accidental import.
  Adds "Check For Updates..." menu item in Help menu. Fixes #391.
  Fix git config which was breaking api doc uploads.
  ReferenceCamera changes to fix performance issues in #392 and infinite loop: Added safeInternalCapture() which has retry on null images and returns a default image on failure, guaranteeing we never see a null image. While loops on getWidth(), getHeight(), and capture() replaced with safeInternalCapture()
  ...
@vonnieda
Copy link
Member Author

Closing this as "Won't Fix". Most users have transitioned to OpenPnpCaptureCamera, and I suggest that all other users do so. The OpenCV camera bindings are terrible and unmaintained, so I won't spend any further time updating them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants