Reputation: 65
I'm writing (learning) an OpenCV code which I want users are able to input a cv::String file name (.xml) and a double type argument
My main function is
int main(int argc, const** argv) {
...
In cmd.exe, I want the program to be called like
> App.exe cascadedClassifier.xml 0.5
Where cascadedClassifier.xml
is for user to select a classifier and 0.5
is a double type number for resizing image (frame)
One of my question is why the input argument is char type but the function to load classifier file require a cv::String type
but it still works in the cmd.exe even though they're two different types of arguments?
The other question is what should I do in main function's input argument that user can freely assign a double type input for the program in cmd.exe?
Thanks in advance.
Upvotes: 0
Views: 816
Reputation: 155085
The C++ language specification defines the int main(int argc, char* argv[])
entrypoint function - it has nothing to do with OpenCV at all - similarly OpenCV is not concerned with your program's entrypoint either: OpenCV is a library, not an application framework (like MFC or Qt).
OpenCV's cv::String
type defines a constructor from const char* s
which will be used to provide an implicit conversion to cv::String
.
All command-line arguments are passed-in through argv
, you cannot pass in non-char
-type arguments with the standard C/C++ main
entrypoint (this is because C and C++ do not define a convention for passing non-string arguments unlike, for example, PowerShell where Cmdlet arguments are defined in terms of .NET types). You will need to use atof
or sscanf
to convert arguments back into typed data.
Upvotes: 5
Reputation: 2295
const char*
can be implicitly converted to cv::String
according to the official cv::String Class Reference.
A double type input is technically impossible in command line. You can use atof(const char*)
function to convert char*
type to float
/double
type in your function.
Upvotes: 1