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

Adding re-texturing option: #462

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/InterfaceCOLMAP/InterfaceCOLMAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ bool ExportScene(const String& strFolder, const Interface& scene)
ProjectVertex_3x4_3_2(cameras[view.imageID].P.val, X.ptr(), proj.p.data());
img.projs.push_back(proj);
}
point.c = scene.verticesColor.empty() ? Interface::Col3(255,255,255) : scene.verticesColor[ID].c;
point.c = scene.verticesColor.empty() ? Interface::Col3(1.f,1.f,1.f) : scene.verticesColor[ID].c;
point.e = 0;
if (!point.Write(file))
return false;
Expand Down
4 changes: 2 additions & 2 deletions apps/InterfacePhotoScan/InterfacePhotoScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ bool UndistortBrown(MVS::Image& imageData, uint32_t ID, const DistCoeff& dc, con
#endif

// undistort image
Image8U3 imgUndist;
Image32F3 imgUndist;
cv::undistort(imageData.image, imgUndist, prevK, distCoeffs, K);
imageData.ReleaseImage();

Expand Down Expand Up @@ -475,7 +475,7 @@ void AssignPoints(const MVS::Image& imageData, uint32_t ID, MVS::PointCloud& poi
const int cw(ir.x+j);
if (!depthMap.isInside(ImageRef(cw,rw)))
continue;
if (depthMap(rw,cw) < Xc.z)
if (depthMap(rw,cw) < Xc.z)
goto NEXT_POINT;
}
}
Expand Down
8 changes: 4 additions & 4 deletions apps/InterfaceVisualSFM/InterfaceVisualSFM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ inline TPoint2<TYPE> DistortPointR1(const TPoint2<TYPE>& pt, const REAL& k1) {
#endif
}

