Home > Back-end >  The great god help me to see an image stitching process, should put pictures in the directory?
The great god help me to see an image stitching process, should put pictures in the directory?

Time:09-23

#include
#include
#include
#include
#include
#include
# include "opencv2/highgui/highgui. HPP"
# include "opencv2/stitching/stitcher. HPP"
# include "opencv2/stitching/warpers. HPP"

# define MaxPics 30
//F: \ \ Program Files \ opencv \ modules \ stitching \ include \ opencv2 \ stitching
using namespace std;
Using the namespace CV;
Bool try_use_gpu=false;
Int filenum;
Vector Imgs;
String result_name="result. JPG";
//void printUsage ();
//int parseCmdArgs (int arg c, char * * argv);
Int readDir (char * path, char fnames [MaxPics] [100]).

Int readDir (char * path, char fnames [MaxPics] [100])
{
Struct _finddata_t c_file;
Intptr_t hFile;
Filenum=0;

Char fullpath [100].

Sprintf (fullpath, "% s \ \ *. JPG", path);
//Find first. C file in current directory
If ((hFile=_findfirst (fullpath, & amp; C_file))==1 l)
Printf (" No *. JPG files in the current directory % s! \ n ", fullpath);
The else
{
Printf (" Listing of JPG files in the directory % s \ n \ n ", path);
Printf (" RDO HID SYS ARC FILE SIZE \ n ", ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ", ");
Do {
Printf ((c_file attrib & amp; _A_RDONLY)? "Y" : "N");
Printf ((c_file attrib & amp; _A_SYSTEM)? "Y" : "N");
Printf ((c_file attrib & amp; _A_HIDDEN)? "Y" : "N");
Printf ((c_file attrib & amp; _A_ARCH)? "Y" : "N");
//ctime_s (buffer, _countof (buffer), & amp; C_file. Time_write);
Printf (" % 15 s % 9 ld \ n ", c_file. Name, c_file. Size);
Sprintf (fnames [filenum], "% s \ \ % s", path, c_file. Name);
Filenum++;
} while (_findnext (hFile, & amp; C_file)==0);
_findclose (hFile);
}
Return filenum;
}
Int main (int arg c, char * argv [])
{
Clock_t start and finish;
Double totaltime.
Start=clock ();


Argv [1]="PIC";
Char fdir [MaxPics] [100];
Filenum=readDir (argv [1], fdir);
Mat img, pano;
for(int i=0 ; iImg=imread (fdir [I]);
Imgs. Push_back (img);
}
Stitcher Stitcher=Stitcher: : createDefault (try_use_gpu);
Stitcher. SetRegistrationResol (0.1);//in order to accelerate, I choose 0.1, the default is 0.6, the slowest maximum 1, this method is used for feature point detection phase, if can't find the feature points, higher
//stitcher. SetSeamEstimationResol (0.1);//default is 0.1
//stitcher. SetCompositingResol (1);//default is 1, for feature point detection phase, can't find the feature point, change - 1
Stitcher. SetPanoConfidenceThresh (1);//the default is 1, seen any set of 0.6 and 0.4
Stitcher. SetWaveCorrection (false);//default is true, false, to accelerate the choose says skip steps WaveCorrection
//stitcher. SetWaveCorrectKind (detail: : WAVE_CORRECT_HORIZ);//you can also choose the detail: : WAVE_CORRECT_VERT, spectrum correction (wave correction) function (horizontal/vertical orientation correction), because setWaveCorrection set of false, it's no use this statement

//to find surf feature points algorithm, this algorithm large amount of calculation, but the rigid motion, scaling, relatively stable under the radiation of the environmental impact, and so on and so forth
Detail: : SurfFeaturesFinder * featureFinder=new detail: : SurfFeaturesFinder ();
Stitcher. SetFeaturesFinder (featureFinder);

//find feature points the ORB algorithm, but found the grass this gallery, this algorithm can't finish stitching
//detail: : OrbFeaturesFinder * featureFinder=new detail: : OrbFeaturesFinder ();
//stitcher. SetFeaturesFinder (featureFinder);

//the Features the matcher which finds two best matches for each feature and leaves the best one, only if the thewire between descriptor distances is greater than the threshold match_conf.
Detail: : BestOf2NearestMatcher * matcher=new detail: : BestOf2NearestMatcher (=match_conf default is false, f/0.5 * 0.65, 0.8, I choose to choose too big can't feature points, failed */0.8);
Stitcher. SetFeaturesMatcher (matcher);

//Rotation Estimation, It takes the features of all images, pairwise matches between all images and estimates rotations of all cameras.
//Implementation of the camera parameters refinement algorithm which minimizes the sum of the distances between the rays passing through the camera center and a feature, this time
Stitcher. SetBundleAdjuster (new detail: : BundleAdjusterRay ());
//Implementation of the camera parameters refinement algorithm which minimizes the sum of the reprojection error squares.
//stitcher. SetBundleAdjuster (new detail: : BundleAdjusterReproj ());

//Seam Estimation
//Minimum graph cut - -based seam estimator
//stitcher. SetSeamFinder (new detail: : GraphCutSeamFinder (detail: : GraphCutSeamFinderBase: : COST_COLOR));//default is the
//stitcher. SetSeamFinder (new detail: : GraphCutSeamFinder (detail: : GraphCutSeamFinderBase: : COST_COLOR_GRAD));//GraphCutSeamFinder second form
//what SeamFinder also need not, Stub seam estimator which does nothing.
Stitcher. SetSeamFinder (new detail: : NoSeamFinder);
//Voronoi diagram - -based seam estimator.
//stitcher. SetSeamFinder (new detail: : VoronoiSeamFinder);

//exposure compensators exposure compensation
//stitcher. SetExposureCompensator (new detail: : BlocksGainCompensator ());//the default is the
//don't exposure compensation
Stitcher. SetExposureCompensator (new detail: : NoExposureCompensator ());
//Exposure compensator which tries to remove Exposure related artifacts by adjusting the image intensities
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related