1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| extern "C" JNIEXPORT jobject JNICALL Java_cn_xiaoxige_opencvdemo2_MainActivity_tmpStitchBitMap2(JNIEnv *env, jobject thiz, jobjectArray bitmaps, jfloat matchConf, jboolean isNeedMatInfo) {
jclass resultClass = env->FindClass("cn/xiaoxige/opencvdemo2/entity/StitchBitmapResult"); jmethodID initMethodId = env->GetMethodID(resultClass, "<init>", "()V"); jobject result = env->NewObject(resultClass, initMethodId);
jfieldID codeFieldId = env->GetFieldID(resultClass, "code", "I"); jfieldID widthFieldId = env->GetFieldID(resultClass, "width", "I"); jfieldID heightFieldId = env->GetFieldID(resultClass, "height", "I"); jfieldID matAddress = env->GetFieldID(resultClass, "matAddress", "J");
try { vector<Mat> mats; int size = env->GetArrayLength(bitmaps); mats.reserve(size); for (int i = 0; i < size; ++i) { Mat mat; if (bitmapToMatrix(env, env->GetObjectArrayElement(bitmaps, i), mat)) { mats.push_back(mat); } } Ptr<Stitcher> stitcher = Stitcher::create(); if (stitcher == nullptr) { env->SetIntField(result, codeFieldId, -1); return result; }
auto *matcher = new detail::BestOf2NearestMatcher(true, matchConf); stitcher->setFeaturesMatcher(matcher); stitcher->setFeaturesFinder(new detail::OrbFeaturesFinder()); stitcher->setBundleAdjuster(new detail::BundleAdjusterRay()); stitcher->setSeamFinder(new detail::NoSeamFinder); stitcher->setExposureCompensator(new detail::NoExposureCompensator()); stitcher->setBlender(new detail::FeatherBlender());
Mat *mat = new Mat(); Stitcher::Status state = stitcher->stitch(mats, *mat); env->SetIntField(result, codeFieldId, (jint) state); if (state == Stitcher::Status::OK) { env->SetIntField(result, widthFieldId, mat->cols); env->SetIntField(result, heightFieldId, mat->rows); if (isNeedMatInfo) { env->SetLongField(result, matAddress, (jlong) mat); } } if (!isNeedMatInfo) { delete mat; } return result; } catch (...) { env->SetIntField(result, codeFieldId, -1); return result; } }
|