Home > other >  Use opencv to do image mosaicing, always return ERR_NEED_MORE_IMGS, solving
Use opencv to do image mosaicing, always return ERR_NEED_MORE_IMGS, solving

Time:11-23

Novice do with opencv image mosaicing, always return ERR_NEED_MORE_IMGS error,
Simple calling code is as follows:

CV: : Ptr Stitcher=CV: : stitcher: : create (CV: : stitcher: : Mode: : PANORAMA);
CV: : Stitcher: : the Status Status=Stitcher - & gt; Stitch (vImg, rImg);

If (CV: : Stitcher: : OK==status)
CV: : imshow (" Stitching Result ", rImg);
The else
Printf (" Stitching fail. ");

Opencv version is 4.4.1
Stitching test graph:

CodePudding user response:

There are few people?

CodePudding user response:

Find the reason and change the image sequence, the android seems to be in a certain order, there is no need for iOS, may be android opencv stitching is the underlying, stitching details and highly abstract editions, detail version can set more parameters, have a higher degree of freedom, the android version, my code is as follows:
Extern "C"
JNIEXPORT jobject JNICALL
Env Java_com_zy_fullimagemerge_ImageMergeTool_nativeStitchImages (JNIEnv *, jclass clazz,
JobjectArray bitmaps) {

Int count=env - & gt; GetArrayLength (bitmaps);
STD: : vector Imgs;
for (int i=0; I & lt; The count. I++) {
Jobject bitmap=env - & gt; GetObjectArrayElement (bitmaps, I);
Int width=0;
Int height=0;
Int the depth=0;
Unsigned char * pixels=getPixelsFromBitmap (env, bitmap, & amp; Width, & amp; Height, & amp; The depth);

The int type=the depth==4? CV_8UC4: the depth==3? CV_8UC3: the depth==1? CV_8UC1: CV_8UC4;
Mat Mat=Mat (height, width, type, pixels);


Mat gray;
If (type==CV_8UC4) {
CvtColor (mat, gray, COLOR_RGBA2RGB);
Imgs. Push_back (gray);
//imgs push_back (mat);
{} else if (type==CV_8UC3)
Imgs. Push_back (mat);
} else {
CvtColor (mat, gray, COLOR_GRAY2RGB);
Imgs. Push_back (gray);
}

Free (pixels);
}

Mat result;



Ptr Stitcher=stitcher: : create ();

//this part can be commented out
PtrStitcher - & gt; SetFeaturesMatcher (matcher);
Stitcher - & gt; SetBundleAdjuster (new detail: : BundleAdjusterRay);
Stitcher - & gt; SetSeamFinder (detail: : NoSeamFinder: : createDefault (detail: : SeamFinder: : NO));
Stitcher - & gt; SetExposureCompensator (detail: : NoExposureCompensator: : createDefault (detail: : NoExposureCompensator: : NO));
Stitcher - & gt; SetBlender (new detail: : FeatherBlender ());


Stitcher: : the Status Status=Stitcher - & gt; Stitch (imgs, result);

The int type=result. The type ();
Int the depth=type==CV_8UC4? 4: type==CV_8UC3? 3: type==CV_8UC1? 1:4;


Jobject bitmap=createJavaBitmapWithPixels (env, the result data, the result, cols, result, rows, and the depth);

Return the bitmap;
}


Images have overlapping part, if it fails, change the image sequence

CodePudding user response:

reference dongtinghong reply: 3/f
find the reason and change the image sequence, the android seems to be in a certain order, there is no need for iOS, may be android opencv stitching is the underlying, stitching details and highly abstract editions, detail version can set more parameters, has a higher degree of freedom, the android version, my code is as follows:
Extern "C"
JNIEXPORT jobject JNICALL
Env Java_com_zy_fullimagemerge_ImageMergeTool_nativeStitchImages (JNIEnv *, jclass clazz,
JobjectArray bitmaps) {

Int count=env - & gt; GetArrayLength (bitmaps);
STD: : vector Imgs;
for (int i=0; I & lt; The count. I++) {
Jobject bitmap=env - & gt; GetObjectArrayElement (bitmaps, I);
Int width=0;
Int height=0;
Int the depth=0;
Unsigned char * pixels=getPixelsFromBitmap (env, bitmap, & amp; Width, & amp; Height, & amp; The depth);

The int type=the depth==4? CV_8UC4: the depth==3? CV_8UC3: the depth==1? CV_8UC1: CV_8UC4;
Mat Mat=Mat (height, width, type, pixels);


Mat gray;
If (type==CV_8UC4) {
CvtColor (mat, gray, COLOR_RGBA2RGB);
Imgs. Push_back (gray);
//imgs push_back (mat);
{} else if (type==CV_8UC3)
Imgs. Push_back (mat);
} else {
CvtColor (mat, gray, COLOR_GRAY2RGB);
Imgs. Push_back (gray);
}

Free (pixels);
}

Mat result;



Ptr Stitcher=stitcher: : create ();

//this part can be commented out
PtrStitcher - & gt; SetFeaturesMatcher (matcher);
Stitcher - & gt; SetBundleAdjuster (new detail: : BundleAdjusterRay);
Stitcher - & gt; SetSeamFinder (detail: : NoSeamFinder: : createDefault (detail: : SeamFinder: : NO));
Stitcher - & gt; SetExposureCompensator (detail: : NoExposureCompensator: : createDefault (detail: : NoExposureCompensator: : NO));
Stitcher - & gt; SetBlender (new detail: : FeatherBlender ());


Stitcher: : the Status Status=Stitcher - & gt; Stitch (imgs, result);

The int type=result. The type ();
Int the depth=type==CV_8UC4? 4: type==CV_8UC3? 3: type==CV_8UC1? 1:4;


Jobject bitmap=createJavaBitmapWithPixels (env, the result data, the result, cols, result, rows, and the depth);

Return the bitmap;
}


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull