OpenCV Android在Imgproc.cvtColor()

时间:2016-06-08 04:57:29

标签: java android opencv

我遇到OpenCV4Android问题。

  

java.lang.RuntimeException:无法启动活动   ComponentInfo {com.example.camtime / com.fognature.develop.smp.CameraActivity}:   CvException [org.opencv.core.CvException:cv :: Exception:   /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/color.cpp:3739:   错误:( - 1515)scn == 3 || scn == 4 in function void   cv :: cvtColor(cv :: InputArray,cv :: OutputArray,int,int)                                                                            ]                                                                                在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2320)                                                                                在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2380)                                                                                在android.app.ActivityThread.access $ 800(ActivityThread.java:151)                                                                                在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1285)                                                                                在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                在android.os.Looper.loop(Looper.java:135)                                                                                在android.app.ActivityThread.main(ActivityThread.java:5289)                                                                                at java.lang.reflect.Method.invoke(Native Method)                                                                                在java.lang.reflect.Method.invoke(Method.java:372)                                                                                在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)                                                                                在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)                                                                             引起:CvException [org.opencv.core.CvException:cv :: Exception:   /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/color.cpp:3739:   错误:( - 1515)scn == 3 || scn == 4 in function void   cv :: cvtColor(cv :: InputArray,cv :: OutputArray,int,int)                                                                            ]                                                                                at org.opencv.imgproc.Imgproc.cvtColor_1(原生方法)                                                                                在org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:4598)                                                                                在   com.fognature.develop.smp.CameraActivity.onCreate(CameraActivity.java:108)                                                                                在android.app.Activity.performCreate(Activity.java:6018)                                                                                在   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)                                                                                在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2273)                                                                                 ......还有10个

在此代码部分:

Mat sec;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        sec = new Mat();
        setContentView(R.layout.activity_camera);
    File photo = new File(Environment.getExternalStorageState()


+File.separator+"SMP"+File.separator+getIntent().getStringExtra("c_name")+File.separator+getIntent().getStringExtra("last_photo"));
                sec = Highgui.imread(photo.getAbsolutePath());
                Imgproc.cvtColor(sec, sec, Imgproc.COLOR_RGBA2GRAY);
        }

Imgproc.cvtColor(秒,秒,Imgproc.COLOR_RGBA2GRAY);

1 个答案:

答案 0 :(得分:4)

错误说明:

  

错误:( - 1515)scn == 3 || scn == 4 in function void   cv :: cvtColor(cv :: InputArray,cv :: OutputArray,int,int)]

通常意味着:

  • 当您尝试转换RGBA2GRAY时,在这种情况下,输入Mat sec只有1个频道。您可以在阅读后立即记录sec.channels()来确认这一点。
  • 输入Mat也可能为空或已损坏,以确认您可以检查sec.widthsec.heightsec.depth等属性,以确保其已正确加载。< / LI>