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

[software] New ColorChecker Detection and Correction #973

Merged
merged 35 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6091ac7
Add alicevision main color checker detection
ludchieng Dec 2, 2020
e0fe2e0
[software] colorCheckerDetection: update
ludchieng Jan 11, 2021
96fe9a6
[software] colorCheckerDetection update cmakelists and main
ludchieng Jan 12, 2021
dc0d3ba
[software] colorCheckerDetection: process images
vscav Jan 13, 2021
e8f9fe8
[software] colorCheckerDetection: svg debug
ludchieng Jan 13, 2021
e9a2857
[software] colorCheckerDetection: color calibration
fabiencastan Jan 20, 2021
dfe90ae
[software] colorCheckerDetection: update
ludchieng Jan 13, 2021
be38e46
[software] colorCheckerCorrection: create main file
vscav Jan 14, 2021
4950d63
[software] colorCheckerDetection: update
ludchieng Jan 15, 2021
d10a05f
[software] colorCheckerCorrection: processColorCorrection method
vscav Jan 18, 2021
970feee
[software] colorCheckerCorrection: deserialize matrix from text file
fabiencastan Jan 20, 2021
25e98d1
[software] colorCheckerDetection: fix svg and update image loading
fabiencastan Jan 20, 2021
386dc39
[software] colorCheckerDetection: add input as regex
ludchieng Jan 18, 2021
4d42666
[software] refactor AV image and opencv image conversions functions
ludchieng Jan 20, 2021
4b102ba
[software] colorCheckerDetection: multiple cchecker handling
ludchieng Jan 20, 2021
f894d78
[software] fix image convertionOpenCV
ludchieng Jan 20, 2021
bc694e6
[software] colorCheckerCorrection: use regex as input
vscav Jan 20, 2021
f72c698
[software] colorCheckerDetection: add position data output
ludchieng Jan 21, 2021
b7c43e6
[software] colorCheckerCorrection: BGR matrix to RGBA image
vscav Jan 21, 2021
c159ea9
[software] colorCheckerCorrection: save image function
vscav Jan 21, 2021
b522cd8
[software] colorCheckerCorrection: exr format support
vscav Jan 21, 2021
a5c52b2
[software] colorCheckerDetection: data output in json format
ludchieng Jan 21, 2021
f980c6b
[software] colorCheckerCorrection: fix bug when no input color data
vscav Jan 21, 2021
68037ef
[software] colorCheckerCorrection: data input in json format
vscav Jan 22, 2021
82cb14f
[software] colorCheckerCorrection: correction process in float precision
vscav Jan 25, 2021
90ee3d7
[software] colorCheckerDetection: change functions params and namespace
ludchieng Jan 25, 2021
4f75072
[software] colorCheckerDetection: fix color uint values exceeding 255
ludchieng Feb 20, 2021
4db7c78
[software] colorChecker: update color read as float
ludchieng Feb 27, 2021
0b37189
[software] colorCheckerDetection: update param as const &
ludchieng Mar 10, 2021
665e02f
[software] colorCheckerDetection: linux build fix
fabiencastan Apr 21, 2021
6194217
[ci] Update docker image for alicevision-deps
fabiencastan Apr 22, 2021
bad341b
[cmake] all-in-one build: update opencv and add mcc module
fabiencastan Apr 22, 2021
707d234
[docker] fetch.sh: minor fix
fabiencastan Apr 22, 2021
af7be7f
[software] colorCheckerDetection: add comment
fabiencastan Apr 22, 2021
fa9c24b
[software] colorchecker: fix codacy warnings
fabiencastan Apr 22, 2021
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 .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
build:
runs-on: ubuntu-latest
container:
image: alicevision/alicevision-deps:ci-2020.09.09-centos7-cuda10.2
image: alicevision/alicevision-deps:ci-2021-04-22-centos7-cuda10.2
env:
DEPS_INSTALL_DIR: /opt/AliceVision_install
BUILD_TYPE: Release
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ set(ALEMBIC_CMAKE_FLAGS -DAlembic_DIR:PATH=${CMAKE_INSTALL_PREFIX}/lib/cmake/Ale
if(AV_BUILD_OPENCV)
set(OPENCV_TARGET opencv)
ExternalProject_Add(opencv_contrib
URL https://github.com/opencv/opencv_contrib/archive/4.5.1.zip
URL_MD5 ddb4f64d6cf31d589a8104655d39c99b
URL https://github.com/opencv/opencv_contrib/archive/4.5.2.zip
URL_MD5 1f5218d9c47994cb38bc018596534e4d
DOWNLOAD_DIR ${BUILD_DIR}/download/opencv_contrib
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/opencv_contrib
BUILD_ALWAYS 0
Expand All @@ -639,8 +639,8 @@ ExternalProject_Add(opencv_contrib
)
ExternalProject_Add(${OPENCV_TARGET}
DEPENDS opencv_contrib ${TBB_TARGET} ${ZLIB_TARGET} ${OPENEXR_TARGET} ${TIFF_TARGET} ${PNG_TARGET} ${JPEG_TARGET} ${LIBRAW_TARGET} ${FFMPEG_TARGET}
URL https://github.com/opencv/opencv/archive/4.5.1.zip
URL_MD5 cc13d83c3bf989b0487bb3798375ee08
URL https://github.com/opencv/opencv/archive/4.5.2.zip
URL_MD5 f100177ab3e7b884f490cba4cff8e074
DOWNLOAD_DIR ${BUILD_DIR}/download/opencv
UPDATE_COMMAND ""
BUILD_IN_SOURCE 0
Expand Down Expand Up @@ -670,7 +670,7 @@ ExternalProject_Add(${OPENCV_TARGET}
-DWITH_CUDA=OFF
-DWITH_OPENCL=OFF
-DBUILD_TESTS=OFF
-DBUILD_LIST=core,improc,photo,objdetect,video,imgcodecs,videoio,features2d,xfeatures2d,version
-DBUILD_LIST=core,improc,photo,objdetect,video,imgcodecs,videoio,features2d,xfeatures2d,version,mcc
<SOURCE_DIR>
BUILD_COMMAND $(MAKE)
)
Expand Down
2 changes: 1 addition & 1 deletion docker/fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cmake -P "opencv_contrib-prefix/src/opencv_contrib-stamp/download-opencv_contrib

cmake -P "external/src/alembic-stamp/download-alembic.cmake"
cmake -P "external/src/boost-stamp/download-boost.cmake"
cmake -P "external/src/ceres-stamp/download-ceres.cmake"
# cmake -P "external/src/ceres-stamp/download-ceres.cmake"
cmake -P "external/src/eigen-stamp/download-eigen.cmake"
cmake -P "external/src/ffmpeg-stamp/download-ffmpeg.cmake"
cmake -P "external/src/geogram-stamp/download-geogram.cmake"
Expand Down
1 change: 1 addition & 0 deletions src/aliceVision/image/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
#include "aliceVision/image/convolutionBase.hpp"
#include "aliceVision/image/convolution.hpp"
#include "aliceVision/image/Sampler.hpp"
#include "aliceVision/image/convertionOpenCV.hpp"


98 changes: 98 additions & 0 deletions src/aliceVision/image/convertionOpenCV.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// This file is part of the AliceVision project.
// Copyright (c) 2021 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

#if ALICEVISION_IS_DEFINED(ALICEVISION_HAVE_OPENCV)

#include "aliceVision/image/Image.hpp"
#include <aliceVision/numeric/numeric.hpp>

#include <opencv2/core.hpp>

namespace aliceVision{
namespace image
{


/**
* @brief Sets the value at the specified pixel of a OpenCV BGR image matrix
* Ignores the alpha channel of the source image
* @tparam VecType - OpenCV vector type to interpret the mat values with
* @tparam ValueType - numeric type to cast the color values
* @param[inout] mat - OpenCV mat to set
* @param[in] i - row index to set
* @param[in] j - column index to set
* @param[in] color - value to set
* @param[in] factor - optional scale factor
* @param[in] delta - optional delta added to the scaled values
* @return the resulting openCV image
*/
template <typename VecType, typename ValueType>
inline void setValueCvMatBGR(cv::Mat& mat, int i, int j, const image::RGBAfColor& color, float factor = 1.f,
float delta = 0.f)
{
mat.at<VecType>(i, j)[0] = (ValueType) clamp(color.b() * factor + delta, 0.f, 255.f);
mat.at<VecType>(i, j)[1] = (ValueType) clamp(color.g() * factor + delta, 0.f, 255.f);
mat.at<VecType>(i, j)[2] = (ValueType) clamp(color.r() * factor + delta, 0.f, 255.f);
}


/**
* @brief Converts an aliceVision image to an openCv image (cv::Mat) in BGR
* Ignores the alpha channel of the source image
* @param[in] img - Input RGBA aliceVision image
* @param[in] cvtype - OpenCV mat type (supported values: CV_32FC3, CV_8UC3)
* @return the resulting openCV image
*/
inline cv::Mat imageRGBAToCvMatBGR(const image::Image<image::RGBAfColor>& img, int cvtype = CV_32FC3)
{
cv::Mat mat(img.Height(), img.Width(), cvtype);
for(int i = 0; i < img.Height(); i++)
{
for(int j = 0; j < img.Width(); j++)
{
switch(cvtype)
{
case CV_32FC3:
setValueCvMatBGR<cv::Vec3f, float>(mat, i, j, img(i, j));
break;
case CV_8UC3:
setValueCvMatBGR<cv::Vec3b, uint8_t>(mat, i, j, img(i, j), 255.f);
break;
default:
std::runtime_error("Cannot handle OpenCV matrix type '" + std::to_string(cvtype) + "'.");
}
}
}
return mat;
}


/**
* @brief Converts an openCv image (cv::Mat) in BGR to an aliceVision image
* Keeps the alpha channel of the output image unchanged
* @param[in] img - Input openCV image (cv::Mat)
* @param[out] img - output RGBA aliceVision image
* @return the resulting regex
*/
inline void cvMatBGRToImageRGBA(const cv::Mat& img, image::Image<image::RGBAfColor>& imageOut)
{
for(int row = 0; row < imageOut.Height(); row++)
{
const cv::Vec3f* rowPtr = img.ptr<cv::Vec3f>(row);
for(int col = 0; col < imageOut.Width(); col++)
{
const cv::Vec3f& matPixel = rowPtr[col];
imageOut(row, col) = image::RGBAfColor(matPixel[2], matPixel[1], matPixel[0], imageOut(row, col).a());
}
}
}

} // namespace image
} // namespace aliceVision

#endif // ALICEVISION_HAVE_OPENCV
32 changes: 32 additions & 0 deletions src/software/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,38 @@ alicevision_add_software(aliceVision_utils_lightingEstimation
${Boost_LIBRARIES}
)


# Perform color chart detection
if(ALICEVISION_HAVE_OPENCV)
alicevision_add_software(aliceVision_utils_colorCheckerDetection
SOURCE main_colorCheckerDetection.cpp
FOLDER ${FOLDER_SOFTWARE_UTILS}
LINKS aliceVision_system
aliceVision_sfmData
aliceVision_sfmDataIO
Boost::program_options
Boost::filesystem
${OpenCV_LIBS} # opencv_core opencv_imgproc opencv_video opencv_imgcodecs opencv_videoio opencv_features2d opencv_xfeatures2d
opencv_mcc
)
endif()


# Perform color correction
if(ALICEVISION_HAVE_OPENCV)
alicevision_add_software(aliceVision_utils_colorCheckerCorrection
SOURCE main_colorCheckerCorrection.cpp
FOLDER ${FOLDER_SOFTWARE_UTILS}
LINKS aliceVision_system
aliceVision_sfmData
aliceVision_sfmDataIO
Boost::program_options
Boost::filesystem
${OpenCV_LIBS} # opencv_core opencv_imgproc opencv_video opencv_imgcodecs opencv_videoio opencv_features2d opencv_xfeatures2d
opencv_mcc
)
endif()

endif() # ALICEVISION_BUILD_SFM

if(ALICEVISION_BUILD_MVS)
Expand Down
Loading