JPCT-AE With OpenCV Augmented Reality

Started by Mr. K, May 23, 2016, 10:26:16 AM

Previous topic - Next topic

Mr. K

Hello it's me again, thanks for the help given previously and i hope don't be annoying

But someone haved used JPCT-AE with OpenCV? i dont have idea how to use OpenCV and JPCT-AE in the same activity, i mean do augmented reality, someone have a tutorial or example?

thanks and have a nice day.


Mr. K

At first thanks for the reply

i found another solution for this using the following tutorial http://www.jpct.net/forum2/index.php?topic=1586.0, but i changed the CameraView class for another similar, but with OpenCV integrated, i will put here a llitle example if someone need to use OpenCV with JPCT-AE

Activity XML File:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=your application context>

    <android.opengl.GLSurfaceView
        android:id="@+id/glsurfaceview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <CameraView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:opencv="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/cameraView"
        opencv:show_fps="true"
        opencv:camera_id="any" >

    </CameraView>

</FrameLayout>


Activity Java File:

public class MainActivity extends AppCompatActivity {

    private GLSurfaceView glSurfaceView;
    private RendererJPCT renderer;
    private boolean gl2 = true;

    private CameraView cameraView;
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i(TAG, "OpenCV loaded successfully");
                    cameraView.enableView();
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        if(masterMainActivity != null){
            copyActivity(masterMainActivity);
        }

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.
                FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);

        cameraView = (CameraView) findViewById(R.id.cameraView);
        cameraView.setVisibility(SurfaceView.VISIBLE);
        cameraView.setCvCameraViewListener(cameraView);

        glSurfaceView = (GLSurfaceView) findViewById(R.id.glsurfaceview);

        if (gl2) {
            glSurfaceView.setEGLContextClientVersion(2);
        } else {
            glSurfaceView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
                public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
                    int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
                    EGLConfig[] configs = new EGLConfig[1];
                    int[] result = new int[1];
                    egl.eglChooseConfig(display, attributes, configs, 1, result);
                    return configs[0];
                }
            });

        }

        glSurfaceView.setEGLConfigChooser(8,8,8,8,16,0);
        renderer = new RendererJPCT(masterMainActivity);
        glSurfaceView.setRenderer(renderer);

        glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    }
}



CameraView Java Class:


public class CameraView extends JavaCameraView implements CvCameraViewListener2{

    public CameraView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onCameraViewStarted(int width, int height) {

    }

    @Override
    public void onCameraViewStopped() {

    }

    @Override
    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        return inputFrame.rgba();
    }
}


The class RendererJPCT its simple class extended of Renderer

I hope this will helpful, thanks EgonOlsen


EgonOlsen


eslabon3d

Hi All

How pass the proyection matrix to camera in JPCT?


Mr. K  you can post the renderer class please

the key for AR is the proyection matriz and model matrix  I think.

sorry if the question is silly (and for my poor english) I am new in programming

Greetings from Colombia