panJames
asked on
Passing argument to a function
Hello experts!
Have a look at my source code.
Two questions if I may:
1. How can I pass argument to this function when debugging using VC++
2. How can I pass argument to this function when running using console?
Thank you!
panJames
Have a look at my source code.
Two questions if I may:
1. How can I pass argument to this function when debugging using VC++
2. How can I pass argument to this function when running using console?
Thank you!
panJames
#include <cv.h>
#include <highgui.h>
#include <math.h>
using namespace cv;
int main(int argc, char** argv)
{
Mat src, dst, color_dst;
if( argc != 2 || !(src=imread(argv[1], 0)).data)
return -1;
Canny( src, dst, 50, 200, 3 );
cvtColor( dst, color_dst, CV_GRAY2BGR );
vector<Vec4i> lines;
HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
for( size_t i = 0; i < lines.size(); i++ )
{
line( color_dst, Point(lines[i][0], lines[i][1]),
Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
}
namedWindow( "Source", 1 );
imshow( "Source", src );
namedWindow( "Detected Lines", 1 );
imshow( "Detected Lines", color_dst );
waitKey(0);
return 0;
}
#include <cv.h>
#include <highgui.h>
#include <math.h>
using namespace cv;
int main(int argc, char** argv)
{
Mat src, dst, color_dst;
if( argc != 2 || !(src=imread(argv[1], 0)).data)
return -1;
Canny( src, dst, 50, 200, 3 );
cvtColor( dst, color_dst, CV_GRAY2BGR );
vector<Vec4i> lines;
HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
for( size_t i = 0; i < lines.size(); i++ )
{
line( color_dst, Point(lines[i][0], lines[i][1]),
Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
}
namedWindow( "Source", 1 );
imshow( "Source", src );
namedWindow( "Detected Lines", 1 );
imshow( "Detected Lines", color_dst );
waitKey(0);
return 0;
}
Well what kind of argument do you want to pass to which function in the above?
Both programs seem to accept an image filename is the one and only argument, so you could call it like this eg. :
my_application.exe my_image.ext
my_application.exe my_image.ext
ASKER
According to website I took example from:
http://opencv.willowgarage.com/documentation/cpp/feature_detection.html?highlight=hough#HoughLinesP
it should be file name.
/* This is a standalone program. Pass an image name as a first parameter
of the program. */
For me it looks like integer should be first...
panJames
http://opencv.willowgarage.com/documentation/cpp/feature_detection.html?highlight=hough#HoughLinesP
it should be file name.
/* This is a standalone program. Pass an image name as a first parameter
of the program. */
For me it looks like integer should be first...
panJames
>> For me it looks like integer should be first...
argv[0] is the executable name
argv[1] is the first parameter
argc contains the amount of items in the argv array (including the executable name)
So the (argc != 2) check makes sure that argc is equal to 2 (the executable name plus one parameter), and the one parameter is then passed to the imread function.
argv[0] is the executable name
argv[1] is the first parameter
argc contains the amount of items in the argv array (including the executable name)
So the (argc != 2) check makes sure that argc is equal to 2 (the executable name plus one parameter), and the one parameter is then passed to the imread function.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
To Infinity08
I typed in console as you said:
my_application.exe my_image.ext
And it works fine!
Two questions though:
1. In my main function
int main(int argc, char** argv)
first argument argc is integer, why don't I actually pass it?
2. How can I pass my arguments to main in VC++ for checking how it works during debuggin?
panJames
I typed in console as you said:
my_application.exe my_image.ext
And it works fine!
Two questions though:
1. In my main function
int main(int argc, char** argv)
first argument argc is integer, why don't I actually pass it?
2. How can I pass my arguments to main in VC++ for checking how it works during debuggin?
panJames
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can enter your arguments in the Project Settings, category 'Debug'.