diff --git a/inc/projection.h b/inc/projection.h index 2cb0589818c136f803f0f6c040395aa0a7d4e013..08dec60af6c7c78bd9a7557ad54f439dee8cb002 100644 --- a/inc/projection.h +++ b/inc/projection.h @@ -15,7 +15,7 @@ class Projection{ void buildFrame(cv::Mat_<float> &depth, cv::Mat_<cv::Point2i> &frameMapMask, cv::Mat_<cv::Vec3b> &src, cv::Mat_<cv::Vec3b> &dst); cv::Point2i findMatchingPixel(int i, int j, float z, Camera *camera, cv::Point3f beamer_pos); void copyPixelsInto(cv::Point2i pixel_dst, cv::Mat_<cv::Vec3b> &dst, cv::Point2i pixel_src, cv::Mat_<cv::Vec3b> &src, cv::Mat_<float> &depth); - cv::Size getMatchingSize(cv::Mat_<cv::Vec3b> &src, cv::Rect base); + cv::Size getMatchingSize(cv::Mat &src, cv::Mat &base); public: Projection(); diff --git a/src/components/projection.cpp b/src/components/projection.cpp index ed61e759dd5c97a82183cdda11bde67d6312669d..0b2aa97a2647bc6260ffd841a0a7c25f3ed34fd9 100644 --- a/src/components/projection.cpp +++ b/src/components/projection.cpp @@ -31,28 +31,24 @@ cv::Point2i Projection::revertRotatePixel(cv::Point2i pixel){ // Adjust the projected frame with the topology from the camera to the beamer POV void Projection::adjustFrame(cv::Mat_<float> depth, cv::Mat_<cv::Vec3b> src, cv::Mat_<cv::Vec3b> &dst, Camera *camera, cv::Point3f beamer_pos){ - cv::Rect mask = camera->getCroppingMask(); - // resize the frames to be a multiple of the camera size : // src.size = n * camera.depth.size , where n is uint > 0 - static cv::Mat_<cv::Vec3b> resized_dst = cv::Mat_<cv::Vec3b>(getMatchingSize(dst, mask)); + static cv::Mat_<cv::Vec3b> resized_dst = cv::Mat_<cv::Vec3b>(getMatchingSize(dst, depth)); cv::resize(dst, resized_dst, resized_dst.size()); cv::resize(src, src, resized_dst.size()); - static cv::Mat_<cv::Point2i> deprojectMap = cv::Mat_<cv::Point2i>(mask.height, mask.width); + static cv::Mat_<cv::Point2i> deprojectMap = cv::Mat_<cv::Point2i>(depth.size()); deprojectMap = cv::Point2i(-1,-1); - static cv::Mat_<cv::Point2i> frameMapMask = cv::Mat_<cv::Point2i>(mask.height, mask.width, cv::Point2i(-1,-1)); + static cv::Mat_<cv::Point2i> frameMapMask = cv::Mat_<cv::Point2i>(depth.size(), cv::Point2i(-1,-1)); frameMapMask = cv::Point2i(-1,-1); - deprojectPixelsFromDepth(depth, mask, camera, beamer_pos, deprojectMap); + deprojectPixelsFromDepth(depth, camera->getCroppingMask(), camera, beamer_pos, deprojectMap); filterLowestDeprojectedPoints(depth, deprojectMap, frameMapMask); buildFrame(depth, frameMapMask, src, resized_dst); - // TODO : Holefilling method - cv::resize(resized_dst, dst, dst.size()); cv::warpAffine(dst, dst, adjustingMatrix, dst.size()); } @@ -132,10 +128,10 @@ void Projection::buildFrame(cv::Mat_<float> &depth, cv::Mat_<cv::Point2i> &frame } -cv::Size Projection::getMatchingSize(cv::Mat_<cv::Vec3b> &src, cv::Rect base){ +cv::Size Projection::getMatchingSize(cv::Mat &src, cv::Mat &base){ cv::Size bigSize; - bigSize.width = (src.size().width % base.width == 0) ? src.size().width : src.size().width - (src.size().width % base.width) + base.width; - bigSize.height = (src.size().height % base.height == 0) ? src.size().height : src.size().height - (src.size().height % base.height) + base.height; + bigSize.width = (src.size().width % base.size().width == 0) ? src.size().width : src.size().width - (src.size().width % base.size().width) + base.size().width; + bigSize.height = (src.size().height % base.size().height == 0) ? src.size().height : src.size().height - (src.size().height % base.size().height) + base.size().height; return bigSize; } @@ -177,13 +173,14 @@ void Projection::copyPixelsInto(cv::Point2i pixel_dst, cv::Mat_<cv::Vec3b> &dst, cv::Point2i Projection::findMatchingPixel(int i, int j, float z, Camera *camera, cv::Point3f CB){ float pixel[2] = {static_cast<float>(i), static_cast<float>(j)}; + const float BEz = distanceTopSandbox - CB.z; + cv::Point3f CP = camera->deprojectPixelToPoint(pixel, z); - cv::Point3f BP = CB - CP; - float BAz = CB.z + BP.z; - float BEz = distanceTopSandbox - CB.z; + cv::Point3f BP = CP - CB; + float BAz = BP.z; float alpha = BEz / BAz; - cv::Point3f V = (alpha * BP); - cv::Point3f CV = V + CB; + cv::Point3f BV = (alpha * BP); + cv::Point3f CV = CB + BV; return camera->projectPointToPixel(CV); }