Skip to content

Commit

Permalink
Merge pull request #140 from DEAR18/main
Browse files Browse the repository at this point in the history
Ensure downscaleFactor has a consistent impact on data
  • Loading branch information
pierotofy authored Dec 3, 2024
2 parents 57201dc + 07f598d commit 0129130
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions input_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,25 @@ void Camera::loadImage(float downscaleFactor){
if (image.numel()) std::runtime_error("loadImage already called");
std::cout << "Loading " << filePath << std::endl;

float scaleFactor = 1.0f / downscaleFactor;
cv::Mat cImg = imreadRGB(filePath);

float rescaleF = 1.0f;
// If camera intrinsics don't match the image dimensions
if (cImg.rows != height || cImg.cols != width){
rescaleF = static_cast<float>(cImg.rows) / static_cast<float>(height);
}
fx *= scaleFactor * rescaleF;
fy *= scaleFactor * rescaleF;
cx *= scaleFactor * rescaleF;
cy *= scaleFactor * rescaleF;
fx *= rescaleF;
fy *= rescaleF;
cx *= rescaleF;
cy *= rescaleF;

if (downscaleFactor > 1.0f){
float f = 1.0f / downscaleFactor;
cv::resize(cImg, cImg, cv::Size(), f, f, cv::INTER_AREA);
float scaleFactor = 1.0f / downscaleFactor;
cv::resize(cImg, cImg, cv::Size(), scaleFactor, scaleFactor, cv::INTER_AREA);
fx *= scaleFactor;
fy *= scaleFactor;
cx *= scaleFactor;
cy *= scaleFactor;
}

K = getIntrinsicsMatrix();
Expand Down

0 comments on commit 0129130

Please sign in to comment.