Canny边缘检测C ++显示错误?

时间:2018-11-20 04:28:48

标签: android c++ opencv java-native-interface native

我是native c++opencv的初学者,所以如果我的问题很愚蠢,请原谅。基本上,我是将位图传递给{em>的native C++使用opencv进行canny边缘检测,但问题是显示错误。我这样做的程序可能是错误的。因此,有人可以帮我解决此问题吗?

代码Java:

Bitmap new_bitmap=bitmap.copy(Bitmap.Config.ARGB_8888,true);

            int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];

            //Converting bitmap to byteArray
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            new_bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] FrameData = stream.toByteArray();
            //bitmap.recycle();

            ImageProcessing(bitmap.getWidth(), bitmap.getHeight(), FrameData, pixels);
            new_bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
            imgView.setImageBitmap(new_bitmap);

代码本机C ++:

#include <jni.h>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>

using namespace std;
using namespace cv;

  Mat * mCanny = NULL;

  extern "C"
  jboolean
  Java_opengl_community_testopencv_MainActivity_ImageProcessing(
    JNIEnv* env, jobject thiz,
    jint width, jint height,
    jbyteArray NV21FrameData, jintArray outPixels)
 {
jbyte * pNV21FrameData = env->GetByteArrayElements(NV21FrameData, 0);
jint * poutPixels = env->GetIntArrayElements(outPixels, 0);

if ( mCanny == NULL )
{
    mCanny = new Mat(height, width, CV_8UC1);
}

Mat mGray(height, width, CV_8UC1, (unsigned char *)pNV21FrameData);
Mat mResult(height, width, CV_8UC4, (unsigned char *)poutPixels);
IplImage srcImg = mGray;
IplImage CannyImg = *mCanny;
IplImage ResultImg = mResult;

 cvCanny(&srcImg, &CannyImg, 80, 100, 3);
 //cvSmooth(&srcImg,&CannyImg,3,0,0,0);
 cvCvtColor(&CannyImg, &ResultImg, CV_GRAY2BGRA);
//cvCvtColor(&srcImg, &CannyImg, CV_BGR2GRAY);

env->ReleaseByteArrayElements(NV21FrameData, pNV21FrameData, 0);
env->ReleaseIntArrayElements(outPixels, poutPixels, 0);
return true;
}

错误:

11-19 23:12:30.264 2645-2645/opengl.community.testopencv E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
MAX_TEXTURE_SIZE: 16384

0 个答案:

没有答案