Hello, I hope to use the facetime camera with OpenCV4Android 2.4.3. I am
able to run the sample of Sample2NativeCamera
(org.opencv.samples.tutorial2.Sample2NativeCamera). How can I let it use
the facetime camera? Thanks.

I have copied the tutorial code below.

package org.opencv.samples.tutorial2;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;

public class Sample2NativeCamera extends Activity implements
CvCameraViewListener {
private static final String TAG = "OCVSample::Activity";

public static final int VIEW_MODE_RGBA = 0;
public static final int VIEW_MODE_GRAY = 1;
public static final int VIEW_MODE_CANNY = 2;

private static int viewMode = VIEW_MODE_RGBA;
private MenuItem mItemPreviewRGBA;
private MenuItem mItemPreviewGray;
private MenuItem mItemPreviewCanny;
private Mat mRgba;
private Mat mIntermediateMat;

private CameraBridgeViewBase mOpenCvCameraView;

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

} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};

public Sample2NativeCamera() {
Log.i(TAG, "Instantiated new " + this.getClass());
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

setContentView(R.layout.tutorial2_surface_view);

mOpenCvCameraView = (CameraBridgeViewBase)
findViewById(R.id.tutorial2_activity_surface_view);
mOpenCvCameraView.setCvCameraViewListener(this);
}

@Override
public void onPause()
{
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
super.onPause();
}

@Override
public void onResume()
{
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this,
mLoaderCallback);
}

public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}

public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height, width, CvType.CV_8UC4);
mIntermediateMat = new Mat(height, width, CvType.CV_8UC4);
}

public void onCameraViewStopped() {
mRgba.release();
mIntermediateMat.release();
}

public Mat onCameraFrame(Mat inputFrame) {
switch (Sample2NativeCamera.viewMode) {
case Sample2NativeCamera.VIEW_MODE_GRAY:
{
Imgproc.cvtColor(inputFrame, mRgba,
Imgproc.COLOR_GRAY2RGBA, 4);
} break;
case Sample2NativeCamera.VIEW_MODE_RGBA:
{
inputFrame.copyTo(mRgba);
Core.putText(mRgba, "OpenCV+Android", new Point(10,
inputFrame.rows() - 10), 3, 1, new Scalar(255, 0, 0, 255), 2);
} break;
case Sample2NativeCamera.VIEW_MODE_CANNY:
{
Imgproc.Canny(inputFrame, mIntermediateMat, 80, 100);
Imgproc.cvtColor(mIntermediateMat, mRgba,
Imgproc.COLOR_GRAY2BGRA, 4);
} break;
}

return mRgba;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.i(TAG, "called onCreateOptionsMenu");
mItemPreviewRGBA = menu.add("Preview RGBA");
mItemPreviewGray = menu.add("Preview GRAY");
mItemPreviewCanny = menu.add("Canny");
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(TAG, "called onOptionsItemSelected; selected item: " + item);
if (item == mItemPreviewRGBA)
{

mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
viewMode = VIEW_MODE_RGBA;
}
else if (item == mItemPreviewGray)
{

mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_GREY_FRAME);
viewMode = VIEW_MODE_GRAY;
}
else if (item == mItemPreviewCanny)
{

mOpenCvCameraView.SetCaptureFormat(Highgui.CV_CAP_ANDROID_GREY_FRAME);
viewMode = VIEW_MODE_CANNY;
}

return true;
}
}

---------------------------
He Jibo
Assistant Professor
Department of Psychology,
Wichita State University
website: www.hejibo.info

--

Search Discussions

  • Andrey Pavlenko at Jan 8, 2013 at 12:01 pm
    Look at the app layout of the Tutorial-1 sample in the latest
    OpenCv4Android SDK v 2.4.3.2 package<http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.3/OpenCV-2.4.3.2-android-sdk.zip/download>
    .

    --
  • He Jibo at Jan 8, 2013 at 8:18 pm
    Thanks, Andrey, This solution is easier than the previous version I used.

    I just need to change any to front to use the front camera. Thanks!
    opencv:camera_id="front" />


    <LinearLayout 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" >

    <org.opencv.android.JavaCameraView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="gone"
    android:id="@+id/tutorial1_activity_java_surface_view"
    opencv:show_fps="true"
    opencv:camera_id="front" />

    <org.opencv.android.NativeCameraView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="gone"
    android:id="@+id/tutorial1_activity_native_surface_view"
    opencv:show_fps="true"
    opencv:camera_id="front" />

    </LinearLayout>

    ---------------------------
    He Jibo
    Assistant Professor
    Department of Psychology,
    Wichita State University
    website: www.hejibo.info


    On Tue, Jan 8, 2013 at 6:01 AM, Andrey Pavlenko
    wrote:
    Look at the app layout of the Tutorial-1 sample in the latest
    OpenCv4Android SDK v 2.4.3.2 package<http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.3/OpenCV-2.4.3.2-android-sdk.zip/download>.


    --


    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-opencv @
categoriesandroid
postedJan 6, '13 at 4:47a
activeJan 8, '13 at 8:18p
posts3
users2
websiteandroid.com

2 users in discussion

He Jibo: 2 posts Andrey Pavlenko: 1 post

People

Translate

site design / logo © 2019 Grokbase