A Problem with Stitch

asked 2016-06-11 23:02:01 -0500

Downwing gravatar image

updated 2016-06-12 00:48:58 -0500

Recently, I'm working with opencv Stitch class. I try to use some sample code from opencv's stitch class. I also try to use some code from internet. They all seem to be very easy to understand. But the weird thing is that all of them cannot be run correctly. My operating system is Windows 10, x64. My opencv version is 2.4.9. My IDE is Qt 5.5.

Here's the code:

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    cv::Mat im1 = cv::imread("C:\\Users\\bian\\Pictures\\Camera Roll\\WIN_20160607_17_04_45_Pro.jpg");
    cv::Mat im2 = cv::imread("C:\\Users\\bian\\Pictures\\Camera Roll\\WIN_20160607_17_05_08_Pro.jpg");
    cv::imshow("im1",im1);
    cv::imshow("im2",im2);
    cv::Mat im1_gray = grayscaleImg(im1);
    cv::Mat im2_gray = grayscaleImg(im2);
    cv::imshow("im1_gray",im1_gray);
    cv::imshow("im2_gray",im2_gray);
    std::vector<cv::Mat> imgs;
    imgs.push_back(im1_gray);
    imgs.push_back(im2_gray);
    cv::Mat pano;
    bool try_use_gpu = true;
    cv::Stitcher stitcher = cv::Stitcher::createDefault(try_use_gpu);
    cv::Stitcher::Status status = stitcher.stitch(imgs,pano);
    if (status != cv::Stitcher::OK)
    {
        std::cout << "Can't stitch images, error code = " << status << std::endl;
    }else{
        cv::imwrite("stitching image.jpg",pano);
        cv::imshow("拼接",pano);
        cv::waitKey(0);
    }
}

MainWindow::~MainWindow()
{
    delete ui;
}
cv::Mat MainWindow::grayscaleImg(cv::Mat& src)
{
    cv::Mat dst;
    if(src.channels()>1){
        cv::cvtColor(src,dst,CV_BGR2GRAY);
        return dst;
    }else{
        return src;
    }
}

Here's the log:

SetProcessDpiAwareness failed: "COM error 0x80070005  (Unknown error 0x0ffffffff80070005)"
init done
opengl support available
Can't stitch images, error code = 1

Here's the code from opencv:

#include "mainwindow.h"
#include <QApplication>
#include <iostream>
#include <fstream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"

using namespace std;
using namespace cv;

bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "result.jpg";

void printUsage();
int parseCmdArgs(int argc, char** argv);

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
//    MainWindow w;
//    w.show();
    int retval = parseCmdArgs(argc, argv);
    if (retval) return -1;

    Mat pano;
    Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
    Stitcher::Status status = stitcher.stitch(imgs, pano);

    if (status != Stitcher::OK)
    {
        cout << "Can't stitch images, error code = " << status << endl;
        return -1;
    }

    imwrite(result_name, pano);
    return a.exec();
}
void printUsage()
{
    cout <<
        "Rotation model images stitcher.\n\n"
        "stitching img1 img2 [...imgN]\n\n"
        "Flags:\n"
        "  --try_use_gpu (yes|no)\n"
        "      Try to use GPU. The default value is 'no'. All default values\n"
        "      are for CPU mode.\n"
        "  --output <result_img>\n"
        "      The default is 'result.jpg'.\n";
}


int parseCmdArgs(int argc, char** argv)
{
    if (argc == 1)
    {
        printUsage();
        return -1;
    }
    for (int i = 1; i < argc; ++i)
    {
        if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
        {
            printUsage();
            return -1;
        }
        else if (string(argv[i]) == "--try_use_gpu")
        {
            if (string(argv[i + 1]) == "no")
                try_use_gpu = false;
            else if (string(argv[i + 1]) == "yes")
                try_use_gpu = true;
            else
            {
                cout << "Bad --try_use_gpu flag value\n";
                return -1;
            }
            i++;
        }
        else if (string(argv[i]) == "--output")
        {
            result_name = argv[i + 1];
            i++;
        }
        else
        {
            Mat img = imread(argv[i]);
            if (img.empty())
            {
                cout << "Can ...
(more)
edit retag flag offensive close merge delete

Comments

there's nothing wrong with your code,

Can't stitch images, error code = 1

if you had gone and looked up the statuscode you'd found:

 ERR_NEED_MORE_IMGS

so, it did not like your images, try with different (and more) ones.

berak gravatar imageberak ( 2016-06-12 00:11:55 -0500 )edit

I add the images I tested to the problem. Could u check it again? And give some advice. Thx.

Downwing gravatar imageDownwing ( 2016-06-12 00:51:10 -0500 )edit

Before line Stitcher::Status status = stitcher.stitch(imgs, pano); insert line stitcher.setPanoConfidenceThresh(0.6);

Results for set1set2set3 using stitchind_detailed.cpp

LBerger gravatar imageLBerger ( 2016-06-12 14:56:05 -0500 )edit