Image stitching in android using OpenCV

半腔热情 提交于 2019-12-23 18:23:17

问题


I am trying to stitch images like Panorama View in android.I am using Android NDK and OpenCv library for that.I am using below code of Jni for stitching images

First Method:

extern "C" {

JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3Native_FindFeatures(
    JNIEnv*, jobject, jlong im1, jlong im2, jlong im3, jint no_images) {

vector<Mat> imgs;
bool try_use_gpu = false;
Mat& temp1 = *((Mat*) im1);
Mat& temp2 = *((Mat*) im2);
Mat& pano = *((Mat*) im3);
 __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "Before stitching Images\n...");
 if(temp1.empty() || temp2.empty())
  {

    __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "Can’t read one of the images\n...");
     printf("Can’t read one of the images\n");

   }
 else{
imgs.push_back(temp1);
imgs.push_back(temp2);

Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status = stitcher.stitch(imgs, pano);

    if (status != Stitcher::OK)
    {
__android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "Can't stitch images, error code = %i" +status);
    }
  else
  {
 __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "Stitching Image Successfully");
   }

Above code is working fine for some images but If I take images using camera and try to stitch that images using above code then it’s not working.I am using below code for calling native code from android

FindFeatures(Highgui.imread(path + "Pano1.jpg").getNativeObjAddr(), Highgui.imread(path+"Pano2.jpg").getNativeObjAddr(),panorama.getNativeObjAddr(), 2);
Highgui.imwrite(StitchImageDir.getPath()+ File.separator + "panoStich"+dateFormat.format(dateNow) +mImageExt, panorama);

Method Declaration

public native void FindFeatures(long image1, long image2, long image3,int count);

Second Method:

I have also tried to stitch images using SurfFeatureDetector whose code available here.In this code i got the compilation error of undefined reference to `cv::SURF::SURF(double, int, int, bool, bool)'.Although I have included all the necessary libraries in header and also in build path of NDK.I can't understand what is the problem is?

Anyone of you have any idea regarding any of the above two methods of image stitching or any other new idea or method for image stitching then please suggest me.Thanks in advance.


回答1:


Concerning the compilation error: It seems that you don't link opencv properly, or you miss adding the lib files. check that you add these libs if you are using Debug mode OpenCV 2.x.x:

opencv_nonfree2xxd.lib

opencv_features2d2xxd.lib



来源:https://stackoverflow.com/questions/15492259/image-stitching-in-android-using-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!