OpenNI with ofxNI2 and Code::Blocks

I saw this entry on DevArt and got quite interested in OpenNI2 and NiTE2. I cloned satoruhiga’s ofxNI2 repository and tried to run the example on Windows 8 with Code::Blocks 12.11. I got these errors:

..\..\..\addons\ofxNI2\libs\OpenNI2\include\ni2\OniPlatform.h|34|error: #error OpenNI Platform Abstraction Layer - Win32 - Microsoft Visual Studio version below 2003 (7.0) are not supported!

..\..\..\addons\ofxNI2\libs\OpenNI2\include\ni2\Win32\OniPlatformWin32.h|57|fatal error: crtdbg.h: No such file or directory

Cyril Diagne (kikko) seemed to get ofxNI2 running on Mac. The github readme is very brief and only mentions OSX. I didn’t find anything about oF and OpenNI2 in the forum or anywhere else.

Can anyone help me to get it running on Code::Blocks?

Cheers!

Documenting the progress:

Checking the source of ofxOpenNI, I noticed they modified some headers to make it compatible with MINGW32 / Code::Blocks.

#ifndef __MINGW32_VERSION // MingW32 (added gameover/m gingold 10/07/2011)

These modifications can be seen here.
I modified the OpenNI 2 files in the same way and managed to get passed the errors described above.

Then I got another error involving the names near and far. Luckily this time I knew what it was because I’ve seen the same issue before when working with ofxCubeMap on Windows. This time I just edited windef.h and commented them out.

Then another error involving setenv() - ofxNI2.cpp line 34.
I don’t know exactly what is going on here, but setenv should be in stdlib.h and it is not.
I decided to comment this line out and create the environment variable by hand. I am on 64-bit, but just to be sure I created two:

OPENNI2_DRIVERS_PATH C:\Program Files\OpenNI2\Redist\OpenNI2\Drivers
OPENNI2_DRIVERS_PATH64 C:\Program Files\OpenNI2\Redist\OpenNI2\Drivers

After that, another error:

obj\Release\addons\ofxNI2\src\ofxNI2.o:ofxNI2.cpp|| undefined reference to `_imp__oniFrameAddRef'
obj\Release\addons\ofxNI2\src\ofxNI2.o:ofxNI2.cpp|| undefined reference to `_imp__oniFrameRelease'
...
More errors follow but not being shown.

And I am stuck again.

According to the Code::Blocks wiki page: “Most of the time it is because the required library is not linked with your project.”
I have added C:\Program Files\OpenNI2\Lib\OpenNI2.lib to the Build options > Linker settings, but the error persisted.

I also found this post on stackoverflow that shows how to setup OpenNI 2 on Visual Studio (without oF) but I am not sure how that applies to Code::Blocks.

Even if it is not a full solution, I hope my findings are helpful to someone.
And I still appreciate if someone can help me with the last error.

I really want to get this working on Code::Blocks.
Here is a fork of ofxNI2 with my changes, in case anyone wants to give it a try: https://github.com/brunoimbrizi/ofxNI2

Libraries still seem to be missing, but where is the problem?
I followed the instructions of the OpenNI 2.0 Getting Started page, but I am not sure about that last part “-Wl,-rpath ./”
The issue might be more related to OpenNI 2 and GCC than to openFrameworks, but I think it is relevant to chase a solution here since I’m probably not the only one interested in this.

Below is my build log:

