0

我正在开发一个检测黄色物体的应用程序,每当检测到该物体时,它就会说出检测到的物体。这是我的代码:

package org.opencv.samples.imagemanipulations;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;


import android.view.WindowManager;

public abstract class ImageManipulationsActivity extends Activity implements     CvCameraViewListener2, TextToSpeech.OnInitListener {
private static final String  TAG                 = "OCVSample::Activity";

private CameraBridgeViewBase mOpenCvCameraView;


private Mat                  mRgba;

int count = 0;
int a=0;
int b=0;
int c=0;

private TextToSpeech myTTS;

private int MY_DATA_CHECK_CODE = 0;



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 ImageManipulationsActivity() {
    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.image_manipulations_surface_view);

    myTTS= new TextToSpeech(this,this);
     Intent checkTTSIntent = new Intent();
        checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
        startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.image_manipulations_activity_surface_view);
    mOpenCvCameraView.setCvCameraViewListener(this);
}

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

@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();

    new Size();
    new Mat();
}



public void onCameraViewStopped() {
    // Explicitly deallocate Mats


    if (mRgba != null)
        mRgba.release();



    mRgba = null;


}

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();

    Size s=mRgba.size();

    for (int i = 0; i < s.height; i++) {
        for (int j = 0; j < s.width; j++) {


            double[] rgb=mRgba.get(i,j);

            a=(int) rgb[0];
            b=(int) rgb[1];
            c=(int) rgb[2];


            if ((a>=225) && (a<=240) && (b>=215) && (b<= 230) && (c>=90) && (c<= 150)) {
                count=count++;
            }
        }
    }

    if (count>1000) {

        myTTS.speak("object detected", TextToSpeech.QUEUE_FLUSH, null);

    }
    return mRgba;
}
}

我在 logcat 中收到以下错误。请帮我解决这个问题:

07-15 23:22:56.733: E/AndroidRuntime(13661): FATAL EXCEPTION: main
07-15 23:22:56.733: E/AndroidRuntime(13661): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.opencv.samples.imagemanipulations/org.opencv.samples.imagemanipulations.ImageManipulationsActivity}: java.lang.InstantiationException: can't instantiate class     org.opencv.samples.imagemanipulations.ImageManipulationsActivity
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.os.Looper.loop(Looper.java:137)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.app.ActivityThread.main(ActivityThread.java:4921)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at java.lang.reflect.Method.invokeNative(Native Method)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at java.lang.reflect.Method.invoke(Method.java:511)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at dalvik.system.NativeStart.main(Native Method)
07-15 23:22:56.733: E/AndroidRuntime(13661): Caused by: java.lang.InstantiationException: can't instantiate class org.opencv.samples.imagemanipulations.ImageManipulationsActivity
07-15 23:22:56.733: E/AndroidRuntime(13661):    at java.lang.Class.newInstanceImpl(Native Method)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at java.lang.Class.newInstance(Class.java:1319)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
07-15 23:22:56.733: E/AndroidRuntime(13661):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
07-15 23:22:56.733: E/AndroidRuntime(13661):    ... 11 more
4

1 回答 1

1

ImageManipulationsActivityabstract,所以它不能被实例化。删除关键字或使用非抽象类进行abstract扩展。ImageManipulationsActivity

于 2013-07-15T19:54:08.450 回答