OpenGL + OpenCV Augmented Reality on Android

喜夏-厌秋 提交于 2019-12-03 09:10:30

I combined opencv tracking (using the Camshift algorithm) with OpenGL here:

http://www.youtube.com/watch?v=yEioXZT-lv0

My first recommendation is not to try and tackle opengl libraries directly - there is a very good java wrapper for it called Rajawali

http://www.rozengain.com/blog/2011/08/23/announcing-rajawali-an-opengl-es-2-0-based-3d-framework-for-android/

You can use opengl directly but I found the interface quite bewildering and Rajawali hides a lot of the complexity.

Now, to map the opencv 2D coordinates to the 3D openGL is an interesting problem as a). you need to worry about how your camera 'sees' the 3D world in terms of lens distortion etc and b). you lose a dimension when moving from what the camera sees in 2D to the 3D model and so you need to make up for that loss of information from other sources such as the size of object being tracked. Vuforia will do this through a reference image so it is a shame you can't use that.

These issues are covered in sections 11 and 12 of the O'Reilly book http://www.amazon.co.uk/Learning-OpenCV-Computer-Vision-Library/dp/0596516134/ (although that book covers the C/C++ interfaces rather than Java but there's usually an obvious mapping).

For my example I didn't do anything too complex - the bigger the Camshift detected area the closer I moved the camera position in the 3D model. I used the accelerometer sensors to determine clockwise/anticlockwise rotation etc. Actually Vuforia would of been better for what I was trying to do but there you are.

The model btw was crafted in Blender and you can import that into Rajawali including some basic texturing.

Hope that helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!