Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added mask for lens distortion in images #968

Merged
merged 11 commits into from
May 4, 2023
33 changes: 32 additions & 1 deletion libs/MVS/SceneTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ struct MeshTexture {
typedef TRasterMesh<RasterMesh> Base;
FaceMap& faceMap;
FIndex idxFace;
Image8U mask;
bool validFace;

RasterMesh(const Mesh::VertexArr& _vertices, const Camera& _camera, DepthMap& _depthMap, FaceMap& _faceMap)
: Base(_vertices, _camera, _depthMap), faceMap(_faceMap) {}
void Clear() {
Expand All @@ -164,11 +167,16 @@ struct MeshTexture {
Depth& depth = depthMap(pt);
if (depth == 0 || depth > z) {
depth = z;
faceMap(pt) = idxFace;
if (validFace && (validFace = mask(pt) != 0))
faceMap(pt) = idxFace;
else
faceMap(pt) = -1;
}
}
};



// used to represent a pixel color
typedef Point3f Color;
typedef CLISTDEF0(Color) Colors;
Expand Down Expand Up @@ -509,11 +517,34 @@ bool MeshTexture::ListCameraFaces(FaceDataViewArr& facesDatas, float fOutlierThr
faceMap.create(imageData.height, imageData.width);
depthMap.create(imageData.height, imageData.width);
RasterMesh rasterer(vertices, imageData.camera, depthMap, faceMap);
// creating mask for the image border
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
rasterer.mask = Image8U(imageData.height + 2, imageData.width + 2);
rasterer.mask = rasterer.mask != rasterer.mask;
Image8U imageCopy;
cv::cvtColor(imageData.image, imageCopy, cv::COLOR_BGR2GRAY);
imageCopy -= 1; // this line gets rid of white spots in the middle of the image
cv::floodFill(imageCopy, rasterer.mask, cv::Point(0, 0), 255);
cv::floodFill(imageCopy, rasterer.mask, cv::Point(0, imageCopy.rows / 2), 255);
cv::floodFill(imageCopy, rasterer.mask, cv::Point(0, imageCopy.rows - 1), 255);
cv::floodFill(imageCopy, rasterer.mask, cv::Point(imageCopy.cols / 2, imageCopy.rows - 1), 255);
cv::floodFill(imageCopy, rasterer.mask, cv::Point(imageCopy.cols - 1, imageCopy.rows - 1), 255);
cv::floodFill(imageCopy, rasterer.mask, cv::Point(imageCopy.cols - 1, imageCopy.rows / 2), 255);
cv::floodFill(imageCopy, rasterer.mask, cv::Point(imageCopy.cols - 1, 0), 255);
cv::floodFill(imageCopy, rasterer.mask, cv::Point(imageCopy.cols / 2, 0), 255);
cv::Mat kernel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3, 3));
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
cv::erode(rasterer.mask, rasterer.mask, kernel);
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
rasterer.mask = rasterer.mask == 0;
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
if (VERBOSITY_LEVEL > 2) {
cv::imwrite(String::FormatString("invalidMask%d.png", idx), rasterer.mask);
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
}
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
rasterer.Clear();
for (auto idxFace : cameraFaces) {
rasterer.validFace = true;
const Face& facet = faces[idxFace];
rasterer.idxFace = idxFace;
rasterer.Project(facet);
if(!rasterer.validFace)
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
PxGluz marked this conversation as resolved.
Show resolved Hide resolved
rasterer.Project(facet);
}
// compute the projection area of visible faces
#if TEXOPT_FACEOUTLIER != TEXOPT_FACEOUTLIER_NA
Expand Down