0

i am trying to make one Asus Xtion work in java with opencv 2.4.7 and OpenNI (i have both installed).

My problem is that the flags doens't work..

CV_CAP_OPENNI

CV_CAP_OPENNI_DEPTH_MAP

CV_CAP_OPENNI_POINT_CLOUD_MAP

CV_CAP_OPENNI_DISPARITY_MAP

CV_CAP_OPENNI_DISPARITY_MAP_32F

CV_CAP_OPENNI_VALID_DEPTH_MASK

No one is working, why?

Luis Carlos
  • 333
  • 2
  • 6
  • 18

3 Answers3

0

query Core.getBuildInformation() http://docs.opencv.org/java/org/opencv/core/Core.html#getBuildInformation()

to see, if your opencv libs were built with openni support (probably not, if you're using the prefab ones)

highly likely, that you have to recompile opencv (with openni sdk installed) to achieve it.

berak
  • 39,159
  • 9
  • 91
  • 89
0

My guess is the OpenCV Java Wrapper might not have support for OpenNI. The Java and Python wrappers usually are limited compared to the c++ API. Usually the core functions are there but the newer/experimental parts make it in later.

For quick prototyping in Java I use Processing a lot. This can be used as a library in eclipse as well. There are two nice wrappers that could help out: SimpleOpenNI to connect to your Xtion sensor (I've tested with one and it works fine) and the OpenCV Processing wrapper.

SimpleOpenNI

SimpleOpenNI SimpleOpenNI

OpenCV Processing

OpenCV Processing

If you don't want to use SimpleOpenNI, you can use PrimeSense's OpenNI Java wrapper (which comes with the OpenNI Install for OpenNI 1.5.x or this wrapper for OpenNI 2.x). Once you get the depth/rgb images, there should be ways to convert them to OpenCV Mat instances for further processing.

Community
  • 1
  • 1
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • I dont want to use Processing, i used a lot but this time i dont want to use it. OpenNI supports java.. I figured out that the main problem of the missing OpenNI support is that the original openCV x is not compiled with OpenNI support. And this problem is for c/c++ and java. I tried to compile opencv with openni support but with no success yet :/ – Luis Carlos Nov 27 '13 at 10:31
  • I've built OpenCV with OpenNI support before. Please try [these instructions](http://stackoverflow.com/questions/16754631/how-to-install-openni-in-windows-and-visual-studio-2010/16780470#16780470) and let me know if you'e managed to compile OpenCV with OpenNI support yourself. It will be easy to do a quick test in c++, but I haven't tried using the OpenCV OpenNI support in Java, so not sure it's there or not. – George Profenza Nov 27 '13 at 11:02
  • I tried to folow your post but i have these problems: Still have the "warning: PrimeSense..." problem. Tried to make the changes to "OpenCVFindOpenNI.cmake" but i think my current opencv 2.4.7 have that fixed. Also, i am using OpenNI2 and in your post i think you used the old one and the new one dont have "openni64" and "XnCppWrapper.h". So many problems :/ – Luis Carlos Nov 27 '13 at 12:05
  • Yes, I think that might be true. In the post I linked earlier(http://stackoverflow.com/questions/16754631/how-to-install-openni-in-windows-and-visual-studio-2010/16780470#16780470) notice the OpenNI links are for OpenNI 1.5. This [post](http://www.morethantechnical.com/2013/05/25/openni-2-x-and-opencv-interoperability-w-code/) might be handy for OpenNI2 <-> OpenCV integration, but that would probably mean you will need a JNI layer to use that java. If you need to use OpenNI 2 and OpenCV in java, maye the above suggestion might be simpler... – George Profenza Nov 27 '13 at 14:53
  • ...use a [Java OpenNi 2 wrapper](https://github.com/almerindo/OpenNI2/tree/master/Wrappers) and get the depth/rgb image then convert the pixels from that format to Mat format and carry with OpenCV. – George Profenza Nov 27 '13 at 14:56
  • Thank you for your comments :) Unfortunatly opencv does not have openNI 2 support. And i don't like to use 3º person wrappers – Luis Carlos Nov 30 '13 at 17:31
0

I got OpenNI working with official OpenCV Java Bindings. I had to recompile and enable WITH_OPEN_NI, like stated in OpenCV documentation for getting Kinect to work. Then, the problem was to get the constants for OpenNI. It seems that, like you said, CV_CAP_OPENNI is not defined in Java binding. The code looked like this:

int CV_CAP_OPENNI = 900;
    VideoCapture capture = new VideoCapture(CV_CAP_OPENNI);


    capture.grab();
    Mat depthMap = new Mat();
    int CV_CAP_OPENNI_DEPTH_MAP = 0;
    capture.retrieve( depthMap,  CV_CAP_OPENNI_DEPTH_MAP);
    Mat show = new Mat();
    depthMap.convertTo( show,CvType.CV_8UC1, 0.05f );

the constant values were extracted from D:\opencv\modules\highgui\include\opencv2\highgui\highgui_c.h I believe the best way to do it is to check python scripts that generate Java classes and make them include those constants to generated jar.

Java OpenNI

dannyxyz22
  • 978
  • 9
  • 18