Java OpenCV错误:空指针(为缺少的输出数组调用create())

Java OpenCV错误:空指针(为缺少的输出数组调用create()),java,android,c++,opencv,java-native-interface,Java,Android,C++,Opencv,Java Native Interface,我已将来自的本机代码打包,以便在我的android项目中使用,如下所示: Thresholder.cpp中的doThreshold函数 JNIEXPORT void JNICALL Java_packagename_MainActivity_doThreshold (JNIEnv* env, jobject thiz, InputArray _src, OutputArray _dst, const BhThresholdMethod &method) { Mat src =

我已将来自的本机代码打包,以便在我的android项目中使用,如下所示:

Thresholder.cpp中的doThreshold函数

JNIEXPORT void JNICALL Java_packagename_MainActivity_doThreshold
(JNIEnv* env, jobject  thiz, InputArray _src, OutputArray _dst, const     BhThresholdMethod &method)

{
Mat src = _src.getMat();
int winx = 0;
int winy = 0;
float optK=0.5;
if (winx==0 || winy==0) {
    winy = (int) (2.0 * src.rows - 1)/3;
    winx = (int) src.cols-1 < winy ? src.cols-1 : winy;

    // if the window is too big, than we asume that the image
    // is not a single text box, but a document page: set
    // the window size to a fixed constant.
    if (winx > 100)
        winx = winy = 40;
}
// Threshold
_dst.create(src.size(), CV_8UC1);
Mat dst = _dst.getMat();

//medianBlur(src,dst,5);
GaussianBlur(src,dst,Size(5,5),0);

//#define _BH_SHOW_IMAGE
#ifdef _BH_DEBUG
#define _BH_SHOW_IMAGE
#endif
//medianBlur(src,dst,7);
switch (method)
{
case BhThresholdMethod::OTSU :
    threshold(dst,dst,128,255,CV_THRESH_OTSU);
    break;
case BhThresholdMethod::SAUVOLA :
case BhThresholdMethod::WOLFJOLION :
    NiblackSauvolaWolfJolion (src, dst, method, winx, winy, optK, 128);
}
bitwise_not(dst,dst);


#ifdef _BH_SHOW_IMAGE

#undef _BH_SHOW_IMAGE
#endif
}
然后我通过执行以下操作调用本机方法:

InputStream in = getAssets().open("test.jpg");
BufferedInputStream bin = new BufferedInputStream(in);
Bitmap bmp = BitmapFactory.decodeStream(bin);
Mat image = new Mat();
Utils.bitmapToMat(bmp, image);
//call native method
doThreshold(image, image, BhThresholdMethod.SAUVOLA);
但是我得到了这个错误:

E/cv::error(): OpenCV Error: Null pointer (create() called for the missing output array)
in void cv::_OutputArray::create(int, const int*, int, int, bool, int) const, file 
/Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp, line 2437
当到达这一行代码时,Thresholder.cpp中会抛出错误:
\u dst.create(src.size(),CV_8UC1)

如果我理解正确,它似乎试图使用
OutputArray::Create(int,const int*,int,int,bool,int)
而不是
Mat::Create(Size,int-type)


有人能给我解释一下它为什么这样做或者我做错了什么吗?

我也遇到了类似的问题,即,我试图填充一个输出阵列,但却遇到了问题。你发现了吗?没有,最后我用了一个API为我做了所有的工作。
E/cv::error(): OpenCV Error: Null pointer (create() called for the missing output array)
in void cv::_OutputArray::create(int, const int*, int, int, bool, int) const, file 
/Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp, line 2437