Always use OpenCV's built-in error handling mechanisms instead of C++ exceptions or custom error handling. This ensures consistent error handling across the codebase and proper integration with OpenCV's error handling infrastructure.
Always use OpenCV’s built-in error handling mechanisms instead of C++ exceptions or custom error handling. This ensures consistent error handling across the codebase and proper integration with OpenCV’s error handling infrastructure.
Key guidelines:
Example:
void processImage(InputArray src, OutputArray dst, int param) {
// Input validation
CV_Assert(src.dims() <= 2 && src.channels() <= 4);
CV_Assert(param > 0 && param < 100);
// Runtime error handling
if (!src.isContinuous())
CV_Error(Error::StsBadArg, "Input array must be continuous");
// Warning for non-fatal issues
if (param < 10)
CV_LOG_WARNING(NULL, "Parameter value < 10 may reduce accuracy");
// Return false instead of throwing
if (!processData())
return false;
}
Enter the URL of a public GitHub repository