void UndistortImage(const Camera& camera, const REAL& k1, const Image8U3 imgIn, Image8U3& imgOut)
void UndistortImage(const Camera& camera, const REAL& k1, const Image32F3 imgIn, Image32F3& imgOut)
{
// allocate the undistorted image
if (imgOut.data == imgIn.data ||
imgOut.cols != imgIn.cols ||
imgOut.rows != imgIn.rows ||
imgOut.type() != imgIn.type())
imgOut = Image8U3(imgIn.rows, imgIn.cols);
imgOut = Image32F3(imgIn.rows, imgIn.cols);

// compute each pixel
const int w = imgIn.cols;
Expand All @@ -260,13 +260,13 @@ void UndistortImage(const Camera& camera, const REAL& k1, const Image8U3 imgIn,
Camera::NormalizeProjection(K.val, pt.ptr(), pt.ptr());

// if coordinates in range
Pixel8U& col = imgOut(v,u);
Pixel32F& col = imgOut(v,u);
if (imgIn.isInside(pt)) {
// get pixel color
col = imgIn.sample<Sampler,Pixel32F>(sampler, pt).cast<uint8_t>();
} else {
// set to black
col = Pixel8U::BLACK;
col = Pixel32F::BLACK;
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions apps/TextureMesh/TextureMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ float fOutlierThreshold;
float fRatioDataSmoothness;
bool bGlobalSeamLeveling;
bool bLocalSeamLeveling;
bool reTexture;
unsigned nTextureSizeMultiple;
unsigned nRectPackingHeuristic;
uint32_t nColEmpty;
Expand Down Expand Up @@ -104,6 +105,7 @@ bool Initialize(size_t argc, LPCTSTR* argv)
("cost-smoothness-ratio", boost::program_options::value<float>(&OPT::fRatioDataSmoothness)->default_value(0.1f), "ratio used to adjust the preference for more compact patches (1 - best quality/worst compactness, ~0 - worst quality/best compactness)")
("global-seam-leveling", boost::program_options::value<bool>(&OPT::bGlobalSeamLeveling)->default_value(true), "generate uniform texture patches using global seam leveling")
("local-seam-leveling", boost::program_options::value<bool>(&OPT::bLocalSeamLeveling)->default_value(true), "generate uniform texture patch borders using local seam leveling")
("re-texture", boost::program_options::value<bool>(&OPT::reTexture)->default_value(false), "generate texture using previous atlas")
("texture-size-multiple", boost::program_options::value<unsigned>(&OPT::nTextureSizeMultiple)->default_value(0), "texture size should be a multiple of this value (0 - power of two)")
("patch-packing-heuristic", boost::program_options::value<unsigned>(&OPT::nRectPackingHeuristic)->default_value(3), "specify the heuristic used when deciding where to place a new patch (0 - best fit, 3 - good speed, 100 - best speed)")
("empty-color", boost::program_options::value<uint32_t>(&OPT::nColEmpty)->default_value(0x00FF7F27), "color used for faces not covered by any image")
Expand Down Expand Up @@ -228,7 +230,7 @@ int main(int argc, LPCTSTR* argv)
{
// compute mesh texture
TD_TIMER_START();
if (!scene.TextureMesh(OPT::nResolutionLevel, OPT::nMinResolution, OPT::fOutlierThreshold, OPT::fRatioDataSmoothness, OPT::bGlobalSeamLeveling, OPT::bLocalSeamLeveling, OPT::nTextureSizeMultiple, OPT::nRectPackingHeuristic, Pixel8U(OPT::nColEmpty)))
if (!scene.TextureMesh(OPT::nResolutionLevel, OPT::nMinResolution, OPT::fOutlierThreshold, OPT::fRatioDataSmoothness, OPT::bGlobalSeamLeveling, OPT::bLocalSeamLeveling, OPT::nTextureSizeMultiple, OPT::nRectPackingHeuristic, Pixel32F(OPT::nColEmpty), OPT::reTexture))
return EXIT_FAILURE;
VERBOSE("Mesh texturing completed: %u vertices, %u faces (%s)", scene.mesh.vertices.GetSize(), scene.mesh.faces.GetSize(), TD_TIMER_GET_FMT().c_str());

Expand All @@ -244,14 +246,14 @@ int main(int argc, LPCTSTR* argv)
if (OPT::nOrthoMapResolution) {
// project mesh as an orthographic image
ProjectOrtho:
Image8U3 imageRGB;
Image8U imageRGBA[4];
Image32F3 imageRGB;
Image32F imageRGBA[4];
Point3 center;
scene.mesh.ProjectOrthoTopDown(OPT::nOrthoMapResolution, imageRGB, imageRGBA[3], center);
Image8U4 image;
Image32F4 image;
cv::split(imageRGB, imageRGBA);
cv::merge(imageRGBA, 4, image);
image.Save(baseFileName+_T("_orthomap.png"));
image.Save(baseFileName+_T("_orthomap.exr"));
SML sml(_T("OrthoMap"));
sml[_T("Center")].val = String::FormatString(_T("%g %g %g"), center.x, center.y, center.z);
sml.Save(baseFileName+_T("_orthomap.txt"));
Expand Down
2 changes: 1 addition & 1 deletion apps/Viewer/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ bool Scene::Open(LPCTSTR fileName, LPCTSTR meshFileName)
image.SetImage(scene.mesh.textureDiffuse);
scene.mesh.textureDiffuse.release();
#else // preserve texture, used only to be able to export the mesh
Image8U3 textureDiffuse;
Image32F3 textureDiffuse;
cv::flip(scene.mesh.textureDiffuse, textureDiffuse, 0);
image.SetImage(textureDiffuse);
#endif
Expand Down
98 changes: 98 additions & 0 deletions build/Modules/FindOpenEXR.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#
# Copyright 2016 Pixar
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#

find_path(OPENEXR_INCLUDE_DIR
OpenEXR/half.h
HINTS
"${OPENEXR_LOCATION}"
"$ENV{OPENEXR_LOCATION}"
PATH_SUFFIXES
include/
DOC
"OpenEXR headers path"
)

if(OPENEXR_INCLUDE_DIR)
set(openexr_config_file "${OPENEXR_INCLUDE_DIR}/OpenEXR/OpenEXRConfig.h")
if(EXISTS ${openexr_config_file})
file(STRINGS
${openexr_config_file}
TMP
REGEX "#define OPENEXR_VERSION_STRING.*$")
string(REGEX MATCHALL "[0-9.]+" OPENEXR_VERSION ${TMP})

file(STRINGS
${openexr_config_file}
TMP
REGEX "#define OPENEXR_VERSION_MAJOR.*$")
string(REGEX MATCHALL "[0-9]" OPENEXR_MAJOR_VERSION ${TMP})

file(STRINGS
${openexr_config_file}
TMP
REGEX "#define OPENEXR_VERSION_MINOR.*$")
string(REGEX MATCHALL "[0-9]" OPENEXR_MINOR_VERSION ${TMP})
endif()
endif()

foreach(OPENEXR_LIB
Half
Iex
Imath
IlmImf
IlmThread
)

# OpenEXR libraries may be suffixed with the version number, so we search
# using both versioned and unversioned names.
find_library(OPENEXR_${OPENEXR_LIB}_LIBRARY
NAMES
${OPENEXR_LIB}-${OPENEXR_MAJOR_VERSION}_${OPENEXR_MINOR_VERSION}
${OPENEXR_LIB}
HINTS
"${OPENEXR_LOCATION}"
"$ENV{OPENEXR_LOCATION}"
PATH_SUFFIXES
lib/
DOC
"OPENEXR's ${OPENEXR_LIB} library path"
)

if(OPENEXR_${OPENEXR_LIB}_LIBRARY)
list(APPEND OPENEXR_LIBRARIES ${OPENEXR_${OPENEXR_LIB}_LIBRARY})
endif()
endforeach(OPENEXR_LIB)

# So #include <half.h> works
list(APPEND OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR})
list(APPEND OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR}/OpenEXR)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenEXR
REQUIRED_VARS
OPENEXR_INCLUDE_DIRS
OPENEXR_LIBRARIES
VERSION_VAR
OPENEXR_VERSION
)
3 changes: 3 additions & 0 deletions build/Templates/ConfigLocal.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
// TIFF codec
#cmakedefine _USE_TIFF

// EXR codec
#cmakedefine _USE_EXR

// OpenGL support
#cmakedefine _USE_OPENGL

Expand Down
6 changes: 3 additions & 3 deletions libs/Common/CUDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class EventRT
}
void Release();
CUresult Reset(unsigned flags = CU_EVENT_DEFAULT);

inline operator CUevent() const {
return hEvent;
}
Expand Down Expand Up @@ -458,7 +458,7 @@ class TArrayRT

public:
inline TArrayRT() : hArray(NULL) {}
inline TArrayRT(const Image8U::Size& size, unsigned flags=0) : hArray(NULL) { reportCudaError(Reset(size, flags)); }
inline TArrayRT(const Image32F::Size& size, unsigned flags=0) : hArray(NULL) { reportCudaError(Reset(size, flags)); }
inline TArrayRT(unsigned width, unsigned height, unsigned depth=0, unsigned flags=0) : hArray(NULL) { reportCudaError(Reset(width, height, depth, flags)); }
inline ~TArrayRT() { Release(); }

Expand All @@ -478,7 +478,7 @@ class TArrayRT
hArray = NULL;
}
}
inline CUresult Reset(const Image8U::Size& size, unsigned flags=0) {
inline CUresult Reset(const Image32F::Size& size, unsigned flags=0) {
return Reset((unsigned)size.width, (unsigned)size.height, 0, flags);
}
CUresult Reset(unsigned width, unsigned height, unsigned depth=0, unsigned flags=0) {
Expand Down
6 changes: 5 additions & 1 deletion libs/Common/Types.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ inline void _ProcessScanLine(int y, const TPoint3<T>& pa, const TPoint3<T>& pb,
}
}
// Raster the given triangle and output the position and depth of each pixel of the triangle;
// based on "Learning how to write a 3D software engine � Rasterization & Z-Buffering" by Nick (David Rousset)
// based on "Learning how to write a 3D software engine � Rasterization & Z-Buffering" by Nick (David Rousset)
// http://blogs.msdn.com/b/davrous/archive/2013/06/21/tutorial-part-4-learning-how-to-write-a-3d-software-engine-in-c-ts-or-js-rasterization-amp-z-buffering.aspx
template <typename TYPE>
template <typename T, typename PARSER>
Expand Down Expand Up @@ -2751,6 +2751,10 @@ bool TImage<TYPE>::Save(const String& fileName) const
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY);
compression_params.push_back(80);
} else
if (ext == ".exr") {
//compression_params.push_back(cv::IMWRITE_EXR_TYPE_FLOAT);
//compression_params.push_back(2);
} else
if (ext == ".pfm") {
if (Base::depth() != CV_32F)
return false;
Expand Down
10 changes: 9 additions & 1 deletion libs/IO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ if(TIFF_FOUND)
else()
SET(TIFF_LIBRARIES "")
endif()
FIND_PACKAGE(OpenEXR)
if(OPENEXR_FOUND)
INCLUDE_DIRECTORIES(${OPENEXR_INCLUDE_DIR})
ADD_DEFINITIONS(${OPENEXR_DEFINITIONS} -D_USE_EXR)
SET(_USE_EXR TRUE CACHE INTERNAL "")
else()
SET(OPENEXR_LIBRARIES "")
endif()

# List sources files
FILE(GLOB PCH_C "Common.cpp")
Expand All @@ -43,7 +51,7 @@ cxx_library_with_type_no_pch(IO "Libs" "STATIC" "${cxx_default}"
set_target_pch(IO Common.h)

# Link its dependencies
TARGET_LINK_LIBRARIES(IO Common ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${EXIV2_LIBS})
TARGET_LINK_LIBRARIES(IO Common ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${OPENEXR_LIBRARIES} ${EXIV2_LIBS})

# Install
SET_TARGET_PROPERTIES(IO PROPERTIES
Expand Down
6 changes: 6 additions & 0 deletions libs/IO/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#ifdef _USE_TIFF
#define _IMAGE_TIFF // add TIFF support
#endif
#ifdef _USE_EXR
#define _IMAGE_EXR // add EXR support
#endif

#include "ImageSCI.h"
#ifdef _IMAGE_BMP
Expand All @@ -47,6 +50,9 @@
#ifdef _IMAGE_DDS
#include "ImageDDS.h"
#endif
#ifdef _IMAGE_EXR
#include "ImageEXR.h"
#endif
#ifdef _IMAGE_PNG
#include "ImagePNG.h"
#endif
Expand Down
Loading