Within an OpenCV project normally cv::String
is used in functions, e.g. a simple putText
. However, when using functions of std
std::string
is in charge. E.g. in the case
ifstream stream(filepath);
string line;
getline(stream, line, '\n');
it is necessary to have a std::string
as cv::String
throws an error. In the vice versa case using an OpenCV function std::string
is properly converted to cv::String
and following code does work:
string Str = "Test";
putText(img, Str, Point(10, 10), FONT_HERSHEY_PLAIN, 1, Scalar::all(255), 1);
Questions
Why does OpenCV has an own String-Class? I think there may be some differences useful for OpenCV, while all (or most?) functionality of std::string
is still possible for cv::String
. But it seems that std::string
can be converted to cv::String
(which I have tested at least for putText
.
The documentations show similar functions but also some differences like the related functions static bool operator> (const String &lhs, const String &rhs)
and similar:
http://docs.opencv.org/3.1.0/d1/d8f/classcv_1_1String.html for cv::String
http://www.cplusplus.com/reference/string/string/ for std::string
Am I missing something?
Is there a reason why I should use both versions of Strings in one project or would it be acceptable to only use std::string
in terms of better readability? (As long as not using e.g. the related functions mentioned earlier)
Edit:
This question here addresses a similar problem with QString and string and the recommendation is to use std::string
where possible. I wonder if this is also valid for OpenCV.