Android Opencv 无法拼接所有图像

问题描述

我正在使用 Opencv 拼接 API 在我的 android 设备中拼接图像,因为我有 C++ 代码。在 ndk 的帮助下,我能够在 android 中运行代码。但问题是它没有拼接所有类型的图像。它能够拼接大多数具有重叠和图像变化的图像。我正在尝试执行垂直拼接,首先我已经对图像垫进行了转置,然后进行了拼接。但它缝合了大部分图像,但不是一些对我的项目很重要的图像。结帐未缝合的附加图像。这是我的拼接代码的 C++ 实现

    #include <jni.h>
#include "opencv2/opencv.hpp"
#include "opencv2/stitching.hpp"
#include <android/log.h>

using namespace std;
using namespace cv;

extern "C" JNIEXPORT void JNICALL Java_com_example_sunscape_NativePanorama_processpanorama
(jnienv * env,jclass clazz,jlongArray imageAddressArray,jlong outputAddress){
// Get the length of the long array
jsize a_len = env->GetArrayLength(imageAddressArray);
// Convert the jlongArray to an array of jlong
jlong *imgAddressArr = env->GetLongArrayElements(imageAddressArray,0);
// Create a vector to store all the image
#define  LOG_TAG    "testjni"
 vector< Mat > imgVec;
 for(int k=0;k<a_len;k++)
{
// Get the image
Mat & curimage=*(Mat*)imgAddressArr[k];
Mat newimage;
// Convert to a 3 channel Mat to use with Stitcher module
cvtColor(curimage,newimage,COLOR_BGR2RGB);
// Reduce the resolution for fast computation
float scale = 1000.0f / curimage.rows;
resize(newimage,Size(scale * curimage.rows,scale * curimage.cols));
imgVec.push_back(newimage);
}
    __android_log_print(ANDROID_LOG_VERBOSE,"C++Message","WORKING ON STITCHER");
Stitcher::Mode mode = Stitcher::PAnorAMA;


Mat & result  = *(Mat*) outputAddress;
Ptr<Stitcher> stitcher = Stitcher::create(mode);
stitcher->setPanoConfidenceThresh(0.3);
    Stitcher::Status status = stitcher->stitch(imgVec,result);
    if (status != Stitcher::OK)
    {
        __android_log_print(ANDROID_LOG_VERBOSE,"UNABLE TO STITCH IMAGES");
        cout << "Can't stitch images,error code = " << int(status) << endl;
    }else{
        __android_log_print(ANDROID_LOG_VERBOSE,"STITCHING IS DONE SUCCESSFULLY");
        cout << "Stitched successfully ";
    }
//// Release the jlong array
env->ReleaseLongArrayElements(imageAddressArray,imgAddressArr,0);
}

我无法拼接这些图像 https://drive.google.com/file/d/1YsE89WZ859h2clweBOQqeKFN6hjD09jZ/view?usp=sharing https://drive.google.com/file/d/1Y8fepMoVZUs9ywYHGEU60TFaMtCFJlB8/view?usp=sharing

这些情况下的错误

Mat::n_1Mat__JIIII() caught cv::Exception: OpenCV(4.5.1) /build/master_pack-android/opencv/modules/core/src/matrix.cpp:75
1: error: (-215:Assertion Failed) m.dims >= 2 in function 'Mat'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)