0

I want to implement image mosaicking with Java call C++ and This is my Java code

package com.example.jni;

public class JNITest {
    static {          
        System.loadLibrary("ConsoleApplication123");      
    }   

    // native method : the floder url that has pictures to be mosaic
    public native String hello(String name); 
} 

I compile it to JNITest.h and in this way I pass a folder rul there have photos, And then in c + + carry on image splicing.but i do not konw how to read these photos in this folder.If I can read these pictures,I can implement image mosaicking,and finaly I want to return the new foler url that has the mosaicked picturess and this is my image_mosaicking.cpp

/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni.h"
#include <iostream>  
#include <fstream>  
#include "opencv2/highgui/highgui.hpp"  
#include "opencv2/stitching/stitching.hpp"  
using namespace std;
using namespace cv;

bool try_use_gpu = true; //false;  
vector<Mat> imgs;
string result_name = "result.jpg";
/* Header for class com_example_jni_JNITest */

#ifndef _Included_com_example_jni_JNITest
#define _Included_com_example_jni_JNITest
#ifdef __cplusplus
extern "C" {
#endif
    /*
    * Class:     com_example_jni_JNITest
    * Method:    hello
    * Signature: (Ljava/lang/String;)Ljava/lang/String;
    */
    JNIEXPORT jstring JNICALL Java_com_example_jni_JNITest_hello
    (JNIEnv *env, jobject, jstring path) {
        //read the path of this folder
        const char* temp_path = env->GetStringUTFChars(path, false);
        int numberOfPics = 0;
        string pics[100];

        //how to get the number of pictures in this folder 
        //how to get every picture's name into pics[]

        for (int i = 1; i < numberOfPics; ++i) {
            Mat img = imread(pics[i]);  //read every pictures in this folder
            if (img.empty()) {
                cout << "Can't read image '" << argv[i] << "'\n";
                // return  null;
            }
            imgs.push_back(img);
        }
            Mat pano;
            Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
            Stitcher::Status status = stitcher.stitch(imgs, pano);

            if (status != Stitcher::OK) {
                cout << "Can't stitch images, error code = " << int(status) << endl;
                // retrun null;
            }

            imwrite(result_name, pano);
            imshow("show", pano);
            cv::waitKey(0);

        jclass strClass = env->FindClass("Ljava/lang/String;");
        jstring imgName = env->NewStringUTF(temp_path);

        //rteurn the new folder that has mosaicked pictures


    }

#ifdef __cplusplus
}
#endif
#endif
Jon Snow
  • 59
  • 10
  • So is your question "How do I load an image in `C++` using `opencv3.1`? – Galik Mar 12 '17 at 10:55
  • Possible duplicate of https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c – Galik Mar 12 '17 at 10:58
  • No ,in a folder that has some pictures than can be connected .In java I pass this folder url ,and in c++ I want to connect these pictures .but first of all I must read these pictures ,and I do not how to do read ? – Jon Snow Mar 12 '17 at 11:08

0 Answers0