How to replace argc and argv to execute in visual studio 2015??

asked 2017-01-24 11:31:14 -0600

Sherlock gravatar image

updated 2017-01-24 11:32:55 -0600

I am using opencv 3.1 under windows 10 OS 64 bit, Visual studios 2015 in the debug mode 64 i am getting an error "The program '[20572] learning.exe' has exited with code -1073741510 (0xc000013a)." where here learning.exe is the name of my project. I understnad that i m getting this error due to return of -1 from the function parseCmdArgs(int argc, char** argv). I also understand that argc takes argument or the file name say "stitching.cpp" and "argv" takes in the img in linux compiler when executing the command but my question is how to i alter it so that i can get the result of stitched image. Here is my code which is given in OPENCV samples section

#include <iostream>
#include <fstream>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/stitching.hpp"

using namespace std;
using namespace cv;

bool try_use_gpu = false; //bool type variable
vector<Mat> imgs;        //image data type
string result_name = "result.jpg"; //string datatype

void printUsage();                       // list of instructions
int parseCmdArgs(int argc, char** argv);    

int main(int argc, char* argv[])
{
    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);
    cout<<"hello";
    if (status != Stitcher::OK)
    {
        cout << "Can't stitch images, error code = " << int(status) << endl;
        return -1;
    }

    imwrite(result_name, pano);
    getchar(); getchar();
    return 0;
}


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't read image '" << argv[i] << "'\n";
                return -1;
            }
            imgs.push_back(img);
        }
    }
    return 0;
}

Here is the debug list

VIDEOINPUT LIBRARY - 0.1995 - TFW07

The thread 0x2af4 has exited with code -1 (0xffffffff). The thread 0x5138 has exited with code -1 (0xffffffff). The thread 0xd8 has exited with code -1 (0xffffffff). The program '[23492] learning.exe' has exited with code -1 (0xffffffff).

Build was succeded

edit retag flag offensive close merge delete

Comments

try to run that program from a cmdline, not from your ide.

there are explanatory cout statements, that get lost, when your program finishes, otherwise.

most likely problem is: your image was not loaded (wrong path tho that)

berak gravatar imageberak ( 2017-01-24 11:42:07 -0600 )edit
1

In visual studio in project properties you can set arg in in debug (command argument).

If you don't like this. I think you can write something like this (not tested):

argc=3;
char *myArg[]={"stitching.exe"," pano1.jpg","pano2.jpg"};
CommandLineParser parser(argc, myArgv);
LBerger gravatar imageLBerger ( 2017-01-24 11:47:33 -0600 )edit

In my opinion, this has nothing to do with OpenCV, rather with you not being able to correctly configure your IDE ...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-01-25 03:50:40 -0600 )edit