Two Cameras, Two Listeners, only One OnCameraFrame

asked 2015-04-01 18:35:43 -0600

loleczek gravatar image

updated 2015-04-01 18:40:47 -0600

New user here. Playing around with the Camera Preview Tutorial I am able to generate a split screen utilizing the FRONT and BACK cameras simultaneously in a Kindle Fire HDX. To do this I implemented two JavaCameraViews:

<org.opencv.android.JavaCameraView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:visibility="visible"
    android:id="@+id/tutorial1_activity_java_surface_view"
    opencv:show_fps="true"
    opencv:camera_id="back" />

<org.opencv.android.JavaCameraView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:visibility="visible"
    android:id="@+id/tutorial1_activity_native_surface_view"
    opencv:show_fps="true"
    opencast:camera_id="front" />
</LinearLayout>

</framelayout>

And two Listeners:

    mOpenCvCameraView1 = (CameraBridgeViewBase)findViewById
                                           (R.id.tutorial1_activity_java_surface_view);
    mOpenCvCameraView2 (CameraBridgeViewBase)findViewById
                                           (R.id.tutorial1_activity_native_surface_view);

    mOpenCvCameraView1.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView2.setVisibility(SurfaceView.VISIBLE);

    mOpenCvCameraView1.setCvCameraViewListener(this);  //back camera
    mOpenCvCameraView2.setCvCameraViewListener(this);  //front camera

It works. The problem I can't seem to solve is that:

public class Tutorial1Activity extends Activity implements CvCameraViewListener2 { ...}

only implements a single OnCameraFrame method. If I want to process the Mat differently in each of the Cameras I need a way to determine which Listerner called OnCameraFrame. I'm pretty sure they alternate the calls since, for example, if I processed the OnCameraFrame to return a gray image, both the FRONT and BACK views will be gray. If I comment out ONE of the listerners, then that ONE will be RBG and the other will be gray.

Problem: find a way to identify the CvCameraViewListener, or Camera ID, that called OnCameraFrame within the OnCameraFrame method.

Any help would be much appreciated.

edit retag flag offensive close merge delete