0

私はopenCVのサンプルコードを使用していますが、私が見つけたのは、次のアクティビティがメニューをまったく表示していないことです。ホームボタンの横に、ほとんどすべてが正しいことがわかりましたが、メニューでさえ表示されません-

public class FdActivity extends Activity {
    private static final String TAG         = "Sample::Activity";

    private MenuItem            mItemFace50;
    private MenuItem            mItemFace40;
    private MenuItem            mItemFace30;
    private MenuItem            mItemFace20;
    private MenuItem            mItemType;

    private FaceDetectionView       mView;

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

                    // Load native libs after OpenCV initialization
                    System.loadLibrary("detection_based_tracker");

                    // Create and set View
                    mView = new FaceDetectionView(mAppContext);
                    mView.setDetectorType(mDetectorType);
                    mView.setMinFaceSize(0.2f);
                    setContentView(mView);
                    // Check native OpenCV camera
                    if( !mView.openCamera() ) {
                        AlertDialog ad = new AlertDialog.Builder(mAppContext).create();
                        ad.setCancelable(false); // This blocks the 'BACK' button
                        ad.setMessage("Fatal error: can't open camera!");
                        ad.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            finish();
                            }
                        });
                        ad.show();
                    }
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };


    private int                 mDetectorType = 0;
    private String[]            mDetectorName; 

    public FdActivity() {
        Log.i(TAG, "Instantiated new " + this.getClass());
        mDetectorName = new String[2];
        mDetectorName[FaceDetectionView.JAVA_DETECTOR] = "Java";
        mDetectorName[FaceDetectionView.NATIVE_DETECTOR] = "Native (tracking)";
    }

    @Override
    protected void onPause() {
        Log.i(TAG, "onPause");
        super.onPause();
        if (mView != null)
            mView.releaseCamera();
    }

    @Override
    protected void onResume() {
        Log.i(TAG, "onResume");
        super.onResume();
        if( mView != null && !mView.openCamera() ) {
            AlertDialog ad = new AlertDialog.Builder(this).create();  
            ad.setCancelable(false); // This blocks the 'BACK' button  
            ad.setMessage("Fatal error: can't open camera!");  
            ad.setButton("OK", new DialogInterface.OnClickListener() {  
                public void onClick(DialogInterface dialog, int which) {  
                    dialog.dismiss();                      
                    finish();
                }  
            });  
            ad.show();
        }
    }

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

        Log.i(TAG, "Trying to load OpenCV library");
        if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))
        {
            Log.e(TAG, "Cannot connect to OpenCV Manager");
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        Log.i(TAG, "onCreateOptionsMenu--------------------------->");
        super.onCreateOptionsMenu(menu);
        mItemFace50 = menu.add("Face size 50%");
        mItemFace40 = menu.add("Face size 40%");
        mItemFace30 = menu.add("Face size 30%");
        mItemFace20 = menu.add("Face size 20%");
        mItemType   = menu.add(mDetectorName[mDetectorType]);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.i(TAG, "Menu Item selected " + item);
        if (item == mItemFace50)
            mView.setMinFaceSize(0.5f);
        else if (item == mItemFace40)
            mView.setMinFaceSize(0.4f);
        else if (item == mItemFace30)
            mView.setMinFaceSize(0.3f);
        else if (item == mItemFace20)
            mView.setMinFaceSize(0.2f);
        else if (item == mItemType)
        {
            mDetectorType = (mDetectorType + 1) % mDetectorName.length;
            item.setTitle(mDetectorName[mDetectorType]);
            mView.setDetectorType(mDetectorType);
        }
        return true;
    }
}

そしてxmlコードは -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.emotion.facedetection"
          android:versionCode="1"
          android:versionName="1.1">          
 <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.CAMERA"/>     
    <uses-feature android:name="android.hardware.camera" />    
    <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>

    <application
        android:label="@string/app_name"
        android:icon="@drawable/big_smile"
        android:allowBackup="false"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

        <activity android:name="FdActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="landscape"
                  android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

メニューが表示されないコードで見落とされているもの。

この例は、openCV faceDetection サンプルから取得したものです。

4

2 に答える 2