I am trying to recreate the view of a camera from a spherical projection, so that the resulting image is orthographic (straight lines in reality equate to straight lines in the image space).
I have used the sphericalWarper warp function before with success:
detail::SphericalWarper Projection = detail::SphericalWarper(((360.0/PX2DEG)/PI)/2.0);
Mat SrcProj;
Projection.warp(Src, CameraIntrinsics, Rotation, INTER_LINEAR, 0,SrcProj);
But when I use the function warpBackward
, it requires me to specify the destination Mat size. It seems like if its not a very specific size, it causes an error. I dug into the library files and found the assert which sends the error, and found this (snippet from warpers_inl.hpp):
void RotationWarperBase<P>::warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, Size dst_size, OutputArray dst)
{
projector_.setCameraParams(K, R);
Point src_tl, src_br;
detectResultRoi(dst_size, src_tl, src_br);
Size size = src.size();
CV_Assert(src_br.x - src_tl.x + 1 == size.width && src_br.y - src_tl.y + 1 == size.height);
unfortunately detectResultRoi
is a protected function so im a little stuck on how to find the correct size of the destination image.
Any help will be much appreciated, thanks!
====================================Edit==================================== The Src size can be calculated using the warpRoi function, which is public.
Mat SrcProj=Mat(480,640,CV_8UC3,Scalar(0,0,0));
Rect WindowSize=Projection.warpRoi(SrcProj.size(),CameraIntrinsics,Rotation);
Above I defined my output size, then used warpRoi to find the Src size (or window size). Now you have the size you can cut a Mat of this size from the Src image (or resize it) and then use the warpBackward function without issue.