mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Merge pull request #26602 from shyama7004:minor-fix
Improved dumpVector, cv::Rect operator<< and exceptions #26602 - Applied format for vector element formatting to ensure consistent and clear output representation. - Moved `operator<<` to the `cv` namespace to align with OpenCV's coding standards and improve maintainability. - Enhanced error handling by including detailed exception messages using `e.what()` for better debugging. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
parent
85f9ac4e23
commit
f00814e38d
@ -9,7 +9,12 @@
|
||||
#include <opencv2/core/utils/filesystem.hpp>
|
||||
#include <opencv2/core/utils/filesystem.private.hpp>
|
||||
|
||||
namespace cv { namespace utils {
|
||||
namespace cv {
|
||||
static inline std::ostream& operator<<(std::ostream& os, const Rect& rect)
|
||||
{
|
||||
return os << "[x=" << rect.x << ", y=" << rect.y << ", w=" << rect.width << ", h=" << rect.height << ']';
|
||||
}
|
||||
namespace utils {
|
||||
|
||||
String dumpInputArray(InputArray argument)
|
||||
{
|
||||
@ -51,9 +56,13 @@ String dumpInputArray(InputArray argument)
|
||||
ss << " type(-1)=" << cv::typeToString(argument.type(-1));
|
||||
} while (0);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
ss << " ERROR: exception occurred: " << e.what();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ss << " ERROR: exception occurred, dump is non-complete"; // need to properly support different kinds
|
||||
ss << " ERROR: unknown exception occurred, dump is non-complete";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
@ -104,9 +113,13 @@ CV_EXPORTS_W String dumpInputArrayOfArrays(InputArrayOfArrays argument)
|
||||
}
|
||||
} while (0);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
ss << " ERROR: exception occurred: " << e.what();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ss << " ERROR: exception occurred, dump is non-complete"; // need to properly support different kinds
|
||||
ss << " ERROR: unknown exception occurred, dump is non-complete";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
@ -151,9 +164,13 @@ CV_EXPORTS_W String dumpInputOutputArray(InputOutputArray argument)
|
||||
ss << " type(-1)=" << cv::typeToString(argument.type(-1));
|
||||
} while (0);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
ss << " ERROR: exception occurred: " << e.what();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ss << " ERROR: exception occurred, dump is non-complete"; // need to properly support different kinds
|
||||
ss << " ERROR: unknown exception occurred, dump is non-complete";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
@ -204,28 +221,28 @@ CV_EXPORTS_W String dumpInputOutputArrayOfArrays(InputOutputArrayOfArrays argume
|
||||
}
|
||||
} while (0);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
ss << " ERROR: exception occurred: " << e.what();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ss << " ERROR: exception occurred, dump is non-complete"; // need to properly support different kinds
|
||||
ss << " ERROR: unknown exception occurred, dump is non-complete";
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static inline std::ostream& operator<<(std::ostream& os, const cv::Rect& rect)
|
||||
{
|
||||
return os << "[x=" << rect.x << ", y=" << rect.y << ", w=" << rect.width << ", h=" << rect.height << ']';
|
||||
}
|
||||
|
||||
template <class T, class Formatter>
|
||||
static inline String dumpVector(const std::vector<T>& vec, Formatter format)
|
||||
{
|
||||
std::ostringstream oss("[", std::ios::ate);
|
||||
if (!vec.empty())
|
||||
{
|
||||
oss << format << vec[0];
|
||||
format(oss) << vec[0];
|
||||
for (std::size_t i = 1; i < vec.size(); ++i)
|
||||
{
|
||||
oss << ", " << format << vec[i];
|
||||
oss << ", ";
|
||||
format(oss) << vec[i];
|
||||
}
|
||||
}
|
||||
oss << "]";
|
||||
|
Loading…
Reference in New Issue
Block a user