Android OpenCV 3.1 seamlessclone [closed]

asked 2016-08-16 06:57:33 -0600

alex011235 gravatar image

updated 2016-08-16 08:14:03 -0600

I'm trying to execue the following lines in native OpenCV for Android (C++). And everything compiles.

warpedSub.convertTo(warpedSub, CV_8UC3);
img2sub.convertTo(img2sub, CV_8UC3);
output.convertTo(output, CV_8UC3);
maskSub.convertTo(maskSub, CV_8UC1);

seamlessClone(warpedSub, img2sub, maskSub, center, output, NORMAL_CLONE);

But I get this error when executing:

 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 /builds/master_pack-android/opencv/modules/core/src/matrix.cpp, line 2236

According to the OpenCV documentation, I have the correct types. I have also tested a prototype completely in C++ on my desktop computer and it all works fine! I don't know what to do, please help!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2016-08-16 09:18:47.795256

Comments

what are all those convertTo()'s for ?

are you aware, that those only change the depth, not the channel count ?

berak gravatar imageberak ( 2016-08-16 07:17:39 -0600 )edit

how do you initialize those Mat's in the 1st place ? please show some more code above those lines.

berak gravatar imageberak ( 2016-08-16 07:20:28 -0600 )edit

In Java:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 1;

    bitmap1 = BitmapFactory.decodeFile(path1, options);
    bitmap2 = BitmapFactory.decodeFile(path2, options);

    Mat img1 = new Mat();
    bitmapToMat(bitmap1, img1);
    Mat img2 = new Mat();
    bitmapToMat(bitmap2, img2);

where path1 and path2 are the paths to the bitmaps.

In C++:

Mat img1 = *(Mat*)addrImg1;
Mat img2 = *(Mat*)addrImg2;

where the addrImg1 and addrImg2 are jlong:s

alex011235 gravatar imagealex011235 ( 2016-08-16 07:59:49 -0600 )edit

again: reason behind the convertTo's ?

berak gravatar imageberak ( 2016-08-16 08:31:09 -0600 )edit

I removed them. But I think Java sends 4-channel images, so I have to convert them to 3-channel images.

alex011235 gravatar imagealex011235 ( 2016-08-16 08:45:56 -0600 )edit

ahh, that might explain the complaint about the types.

please use Imgproc.cvtColor(src,dst,COLOR_BGRA2BGR) then, not convertTo()

berak gravatar imageberak ( 2016-08-16 08:49:09 -0600 )edit

It seems to work! Thank you very much!

alex011235 gravatar imagealex011235 ( 2016-08-16 09:13:57 -0600 )edit