Merging images using SeamlessClone function in Android

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Merging images using SeamlessClone function in Android

opencv-users mailing list
Hi guys,
I'm trying to implement simple blending of two images using OpenCV's "seamlessClone" function. I'm getting an exception which sayserror: (-215) CV_MAT_TYPE(mtype) == m.type()
Here is the source code for it:
    public class SeamlessClone extends AppCompatActivity {
        public static final String TAG = "Seamless Clone demo";
        static {            if (!OpenCVLoader.initDebug()) {                // Handle initialization error            }        }

        @Override        protected void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentView(R.layout.activity_seamless_clone);
            Bitmap destinationBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lightning);            Log.d(TAG, "bitmap: " + destinationBitmap.getWidth() + "x" + destinationBitmap.getHeight());

            Mat destination = new Mat(destinationBitmap.getHeight(),                destinationBitmap.getWidth(), CvType.CV_8UC4);            Utils.bitmapToMat(destinationBitmap, destination);            Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.airplane);
            Log.d(TAG, "bitmap: " + sourceBitmap.getWidth() + "x" + sourceBitmap.getHeight());
            Mat source = new Mat(sourceBitmap.getHeight(),                sourceBitmap.getWidth(), CvType.CV_8UC4);            Utils.bitmapToMat(sourceBitmap, source);                    Mat mask = new Mat(source.rows(),source.cols(),source.depth(),Scalar.all(255));
            Point point = new Point(destination.cols()/2,destination.rows()/2);
            Mat result = new Mat(destinationBitmap.getHeight(),                destinationBitmap.getWidth(), CvType.CV_8UC4);
            Photo.seamlessClone(source, destination, mask, point, result, Photo.NORMAL_CLONE);
            Utils.matToBitmap(result, destinationBitmap);
            ImageView imageView = (ImageView) findViewById(R.id.clone_result);
            imageView.setImageBitmap(destinationBitmap);        }    }

And following is the error log from the logcat:
    E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV    E/cv::error(): OpenCV Error: Assertion failed (CV_MAT_TYPE(mtype) == m.type()) in void cv::_OutputArray::create(int, const int*, int, int, bool, int) const, file /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp, line 2297    E/org.opencv.photo: photo::seamlessClone_10() caught cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const    E/AndroidRuntime: FATAL EXCEPTION: main    Process: com.example.hemisphere.opencvexample, PID: 1905    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hemisphere.opencvexample/com.example.hemisphere.opencvexample.SeamlessClone}:    CvException [org.opencv.core.CvException: cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const                                                                                    ]        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)        at android.app.ActivityThread.access$800(ActivityThread.java:155)        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)        at android.os.Handler.dispatchMessage(Handler.java:102)        at android.os.Looper.loop(Looper.java:135)        at android.app.ActivityThread.main(ActivityThread.java:5343)        at java.lang.reflect.Method.invoke(Native Method)        at java.lang.reflect.Method.invoke(Method.java:372)        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)        Caused by: CvException [org.opencv.core.CvException: cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:2297: error: (-215) CV_MAT_TYPE(mtype) == m.type() in function void cv::_OutputArray::create(int, const int*, int, int, bool, int) const                                                                                    ]        at org.opencv.photo.Photo.seamlessClone_0(Native Method)        at org.opencv.photo.Photo.seamlessClone(Photo.java:581)        at com.example.hemisphere.opencvexample.SeamlessClone.onCreate(SeamlessClone.java:72)        at android.app.Activity.performCreate(Activity.java:6010)        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)        ... 10 more

Can you please help me resolving this issue?
Thanks & Regards,Pratik Jambhulkar+91 9673473491
Loading...