我正在开发一个android应用程序,其中jni代码和这个代码使用opencv库。
在我的*.cpp文件中,我无法在fastfeaturedetector之后的图像上绘制关键点。我不知道怎么调试。谢谢您!
->*.cpp文件
JNIEXPORT void JNICALL Java_com_project_pic_1mat_MainActivity_fast (JNIEnv *env, jobject thiz, jintArray buf,jint w, jint h)
{
jint *cbuf;
cbuf = env->GetIntArrayElements(buf, NULL);
if(cbuf == 0)
{
return 0;
}
Mat image(h, w, CV_8UC4, (unsigned char*) buf);
vector<KeyPoint> keypoints;
FastFeatureDetector fast(100);
fast.detect(image, keypoints);
for(unsigned int i=0;i<keypoints.size();i++)
{
const KeyPoint& kp = keypoints[i];
circle(image, Point(kp.pt.x, kp.pt.y), 10, cvScalar(255, 0, 255));
}
//drawKeypoints(image, keypoints, image, Scalar::all(255), 1);
int size = w * h;
jintArray result = env->NewIntArray(size);
env->SetIntArrayRegion(result, 0, size, cbuf);
env->ReleaseIntArrayElements(buf, cbuf, 0);
return result;
}
->*.java文件
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.lena);
int w = bmp.getWidth();
int h = bmp.getHeight();
int[] pixels = new int[w * h];
bmp.getPixels(pixels, 0, w, 0, 0, w, h);
int[] resultInt = MainActivity.gray(pixels, w, h);
Bitmap grayimg = Bitmap.createBitmap(w, h, Config.ARGB_8888);
grayimg.setPixels(resultInt, 0, w, 0, 0, w, h);
grayimg.getPixels(pixels, 0, w, 0, 0, w, h);
int[] result_fast = MainActivity.fast(pixels, w, h);
Bitmap fastimg = Bitmap.createBitmap(w, h, Config.ARGB_8888);
fastimg.setPixels(result_fast, 0, w, 0, 0, w, h);
imgView.setImageBitmap(fastimg);
暂无答案!
目前还没有任何答案,快来回答吧!