diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmask.cpp index 8661153ce877e853b8dfdfab2e334f9406bec98a..21fcbba34a54901c02a67844e0d7af539e7c07a3 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmask.cpp @@ -31,12 +31,12 @@ void CroppingMask::valideRoutine(){ timer->stop(); setup->getCamera()->capture(); std::vector<cv::Point> rectPoints = getRectPoints(); - cv::Point2i center = setup->getCenterOfQuadrilateral(rectPoints); + cv::Point2i centerProjection = setup->getCenterOfQuadrilateral(rectPoints); cv::Mat depthFrame = setup->getCamera()->getDepthFrame(); - setup->setupAdjustMatrix(rectPoints, center); + setup->setupAdjustMatrix(rectPoints, centerProjection); setup->setupCroppingMask(rectPoints); - setup->getProjection()->setDistanceTopSandbox(depthFrame.at<float>(center)); + setup->getProjection()->setDistanceTopSandbox(depthFrame.at<float>(centerProjection)); endSuccess = true; } diff --git a/src/components/projection.cpp b/src/components/projection.cpp index 412dc9048095ccc96cb2cfe1c9fafe26443eb9cb..f445ee6b06395ce17c50d1d3329d0dc5e98cac01 100644 --- a/src/components/projection.cpp +++ b/src/components/projection.cpp @@ -27,7 +27,9 @@ cv::Point2i Projection::revertRotatePixel(cv::Point2i pixel){ } -// Adjust the projected frame with the topology from the camera to the beamer POV +/* + 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){ if(deprojectMap.empty() || deprojectMap.size() != depth.size()){ @@ -43,10 +45,10 @@ void Projection::adjustFrame(cv::Mat_<float> depth, cv::Mat_<cv::Vec3b> src, cv: deprojectMap = cv::Point2i(-1,-1); frameMap = cv::Point2i(-1,-1); + resized_dst = cv::Vec3b(0,0,0); - // resize the frames to be a multiple of the camera size : - // src.size = n * camera.depth.size , where n is uint > 0 - cv::resize(dst, resized_dst, resized_dst.size()); + // resize to match 1:1 ratio with resized_dst, since we'll do later: + // resized_dst[i] = src[i] cv::resize(src, src, resized_dst.size()); deprojectPixelsFromDepth(depth, camera->getCroppingMask(), camera, beamer_pos, deprojectMap); @@ -63,6 +65,11 @@ void Projection::adjustFrame(cv::Mat_<float> depth, cv::Mat_<cv::Vec3b> src, cv: * PRIVATE */ + +/* + Deproject pixels in 3D, then adapt to Beamer's POV, and go back to 2D + This gives us the location od pixels adapted to the Beamer projection +*/ void Projection::deprojectPixelsFromDepth(cv::Mat_<float> &depth, cv::Rect mask, Camera *camera, cv::Point3f beamer_pos, cv::Mat_<cv::Point2i> &deprojectMap){ // Browse the depth frame matching the cropping mask @@ -87,7 +94,13 @@ void Projection::deprojectPixelsFromDepth(cv::Mat_<float> &depth, cv::Rect mask, } } +/* + Save the highest points in deprojectMap into frameMap, + because some points can be deprojected at the same location + frameMap indicates for each pixel of dst, where it should get the value from in src + deprojectMap indicates for each pixel, where it'll be displayed +*/ void Projection::filterLowestDeprojectedPoints(cv::Mat_<float> &depth, cv::Mat_<cv::Point2i> &deprojectMap, cv::Mat_<cv::Point2i> &frameMap){ for (int j = 0; j < deprojectMap.rows; j++){ @@ -115,6 +128,11 @@ void Projection::filterLowestDeprojectedPoints(cv::Mat_<float> &depth, cv::Mat_< } +/* + Build the frame using frameMap, + where each pixel describes in which pixel of the source it should take the value from + dst[i] = src[frameMap[i]] +*/ void Projection::buildFrame(cv::Mat_<float> &depth, cv::Mat_<cv::Point2i> &frameMap, cv::Mat_<cv::Vec3b> &src, cv::Mat_<cv::Vec3b> &dst){ for (int j = 0; j < frameMap.rows; j++){ @@ -132,6 +150,10 @@ void Projection::buildFrame(cv::Mat_<float> &depth, cv::Mat_<cv::Point2i> &frame } +/* + resize the frames to be a multiple of the base size: + src.size = n * base.size, where n is uint > 0 +*/ cv::Size Projection::getMatchingSize(cv::Mat &src, cv::Mat &base){ cv::Size bigSize; bigSize.width = (src.size().width % base.size().width == 0) ? src.size().width : src.size().width - (src.size().width % base.size().width) + base.size().width; @@ -140,7 +162,9 @@ cv::Size Projection::getMatchingSize(cv::Mat &src, cv::Mat &base){ } -// pixels coordinates are relative to the camera depth frame +/* + pixels coordinates are relative to the camera depth frame +*/ void Projection::copyPixelsInto(cv::Point2i pixel_dst, cv::Mat_<cv::Vec3b> &dst, cv::Point2i pixel_src, cv::Mat_<cv::Vec3b> &src, cv::Mat_<float> &depth){ if( src.size().width == dst.size().width && src.size().height == dst.size().height ){