Image Stitching function
The first method: each pixel of an image by traversing the image, to be assigned to an output image mosaic
// Image Stitching function // imageVector input image array // outputImage output image // colCount_ // number of each line of the image // imageWidth_, imageHeight_ // each input image width and height, the same size must be void ImageStitching (Vector <Mat > imageVector, Mat & outputImage, int rowImageCount_, int imageWidth_, int imageHeight_) { for(int i=0;i<imageVector.size();i++) { Mat image = imageVector.at(i); for(int row=0;row<image.rows;row++) { Vec3b * = image.ptr pixRow <Vec3b> (Row); // pixRow row pointer Vec3b outPixRow * = outputImage.ptr <Vec3b> (Row + I / rowImageCount_ * imageHeight_); // pointer offset for ( int COL = 0 ; COL <image.cols; COL ++ ) { outPixRow[col + i%rowImageCount_*imageWidth_] = pixRow[col]; } } } // imshow("outputImage",outputImage); }
The second method: OpenCV comes with stitching function hconcat , vconcat, the stitching multiple images at the same time.
// Image Stitching function // imageVector input image array // outputImage output image // colCount_ // number of each line of the image // imageWidth_, imageHeight_ // each input image width and height, the same size must be void ImageStitching (Vector <Mat > imageVector, Mat & outputImage, int rowImageCount_, int imageWidth_, int imageHeight_) { Vector <Mat> imageVec; // store images to be merged lateral Vector <Mat> hImageVec; // store the combined results of FIG lateral for(int i=0;i<imageVector.size();i++) { // horizontal merger IF ((I + . 1 )% rowImageCount_ == 0 ) // number of images is sufficient { Combine MAT (imageHeight_, imageWidth_, CV_8UC3); // for each row of the combined results of FIG imageVec.push_back (imageVector.at (i)); hconcat (imageVec, Combine); // horizontal mergers hImageVec.push_back (combine); imageVec.clear (); // empty, continue to add next line of picture } the else { imageVec.push_back(imageVector.at(i)); } } // the merged image vertically the synthesis of a transverse FIG vconcat (hImageVec, outputImage); // imshow ( "outputImage2", outputImage); }
call function
Mat img1,img2,img3,img4,img5,img6; vector<Mat> inputImageVector; img1 = imread("1.bmp"); img2 = imread("2.bmp"); img3 = imread("3.bmp"); img4 = imread("4.bmp"); img5 = imread("5.bmp"); img6 = imread("6.bmp"); if(!img1.empty() && !img2.empty() && !img3.empty() && !img4.empty() && !img5.empty() && !img6.empty()) { inputImageVector.push_back(img1); inputImageVector.push_back(img2); inputImageVector.push_back(img3); inputImageVector.push_back(img4); inputImageVector.push_back(img5); inputImageVector.push_back(img6); const int imageWidth = 54 is ; const int imageHeight = 55 ; const int rowImageCount = . 3 ; // represents three line image synthesis Mat outputimage(imageHeight*2,imageWidth*3,CV_8UC3); // const int rowCount = 2; ImageStitching(inputImageVector,outputimage,rowImageCount,imageWidth,imageHeight); }
Show results
Unstitched picture
After the entire image
Time-consuming function
Double Start = ( Double ) GetTickCount (); Test () // function Double Time = (( Double ) GetTickCount () - to) / getTickFrequency (); // Time is a function of the operating time
By getTickCount (), getTickFrequency () function takes the test, as described above. Specific time-consuming but please ~ self-test
end
The end of the ~ do not know what to say what, er er er ah uh, I hope my article to be helpful it.