Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV Error: Assertion failed (ssize.area() > 0) in void cv::resize(cv::InputArray, cv::OutputArray, cv::Size, double, double, int)

I am creating a toy android app that demonstrates OpenCV's panoramic stitching capabilities using the OpenCV 2.4.6. However, I keep getting this error. The resize method gets called somewhere in the library and I do not know how to properly fix it. Can someone help?

Java code below:

public void stitchImages()
{
    // images_to_be_stitched is a List<Mat>
    if (!images_to_be_stitched.isEmpty())
    {
        for (int j = 0; j < images_to_be_stitched.size(); j++)
        {
            writeImage(images_to_be_stitched.get(j), j);
        }

        Log.i("stitchImages", "Done writing to disk. Starting stitching " + images_to_be_stitched.size() + " images");

        // panorama is a Mat
        // Create an array and fill it with the addresses of the images
        int[] imageAddresses = new int[images_to_be_stitched.size()];
        for (int k = 0; k < images_to_be_stitched.size(); k++)
        {
            imageAddresses[k] = (int) images_to_be_stitched.get(k).getNativeObjAddr();
        }

        // This is where I call a native method called FindFeatures which kicks off the stitching
        // Stitch the images together and create the panorama image
        FindFeatures(imageAddresses, panorama, tempImageDir.getPath());

        writePano(panorama);

        Log.i("stitchImages", "Done stitching. Writing panarama");

        writePano(panorama);

        Log.i("stitchImages", "deleting temp files");

        deleteTmpIm();
    }
}

Below is my native C++ code:

#include <android_native_app_glue.h>

#include <errno.h>
#include <jni.h>
#include <sys/time.h>
#include <time.h>
#include <android/log.h>

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <iostream>
#include <string>

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/stitching/stitcher.hpp>

using namespace std;
using namespace cv;

#define  LOG_TAG    "OCV:libnative_activity"
#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGW(...)  __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

extern "C" JNIEXPORT void JNICALL Java_org_opencv_samples_NativeActivity_CvNativeActivity_FindFeatures(JNIEnv *env, jobject obj, jintArray arrayOfImages, Mat retPanoImage, jstring imageDir)
{
    vector<Mat> imgs;
    bool try_use_gpu = false;
    // Get length of the input java array
    jsize lenOfArray = env->GetArrayLength(arrayOfImages);
    // Create an array of addresses from the input imageAddresses array
    jint* array = env->GetIntArrayElements(arrayOfImages, 0);

    for (int k = 0; k < lenOfArray; ++k)
    {
        jint image = array[k];

        // Create a Mat object from the memory address of the image
        Mat img = imdecode(image, CV_LOAD_IMAGE_COLOR);

        // Put that Mat img into a vector of Mats for the stitcher
        imgs.push_back(img);
    }

    // Release the memory alotted for the array now that we are done with it
    env->ReleaseIntArrayElements(arrayOfImages, array, 0);

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