在Android上转换CtvColor和在Eclipse上转换OpenCV时出错

在Android上转换CtvColor和在Eclipse上转换OpenCV时出错,android,eclipse,opencv,template-matching,Android,Eclipse,Opencv,Template Matching,我正在Eclipse中使用openCV开发Android。我试着做一帧一帧的模板匹配。我无法转换模板并在其上执行匹配模板。我正在使用该函数: public void initialize(){ if (src.empty()) return; if(template == null){ Mat templ = Highgui.imread(getFileAbsPath("1.png", Highgui.CV_LOAD

我正在Eclipse中使用openCV开发Android。我试着做一帧一帧的模板匹配。我无法转换模板并在其上执行匹配模板。我正在使用该函数:

public void initialize(){
    if (src.empty())
        return;
    if(template == null){
        Mat templ = Highgui.imread(getFileAbsPath("1.png",
                Highgui.CV_LOAD_IMAGE_UNCHANGED);
        template = new Mat(templ.size(), CvType.CV_32F);
        Imgproc.cvtColor(templ, (Mat) template, Imgproc.COLOR_BGR2RGBA);
    }
}

 private String getFileAbsPath(String fileName) {
   File f = new File(cacheDir, fileName);
   return f.getAbsolutePath();
}
我在以下方面出错:

Imgproc.cvtColor(templ, (Mat) template, Imgproc.COLOR_BGR2RGBA);
我的形象是(第一):

接下来,我介绍了我的方法:

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

   src = inputFrame.rgba();
   initialize();
   int match_method = Imgproc.TM_SQDIFF;

   // Create the result matrix
   int result_cols = src.cols() - ((Mat) template).cols() + 1;
   int result_rows = src.rows() - ((Mat) template).rows() + 1;
   Mat result = new Mat(result_rows, result_cols, CvType.CV_32F);

  // Do the Matching and Normalize
  Imgproc.matchTemplate(src, (Mat) template, result, match_method);
  Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());

  MinMaxLocResult mmr = Core.minMaxLoc(result);

  Point matchLoc;
  if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
    matchLoc = mmr.minLoc;
} else {
    matchLoc = mmr.maxLoc;
}

Rect roi = new Rect((int) matchLoc.x, (int) matchLoc.y, ((Mat) template).cols(), ((Mat) template).rows());
Core.rectangle(src, new Point(roi.x, roi.y), new Point(roi.width - 2, roi.height - 2), new Scalar(255, 0, 0, 255), 2);

return src;
}

我在那一行得到一个错误:

Imgproc.matchTemplate(src, (Mat) template, result, match_method);

我不能比赛,不知道为什么。。。有人能帮我吗?

从BGR到RGBA的转换需要目标
Mat
有4个频道。你想这样做吗?我真的不知道,但我读到的是的,他说我需要转换。我在这里读到: