diff --git a/Makefile b/Makefile index 4081b6b03d907f1a544a5c7704e4f1394d5d0958..fe6a37945590a97edae19fe8e62a8b5d93a7a6c6 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ all: $(MAKE) -C src $(MAKE) -C build + +app: $(MAKE) -C app clean: diff --git a/inc/projection.h b/inc/projection.h index 6d906b5a26c7d585ae7c585f2e77b3d340b5524a..7fb3d02bd2e6e7bc1f7e685d80a2ef40b15da811 100644 --- a/inc/projection.h +++ b/inc/projection.h @@ -11,7 +11,7 @@ class Projection{ float distanceTopSandbox; void deprojectPixelsFromDepth(cv::Mat &depth, cv::Rect mask, Camera *camera, cv::Point3f beamer_pos, cv::Mat &pixelsDeprojectMap); - void filterHighestDeprojectedPoints(cv::Mat &depth, cv::Mat &pixelsDeprojectMap, cv::Mat &pixelsDeprojectHighestMap); + void filterLowestDeprojectedPoints(cv::Mat &depth, cv::Mat &deprojectMap, cv::Mat &frameMapMask); void buildFrame(cv::Mat &depth, cv::Mat &pixelsDeprojectHighestMap, cv::Mat &src, cv::Mat &dst); cv::Point2i findMatchingPixel(int i, int j, float z, Camera *camera, cv::Point3f beamer_pos); void copyPixelsInto(cv::Point2i pixel_dst, cv::Mat &dst, cv::Point2i pixel_src, cv::Mat &src, cv::Mat &depth); diff --git a/src/components/projection.cpp b/src/components/projection.cpp index 77b8a5112bde020a7b86e366b940c191898f65a7..0d9a294e6f3c4cf9318928050cf9765079cdf4fd 100644 --- a/src/components/projection.cpp +++ b/src/components/projection.cpp @@ -39,16 +39,16 @@ void Projection::adjustFrame(cv::Mat depth, cv::Mat src, cv::Mat &dst, Camera *c cv::resize(dst, dst, getMatchingSize(dst, mask)); cv::resize(src, src, dst.size()); - cv::Mat pixelsDeprojectMap = cv::Mat_<cv::Point2i>(mask.height, mask.width, cv::Point2i(-1,-1)); - cv::Mat pixelsDeprojectHighestMap = cv::Mat_<cv::Point2i>(mask.height, mask.width, cv::Point2i(-1,-1)); + cv::Mat deprojectMap = cv::Mat_<cv::Point2i>(mask.height, mask.width, cv::Point2i(-1,-1)); + cv::Mat frameMapMask = cv::Mat_<cv::Point2i>(mask.height, mask.width, cv::Point2i(-1,-1)); - deprojectPixelsFromDepth(depth, mask, camera, beamer_pos, pixelsDeprojectMap); + deprojectPixelsFromDepth(depth, mask, camera, beamer_pos, deprojectMap); - filterHighestDeprojectedPoints(depth, pixelsDeprojectMap, pixelsDeprojectHighestMap); + filterLowestDeprojectedPoints(depth, deprojectMap, frameMapMask); - // TODO : Holefilling method + buildFrame(depth, frameMapMask, src, dst); - buildFrame(depth, pixelsDeprojectHighestMap, src, dst); + // TODO : Holefilling method cv::resize(dst, dst, dst_size); cv::warpAffine(dst, dst, adjustingMatrix, dst.size()); @@ -60,7 +60,7 @@ void Projection::adjustFrame(cv::Mat depth, cv::Mat src, cv::Mat &dst, Camera *c * PRIVATE */ -void Projection::deprojectPixelsFromDepth(cv::Mat &depth, cv::Rect mask, Camera *camera, cv::Point3f beamer_pos, cv::Mat &pixelsDeprojectMap){ +void Projection::deprojectPixelsFromDepth(cv::Mat &depth, cv::Rect mask, Camera *camera, cv::Point3f beamer_pos, cv::Mat &deprojectMap){ // Browse the depth frame matching the cropping mask // while adapting pixels's position to the beamer's position @@ -79,43 +79,50 @@ void Projection::deprojectPixelsFromDepth(cv::Mat &depth, cv::Rect mask, Camera pixel.x -= mask.x; pixel.y -= mask.y; - pixelsDeprojectMap.at<cv::Point2i>(j,i) = pixel; + deprojectMap.at<cv::Point2i>(j,i) = pixel; } } } -void Projection::filterHighestDeprojectedPoints(cv::Mat &depth, cv::Mat &pixelsDeprojectMap, cv::Mat &pixelsDeprojectHighestMap){ +void Projection::filterLowestDeprojectedPoints(cv::Mat &depth, cv::Mat &deprojectMap, cv::Mat &frameMapMask){ - for (int j = 0; j < pixelsDeprojectMap.rows; j++){ - for (int i = 0; i < pixelsDeprojectMap.cols; i++){ + for (int j = 0; j < deprojectMap.rows; j++){ + for (int i = 0; i < deprojectMap.cols; i++){ - cv::Point2i pixel = pixelsDeprojectMap.at<cv::Point2i>(j,i); + // coords of the new pixel + cv::Point2i deprojectedPixel = deprojectMap.at<cv::Point2i>(j,i); + cv::Point2i highestDepthPixel = cv::Point2i(i,j); - if(pixel.x != -1 && pixel.y != -1){ + if( (0 <= deprojectedPixel.x && deprojectedPixel.x < depth.cols) && + (0 <= deprojectedPixel.y && deprojectedPixel.y < depth.rows) ){ + // check and keep the highest point at the location pointed by pixel - cv::Point2i defaultPoint = pixelsDeprojectHighestMap.at<cv::Point2i>(j,i); - if(defaultPoint.x != -1 && defaultPoint.y != -1){ - if(depth.at<float>(defaultPoint) <= depth.at<float>(pixel)) - pixel = defaultPoint; + cv::Point2i currentDepthPixel = frameMapMask.at<cv::Point2i>(deprojectedPixel); + if( (0 <= currentDepthPixel.x && currentDepthPixel.x < depth.cols) && + (0 <= currentDepthPixel.y && currentDepthPixel.y < depth.rows) ){ + if(depth.at<float>(currentDepthPixel) <= depth.at<float>(j,i)){ + highestDepthPixel = currentDepthPixel; + } } - pixelsDeprojectHighestMap.at<cv::Point2i>(j,i) = pixel; + frameMapMask.at<cv::Point2i>(deprojectedPixel) = highestDepthPixel; } } } } -void Projection::buildFrame(cv::Mat &depth, cv::Mat &pixelsDeprojectHighestMap, cv::Mat &src, cv::Mat &dst){ +void Projection::buildFrame(cv::Mat &depth, cv::Mat &frameMapMask, cv::Mat &src, cv::Mat &dst){ - for (int j = 0; j < pixelsDeprojectHighestMap.rows; j++){ - for (int i = 0; i < pixelsDeprojectHighestMap.cols; i++){ + for (int j = 0; j < frameMapMask.rows; j++){ + for (int i = 0; i < frameMapMask.cols; i++){ - cv::Point2i pixel = pixelsDeprojectHighestMap.at<cv::Point2i>(j,i); + cv::Point2i pixel_src = frameMapMask.at<cv::Point2i>(j,i); + cv::Point2i pixel_dst = cv::Point2i(i,j); - if( (0<=pixel.x && pixel.x<depth.cols) && (0<=pixel.y && pixel.y<depth.rows) ){ + if( (0<=pixel_src.x && pixel_src.x<depth.cols) && (0<=pixel_src.y && pixel_src.y<depth.rows) ){ // src and dst must be of same size - copyPixelsInto(pixel, dst, cv::Point2i(i,j), src, depth); + copyPixelsInto(pixel_dst, dst, pixel_src, src, depth); } } }