Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried many codes and even many websites, but i get only one code which uses stitcher function of opencv. There is no problem in that function, but the major problem is i can only load one image into the stitcher. So, due to that the code exits with exception. Please help!

What I have tried:

The code below is the code given in almost all websites but it does'nt work correctly.
The line Stitcher statues generates an error that there is only one image loaded. So, due to that the code doesnt work. Please help me with the correct code.

The code which i have used is as follows:
C++
#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;
}
Posted
Updated 25-Jul-18 2:54am
v2
Comments
Richard MacCutchan 25-Jul-18 9:09am    
What is the error, and why are you running the same code 3 times?
11917640 Member 26-Jul-18 2:53am    
Is this your real code? vector<mat> imgs; and Mat img = ... Looks like different types. Show your actual code, and exact error message.

1 solution

You must know WHY your code isnt working. Maybe the files arent there, or your loop is non sense. Why are you loading the 3 files 3 times?

You should learn to use the debugger for your code.
 
Share this answer
 
Comments
Member 13411007 25-Jul-18 9:00am    
it is not because of the loop. I have used the code without the loop also. The error continued for the same. The loop is not nonsense, i have learned my code well enough and files are there in their respective folder.
Member 13411007 25-Jul-18 9:03am    
you should know why i have put the loop if you have learned the code well. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900