Android Studio + OpenCV - “onCameraFrame”功能中的实时更改值

时间:2016-10-16 23:08:07

标签: java android opencv oncreate

我的代码有问题。我希望实时更改返回值。我正在开发app(openCV + Java)。应用程序运行时,是否可以在“Mat onCameraFrame()”函数中更改返回值?

这是一个代码

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    mOpenCvCameraView = (CameraBridgeViewBase)findViewById(R.id.camera_view);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener(this);

    button_rgb = (Button) findViewById(R.id.button_rgb);
    button_gray = (Button) findViewById(R.id.button_grey);
    show_text = (TextView)findViewById(R.id.show_text);

    show_text.setText("GRAY");
    gray_active = true;

    button_rgb.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            show_text.setText("RGB");
            rgb_active = true;
        }
    });

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    mRgba = inputFrame.rgba();

    if (gray_active == true) {
        Imgproc.cvtColor(mRgba, imgGray, Imgproc.COLOR_RGB2GRAY);
        return imgGray;
    }

    else if (edge_active == true){
        Imgproc.cvtColor(imgGray, imgCanny, 50, 150);
        return imgCanny;
    }

    else {
        return mRgba;
    }
}

0 个答案:

没有答案