qq_38472758
qq_38472758
2018-04-19 13:51

OpenCV for Android中grabCut分割报错

20
  • android
  • 函数
  • rgb
  • opencv

代码:

 bit = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));

public void  MyGrabCut(){
        Mat src=new Mat();
        Mat gray=new Mat();
        Mat bg=new Mat();
        Mat fg=new Mat();
        Mat mask=new Mat();
        Utils.bitmapToMat(bit,src);
        Imgproc.cvtColor(src,gray,Imgproc.COLOR_RGBA2RGB);
        Rect rect=new Rect(20,30,100,100);
        mask.create(gray.size(), CvType.CV_8UC1);
        fg.create(gray.size(),CvType.CV_64FC1);
        bg.create(gray.size(),CvType.CV_64FC1);
        Imgproc.grabCut(gray,mask,rect,bg,fg,3,1);
    }

报了error: (-5) _model must have CV_64FC1 type, rows == 1 and cols == 13*componentsCount in function GMM::GMM,这个错误。
然后将

 fg.create(gray.size(),CvType.CV_64FC1);
 bg.create(gray.size(),CvType.CV_64FC1);

两句删除以后,就会报FATAL EXCEPTION: main
Process: com.example.administrator.myapplication, PID: 15958
CvException [org.opencv.core.CvException: cv::Exception: /build/master_pack-android/opencv/modules/imgproc/src/grabcut.cpp:380: error: (-215) !bgdSamples.empty() && !fgdSamples.empty() in function void initGMMs(const cv::Mat&, const cv::Mat&, GMM&, GMM&)
]

求问应该怎么解决???

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