OpenCV中的Android按位xor错误

时间:2013-04-10 21:52:00

标签: android opencv bit-manipulation xor bitwise-xor

我在android上尝试了按位xor,但是我收到以下错误:

04-11 00:25:47.404: E/cv::error()(7370): OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array') in void cv::binary_op(cv::InputArray, cv::InputArray, cv::OutputArray, cv::InputArray, void (* const*)(const uchar*, size_t, const uchar*, size_t, uchar*, size_t, cv::Size, void*), bool), file /home/reports/ci/slave/50-SDK/opencv/modules/core/src/arithm.cpp, line 1021

这是我的代码:

Mat temp1 = mRgba.submat(roi); 
Mat temp2 = Mat.zeros(temp1.size(), CvType.CV_8UC1);    
Core.bitwise_xor(temp1, temp2, temp1);

我也尝试过以下方式实例化temp1和temp2:

Mat temp1 = new Mat(height, width, CvType.CV_8UC1); 
Mat temp2 = new Mat(height, width, CvType.CV_8UC1);

但仍然是同样的错误..

1 个答案:

答案 0 :(得分:3)

您的代码未提及mRgba的类型,但从名称我假设它是RGBA或CV_8UC4。这意味着temp1mRgba的类型相同。正如错误所述,两个矩阵必须具有相同的大小和类型。这意味着必须将temp2声明为CV_8UC4类型,或者您必须先将mRgba转换为CV_8UC1,这可能是通过转换为灰度。我不熟悉Java接口,但等效的C ++调用将是:

cv::cvtColor(mRgba, mRgba, CV_RGBA2GRAY);