Hello OpenCV community,
I am working on understanding and potentially modifying the pyrDown function in OpenCV to ensure consistent behaviour when processing different regions of interest (ROIs). In particular, I’ve observed issues when pyrDown is applied to an ROI compared to when it’s applied to a full image and then cropped to the same ROI. This discrepancy appears when using certain border types and might relate to how the CALL_HAL macro is utilised.
Here’s the snippet of the code: (Line 1348 to 1378 of pyramid.cpp)
void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borderType )
{
CV_INSTRUMENT_REGION();
CV_Assert(borderType != BORDER_CONSTANT);
CV_OCL_RUN(_src.dims() <= 2 && _dst.isUMat(),
ocl_pyrDown(_src, _dst, _dsz, borderType))
CV_OVX_RUN(_src.dims() <= 2,
openvx_pyrDown(_src, _dst, _dsz, borderType))
Mat src = _src.getMat();
Size dsz = _dsz.empty() ? Size((src.cols + 1)/2, (src.rows + 1)/2) : _dsz;
_dst.create( dsz, src.type() );
Mat dst = _dst.getMat();
int depth = src.depth();
if(src.isSubmatrix() && !(borderType & BORDER_ISOLATED))
{
Point ofs;
Size wsz(src.cols, src.rows);
src.locateROI( wsz, ofs );
CALL_HAL(pyrDown, cv_hal_pyrdown_offset, src.data, src.step, src.cols, src.rows,
dst.data, dst.step, dst.cols, dst.rows, depth, src.channels(),
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, borderType & (~BORDER_ISOLATED));
}
else
{
CALL_HAL(pyrDown, cv_hal_pyrdown, src.data, src.step, src.cols, src.rows, dst.data, dst.step, dst.cols, dst.rows, depth, src.channels(), borderType);
}
My questions are :
- What role does CALL_HAL play in pyrDown, and how does it impact border handling and ROI consistency?
- Are there specific considerations when passing ROI offsets and image sizes to CALL_HAL that might affect the outcome?
- How do cv_hal_pyrdown and cv_hal_pyrdown_offset differ in their handling of ROIs and borders, and what precautions should be taken to ensure consistent results between full-image and ROI-based processing?
- Are there best practices or examples for modifying pyrDown or similar functions to ensure uniform results across various border types and ROIs?
Any guidance on this or related experiences would be greatly appreciated.