#include <iostream> #include <fstream> #include "opencv2/highgui/highgui.hpp" #include "opencv2/stitching/stitcher.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/core/core.hpp" using namespace std; using namespace cv; bool try_use_gpu = false; bool divide_images = false; // Define mode for stitching as panoroma // (One out of many functions of Stitcher) //Stitcher:: mode = Stitcher::composePanorama; string result_name = "result.jpg"; // Array for pictures vector<mat> imgs; // methods int main(int argc, char* argv[]) { // Get all the images that need to be // stitched as arguments from command line for (int i = 1; i < 3; ++i) { // Read the ith argument or image // and push into the image array Mat img = imread("C:\\Users\\leno\\Documents\\640x480dove\\OCR_REF\\FONT-0.bmp",IMREAD_GRAYSCALE); Mat img1 = imread("C:\\Users\\leno\\Documents\\640x480dove\\OCR_REF\\FONT-1.bmp", IMREAD_GRAYSCALE); Mat img2 = imread("C:\\Users\\leno\\Documents\\640x480dove\\OCR_REF\\FONT-2.bmp", IMREAD_GRAYSCALE); if (img.empty()) { // Exit if image is not present cout << "Can't read image '" << img << "'\n"; return -1; } imgs.push_back(img); if (img1.empty()) { // Exit if image is not present cout << "Can't read image '" << img << "'\n"; return -1; } imgs.push_back(img1); if (img2.empty()) { // Exit if image is not present cout << "Can't read image '" << img << "'\n"; return -1; } imgs.push_back(img2); } // Define object to store the stitched image Mat pano; // Create a Stitcher class object with mode panoroma //Ptr<stitcher> stitcher = Stitcher::create( try_use_gpu); Stitcher stitcher = Stitcher::createDefault(false); // Command to stitch all the images present in the image array Stitcher::Status status = stitcher.stitch(imgs, pano); if (status != Stitcher::OK) { // Check if images could not be stiched // status is OK if images are stiched successfully cout << "Can't stitch images\n"; return -1; } // Store a new image stiched from the given //set of images as "result.jpg" imwrite("result.jpg", pano); // Show the result imshow("Result", pano); waitKey(0); return 0; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)