Skip to content
Snippets Groups Projects
Commit b40b1836 authored by simon.fanetti's avatar simon.fanetti
Browse files

fixe projection + code clarity

parent f2124872
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ class Projection{ ...@@ -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); 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); 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); 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: public:
Projection(); Projection();
......
...@@ -31,28 +31,24 @@ cv::Point2i Projection::revertRotatePixel(cv::Point2i pixel){ ...@@ -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 // 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){ 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 : // resize the frames to be a multiple of the camera size :
// src.size = n * camera.depth.size , where n is uint > 0 // 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(dst, resized_dst, resized_dst.size());
cv::resize(src, src, 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); 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); frameMapMask = cv::Point2i(-1,-1);
deprojectPixelsFromDepth(depth, mask, camera, beamer_pos, deprojectMap); deprojectPixelsFromDepth(depth, camera->getCroppingMask(), camera, beamer_pos, deprojectMap);
filterLowestDeprojectedPoints(depth, deprojectMap, frameMapMask); filterLowestDeprojectedPoints(depth, deprojectMap, frameMapMask);
buildFrame(depth, frameMapMask, src, resized_dst); buildFrame(depth, frameMapMask, src, resized_dst);
// TODO : Holefilling method
cv::resize(resized_dst, dst, dst.size()); cv::resize(resized_dst, dst, dst.size());
cv::warpAffine(dst, dst, adjustingMatrix, 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 ...@@ -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; 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.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.height == 0) ? src.size().height : src.size().height - (src.size().height % base.height) + base.height; 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; return bigSize;
} }
...@@ -177,13 +173,14 @@ void Projection::copyPixelsInto(cv::Point2i pixel_dst, cv::Mat_<cv::Vec3b> &dst, ...@@ -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){ 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)}; 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 CP = camera->deprojectPixelToPoint(pixel, z);
cv::Point3f BP = CB - CP; cv::Point3f BP = CP - CB;
float BAz = CB.z + BP.z; float BAz = BP.z;
float BEz = distanceTopSandbox - CB.z;
float alpha = BEz / BAz; float alpha = BEz / BAz;
cv::Point3f V = (alpha * BP); cv::Point3f BV = (alpha * BP);
cv::Point3f CV = V + CB; cv::Point3f CV = CB + BV;
return camera->projectPointToPixel(CV); return camera->projectPointToPixel(CV);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment