I have a use case where I need to periodically change the warp maps for a camera (the extrinsics change). The operation is too expensive for me to update the full map all at one time - I need to be able to continue processing images as they arrive. I have attempted to update the map by by acting on an ROI of the map, but this appears to re-allocate / re-initialize the map (or otherwise do something that makes the original map change).
I looked over the code for initUndistortRectifyMap and Mat::create, and it appeared that it would not re-allocate the Mat if the type and dims were the same, but so far (using an ROI to index into the warp map, and by creating a warp map that uses the memory from the original (full size) warp map) and so far I haven’t been able to get it to work.
Here is a recent assertion failure (when calling initUndistortRectifyMap on a cv::Mat that uses the original map memory):
OpenCV Error: Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in create, file /home/steve/embedded-repo/opencv/modules/core/src/matrix.cpp, line 2386
terminate called after throwing an instance of 'cv::Exception'
what(): /home/steve/embedded-repo/opencv/modules/core/src/matrix.cpp:2386: error: (-215) !fixedType() || ((Mat*)obj)->type() == mtype in function create
At this point my question is “should I be able to call initUndistortRectifyMap() on an ROI and update the original map without disrupting the rest of the map?”
For example:
Create the map like this:
cv::initUndistortRectifyMap(m_camMat, m_distCoeffs, cv::Mat(),
perspective*m_camMat, cv::Size(outputWidth, outputHeight), CV_16SC2,
ar_warpMap1, ar_warpMap2);
and then later update it something like:
cv::initUndistortRectifyMap(m_camMat, m_distCoeffs, cv::Mat(),
perspective*m_camMat, cv::Size(roiWidth, roiHeight), CV_16SC2,
ar_warpMap1(roi), ar_warpMap2(roi));
Alternatives I’m considering if this doesn’t work:
- Create a warp map for the ROI in a separate map, and then copy the resulting data to the correct location in the original map.
- Creating an array of warp maps (rectangular tiles) and update them (and apply them) individually.
Any guidance would be appreciated.
Thanks
-Steve