私はAndroid用のイメージステッチングアプリケーションを作成しようとしています。私はOpenCVのネイティブ部分にAndroid NDKを使用しています。起こるべきではない3つの異なる行動があり、私は彼らがなぜ起こるかについての説明が大好きです。OpenCV Androidの動作の説明が必要
一部の画像(デバイス/同じ解像度の同じカメラからのもの)のみがクラッシュしません。クラッシュしたときのエラーは、私のC++コードの下にあります。
イメージステッチの結果は、1つのイメージをバレルするように見えます。 (私はこの結果を他の80%がクラッシュする間に約20%の時間を得る)。私はこれがループののリサイズラインと関係があると思います。この本の例は、列と行を10で割ったものです。これを行うと、イメージはわずかにバレル化されますが、非常にピクセル化されています。繰り返しますが、この場合も1つの画像にしか見えません。私はこのようなスティッチャーの設定を設定しない場合
:
stitcher.setRegistrationResol(-1); /// 0.6 stitcher.setSeamEstimationResol(-1); /// 0.1 stitcher.setCompositingResol(-1); //1 stitcher.setPanoConfidenceThresh(-1); //1 stitcher.setWaveCorrection(true); stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
出力画像は空になります。これは私には奇妙です。なぜなら、この本の例は、それがなければうまく動作するからです。
私のプロジェクトのC++部分にはthis bookの第6章を使用しています。ここに私のC++のコードは次のとおりです。ここで
#include <jni.h>
#include "aaron_picstitch_MyNDK.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/stitching/stitcher.hpp>
#include <opencv2/core/mat.hpp>
#include <vector>
#include <android/log.h>
using namespace std;
using namespace cv;
char FILEPATH[100] = "/storage/emulated/0/PicStitch/cppResult.jpg";
//char FILEPATH1[100] = "/storage/emulated/0/PicStitch/cppTesta.jpg";
//char FILEPATH2[100] = "/storage/emulated/0/PicStitch/cppTestb.jpg";
JNIEXPORT void JNICALL Java_aaron_picstitch_CameraActivity_stitchImages(JNIEnv *env, jobject , jobjectArray images, jint size, jlong panoAddr)
{
vector <Mat> imgs = vector<Mat>();
Mat pano = Mat();
Mat temp = Mat();
Mat &srcRes = *(Mat *)panoAddr, img;
jclass clazz = (env)->FindClass("org/opencv/core/Mat");
jmethodID getNativeObjAddr = (env)->GetMethodID(clazz, "getNativeObjAddr", "()J");
__android_log_print(ANDROID_LOG_VERBOSE, "IN CPP TESTTEST", "ADDR: %lld", panoAddr);
int i = 0;
for (i = 0; i < size; i++)
{
jobject obj = (env->GetObjectArrayElement(images, i));
jlong result = (env)->CallLongMethod(obj, getNativeObjAddr, NULL);
img = *(Mat *)result;
resize(img, temp, Size(img.rows/2, img.cols/2));
imgs.push_back(temp);
env->DeleteLocalRef(obj);
}
env->DeleteLocalRef(images);
Stitcher stitcher = Stitcher::createDefault();
__android_log_print(ANDROID_LOG_VERBOSE, "IN CPP", "HERE 1 temp rows is: %d", temp.rows);
stitcher.setRegistrationResol(-1); /// 0.6
stitcher.setSeamEstimationResol(-1); /// 0.1
stitcher.setCompositingResol(-1); //1
stitcher.setPanoConfidenceThresh(-1); //1
stitcher.setWaveCorrection(true);
stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
__android_log_print(ANDROID_LOG_VERBOSE, "IN CPP", "Right before .stitch");
Stitcher::Status status = stitcher.stitch(imgs, pano);
__android_log_print(ANDROID_LOG_VERBOSE, "IN CPP", "HERE 2 Pano rows is : %d", pano.rows);
if (status == Stitcher::OK)
{
__android_log_print(ANDROID_LOG_VERBOSE, "IN CPP", "STITCHING SHOULD WORK");
}
//pano.copyTo(srcRes);
imwrite(FILEPATH, pano);
}
は、弾丸#1からのエラーです:
04-22 20:51:47.192 32115-32651/aaron.picstitch E/cv::error(): OpenCVError Assertion failed (s >= 0) in void cv::setSize(cv::Mat&, int, int const*, const size_t*, bool), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matrix.cpp, line 116
04-22 20:51:47.192 32115-32651/aaron.picstitch A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 32651 (AsyncTask #1)
問題のように大きくないもう一つの奇妙な問題は、私はgetNativeObjAddrを(使用していることである)についてMatオブジェクトはプロジェクトのJava部分にあるので、結果をそこに入れることができますが、アクセスしようとするたびにsegfaultを取得します。それがなぜ起こるのか分かりませんが、その問題は回避できます。
私の問題についてのご意見はありがとうございます!
リンクが機能していないことを確認してください。 –