-------------- Build: release in example (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Lbin  -o bin\example.exe obj\Release\src\ofxNI2.o obj\Release\src\ofxNiTE2.o obj\Release\example\src\main.o obj\Release\example\src\testApp.o   -s ../../../libs/openFrameworksCompiled/lib/win_cb/openFrameworks.lib -Wl,-rpath .\  ..\..\..\libs\FreeImage\lib\win_cb\FreeImage.lib ..\..\..\libs\rtAudio\lib\win_cb\librtaudio.a ..\..\..\libs\quicktime\lib\win_cb\qtmlClient.lib ..\..\..\libs\cairo\lib\win_cb\libcairo.a ..\..\..\libs\cairo\lib\win_cb\libpixman-1.a ..\..\..\libs\freetype\lib\win_cb\libfreetype.a ..\..\..\libs\glut\lib\win_cb\libglut.a ..\..\..\libs\glfw\lib\win_cb\libglfw3.a ..\..\..\libs\videoInput\lib\win_cb\videoInputLib.a ..\..\..\libs\fmodex\lib\win_cb\libfmodex.a ..\..\..\libs\glew\lib\win_cb\glew32s.lib ..\..\..\libs\glu\lib\win_cb\glu32.lib ..\..\..\libs\poco\lib\win_cb\libPocoNetSSL.a ..\..\..\libs\poco\lib\win_cb\libPocoCrypto.a ..\..\..\libs\poco\lib\win_cb\libPocoNet.a ..\..\..\libs\poco\lib\win_cb\libPocoUtil.a ..\..\..\libs\poco\lib\win_cb\libPocoXML.a ..\..\..\libs\poco\lib\win_cb\libPocoFoundation.a ..\..\..\libs\openssl\lib\win_cb\libssl.a ..\..\..\libs\openssl\lib\win_cb\libcrypto.a ..\..\..\libs\tess2\lib\win_cb\libtess2.a -lopengl32 -lgdi32 -lmsimg32 -lglu32 -ldsound -lwinmm -ldxguid -lstrmbase -lstrmiids -lz -luuid -lole32 -loleaut32 -lsetupapi -lwsock32 -lws2_32 -lIphlpapi -lComdlg32 ..\libs\OpenNI2\lib\win\OpenNI2.lib ..\libs\NiTE2\lib\win\NiTE2.lib 

Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
[skip other warnings]

obj\Release\src\ofxNI2.o:ofxNI2.cpp:(.text+0x230): undefined reference to `_imp__oniFrameAddRef'
obj\Release\src\ofxNI2.o:ofxNI2.cpp:(.text+0x245): undefined reference to `_imp__oniFrameRelease'
[skip other errors]

Process terminated with status 1 (0 minutes, 3 seconds)
50 errors, 17 warnings (0 minutes, 3 seconds)

As you can see here, there are links for both OpenNI2.lib and NiTE2.lib.
Am I missing any links or compiler instructions?

Solved.
I had installed OpenNI and NiTE x64. Changing them to x86 fixed the problem and I managed to compile the example finally.
There was still a runtime error, so I had to add this to ofxNI2.cpp:

"#extension GL_ARB_texture_rectangle : enable\n"

The fork was updated: https://github.com/brunoimbrizi/ofxNI2 There are still some strange things going on with the examples, but eventually I’ll fix those too and do a pull request.

Hey Bruno,

Thanks for this! I get an error when building though:

… addons\ofxNI2\src\ofxNI2.h |240| error: expected primary-expression before ‘;’ token

and another for line 243 in the same file, the code is:

240: inline void setNear(float near) { near_value = near; }
243: inline void setFar(float far) { far_value = far; }

Any thoughts?

Yes, it is the problem with near and far that I mentioned above:

But changing windef.h is not a very dynamic solution, so since I’m already working on a fork, I updated those variable names to _near and _far to avoid this conflict. Please grab an update and let me know if it is working for you.

Hey guys,

Any idea of why I’m getting this error?

[ error ] ofxNI2: libs not found

Process returned -1073741819 (0xC0000005)   execution time : 9.560 s
Press any key to continue.

I’m on Windows7 and using the libfreenect drivers

I think the path to the drivers is wrong, but I’m not sure why:

if (ofFile::doesFileExist("OpenNI2/Drivers", false))
		{
			string path = "OpenNI2/Drivers";
			#ifndef __MINGW32_VERSION
			setenv("OPENNI2_DRIVERS_PATH", path.c_str(), 1);
			#endif
			assert_error(openni::OpenNI::initialize());
		}
		else
		{
			ofLogError("ofxNI2") << "libs not found";
			ofExit(-1);
		}

Right, the problem was that the DLLs need to be in /bin/OpenNi2/Drivers not just /bin as in Bruno’s github readme.

The problem now is this:

[ error ] ofxNI2:       LibraryHandler: Couldn't find function oniDriverCreate i
n NiTE2.dll. Stopping
        DeviceDriver: library handle is invalid for file NiTE2.dll
        Couldn't understand file 'NiTE2.dll' as a device driver
        LibraryHandler: Couldn't find function oniDriverCreate in OpenNI2.dll. S
topping
        DeviceDriver: library handle is invalid for file OpenNI2.dll
        Couldn't understand file 'OpenNI2.dll' as a device driver
        Found no valid drivers in 'D:\Dev\OF\v0.8.4\addons\ofxNI2\example\bin\Op
enNI2\Drivers'

terminate called without an active exception

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Process returned 255 (0xFF)   execution time : 53.043 s
Press any key to continue.

I’m using NiTE-Windows-x86-2.2 and the latest OpenNI2 from http://structure.io/openni: http://com.occipital.openni.s3.amazonaws.com/OpenNI-Windows-x86-2.2.0.33.zip

@gazpachu

It has been a while, but I believe the information in the readme is correct.
Here are some screenshots of where the files are in a working example:

/bin

/bin/OpenNI2/Drivers

Hope it helps.

Thanks!, getting closer. The step that I was missing was copying the “NiTE2” and “OpenNI2” folders from “program files” into the bin folder of the example.

Now I’m getting another error, but I think it’s because the libfreenect drivers don’t work with OpenNI??? The Kinect for Windows SDK drivers only work in Windows 8, but I’m using Windows 7

[ error ] ofxNI2:       DeviceOpen using default: no devices found

[warning] ofShader: GL_FRAGMENT_SHADER shader reports:
No errors.

Process returned 255 (0xFF)   execution time : 10.757 s
Press any key to continue.

Finally working with these drivers: http://www.microsoft.com/en-us/download/details.aspx?id=36996

Is the hand tracker not implemented in the ofx plugin? I can see it in NiTE.h but not in ofxNiTE2.h.

I’m trying to get the hand tracker implementation from here but this is quite difficult for me :-S

http://blog.csdn.net/dingluseu/article/details/11638683

I will put the implementation in the fork I’ve made: https://github.com/gazpachu/ofxNI2