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

New ColorChecker Detection and Correction #1266

Merged
merged 26 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a67bd4d
[nodes] add color checker detection (crashtest)
ludchieng Dec 2, 2020
b1e42e0
Add ColorCheckerDetection pipeline
ludchieng Jan 11, 2021
402c315
[nodes] ColorCheckerDetection: update params
ludchieng Jan 11, 2021
c352e64
[nodes] ColorCheckerCorrection: create node and add it to pipeline
vscav Jan 14, 2021
0984a48
[nodes] ColorChecker: update nodes io
ludchieng Jan 15, 2021
c064b70
[nodes] ColorCheckerCorrection: add SfmData output
vscav Jan 18, 2021
c4553fc
[nodes] ColorChecker: update io and doc
ludchieng Jan 19, 2021
fd59e17
[nodes] ColorChecker: add extension output option
vscav Jan 20, 2021
23dacd2
[nodes] ColorChecker: add postion data output and rename io
ludchieng Jan 20, 2021
d474c17
[nodes] ColorCheckerDetection: remove position data output
ludchieng Jan 21, 2021
7e4ae7c
[nodes] ColorCheckerCorrection: add new file extensions
vscav Jan 21, 2021
899da9e
[nodes] colorCheckerCorrection: rename checker data input
vscav Jan 22, 2021
8f5472a
[nodes] ColorCheckerDetection: add max charts count input and update io
ludchieng Jan 25, 2021
c1ccd5a
[ui] add ColorCheckerViewer
ludchieng Jan 25, 2021
536c9b7
[ui] ColorCheckerViewer: show cchecker in the aside pane
ludchieng Jan 25, 2021
f48f83a
[ui] ColorCheckerViewer: ux improve & remove irrelevant qml includes
ludchieng Jan 26, 2021
a014bcf
[nodes] ColorCheckerCorrection: change output extensions
vscav Jan 28, 2021
e3f685f
[ui] remove colorcheckerdetection pipeline
ludchieng Feb 11, 2021
4f52fad
[ui nodes] ColorChecker: fix refactor and documentation
ludchieng Feb 27, 2021
214a011
[ui] ColorCheckerViewer: fix url path
ludchieng Mar 25, 2021
2f4c736
[ui] ColorCheckerViewer: fix CCheckerPane display
ludchieng Apr 7, 2021
ad3e67e
[ui] ColorCheckerViewer: allow to display the ColorChecker without sf…
fabiencastan Apr 21, 2021
fee4bc9
[ui] ColorCheckerViewer: add load onCompleted
fabiencastan Apr 21, 2021
b2bb1e1
[ui] reconstruction: minor rename
fabiencastan Apr 21, 2021
a17fdf3
[ui] reconstruction: remove dead code
fabiencastan Apr 21, 2021
35e831c
[ui] ColorCheckerViewer: add comment
fabiencastan Apr 26, 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
79 changes: 79 additions & 0 deletions meshroom/nodes/aliceVision/ColorCheckerCorrection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
__version__ = "1.0"

from meshroom.core import desc

import os.path


class ColorCheckerCorrection(desc.CommandLineNode):
commandLine = 'aliceVision_utils_colorCheckerCorrection {allParams}'
size = desc.DynamicNodeSize('input')
# parallelization = desc.Parallelization(blockSize=40)
# commandLineRange = '--rangeStart {rangeStart} --rangeSize {rangeBlockSize}'

documentation = '''
(BETA) \\
Performs color calibration from Macbeth color checker chart.

The node assumes all the images to process are sharing the same colorimetric properties.
All the input images will get the same correction.

If multiple color charts are submitted, only the first one will be taken in account.
'''

inputs = [
desc.File(
name='inputData',
label='Color checker data',
description='Position and colorimetric data of the color checker',
value='',
uid=[0],
),
desc.File(
name='input',
label='Input',
description='SfMData file input, image filenames or regex(es) on the image file path.\nsupported regex: \'#\' matches a single digit, \'@\' one or more digits, \'?\' one character and \'*\' zero or more.',
value='',
uid=[0],
),
desc.ChoiceParam(
name='extension',
label='Output File Extension',
description='Output Image File Extension.',
value='exr',
values=['exr', ''],
exclusive=True,
uid=[0],
),
desc.ChoiceParam(
name='storageDataType',
label='Storage Data Type for EXR output',
description='Storage image data type:\n'
' * float: Use full floating point (32 bits per channel)\n'
' * half: Use half float (16 bits per channel)\n'
' * halfFinite: Use half float, but clamp values to avoid non-finite values\n'
' * auto: Use half float if all values can fit, else use full float\n',
value='float',
values=['float', 'half', 'halfFinite', 'auto'],
exclusive=True,
uid=[0],
),
]

outputs = [
desc.File(
name='outSfMData',
label='Output sfmData',
description='Output sfmData.',
value=lambda attr: (desc.Node.internalFolder + os.path.basename(attr.node.input.value)) if (os.path.splitext(attr.node.input.value)[1] in ['.abc', '.sfm']) else '',
uid=[],
group='', # do not export on the command line
),
desc.File(
name='output',
label='Output Folder',
description='Output Images Folder.',
value=desc.Node.internalFolder,
uid=[],
),
]
63 changes: 63 additions & 0 deletions meshroom/nodes/aliceVision/ColorCheckerDetection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
__version__ = "1.0"

from meshroom.core import desc

import os.path


class ColorCheckerDetection(desc.CommandLineNode):
commandLine = 'aliceVision_utils_colorCheckerDetection {allParams}'
size = desc.DynamicNodeSize('input')
# parallelization = desc.Parallelization(blockSize=40)
# commandLineRange = '--rangeStart {rangeStart} --rangeSize {rangeBlockSize}'

documentation = '''
(BETA) \\
Performs Macbeth color checker chart detection.

Outputs:
- the detected color charts position and colors
- the associated tranform matrix from "theoric" to "measured"
assuming that the "theoric" Macbeth chart corners coordinates are:
(0, 0), (1675, 0), (1675, 1125), (0, 1125)

Dev notes:
- Fisheye/pinhole is not handled
- ColorCheckerViewer is unstable with multiple color chart within a same image
'''

inputs = [
desc.File(
name='input',
label='Input',
description='SfMData file input, image filenames or regex(es) on the image file path.\nsupported regex: \'#\' matches a single digit, \'@\' one or more digits, \'?\' one character and \'*\' zero or more.',
value='',
uid=[0],
),
desc.IntParam(
name='maxCount',
label='Max count by image',
description='Max color charts count to detect in a single image',
value=1,
range=(1, 3, 1),
uid=[0],
advanced=True,
),
desc.BoolParam(
name='debug',
label='Debug',
description='If checked, debug data will be generated',
value=False,
uid=[0],
),
]

outputs = [
desc.File(
name='outputData',
label='Color checker data',
description='Output position and colorimetric data extracted from detected color checkers in the images',
value=desc.Node.internalFolder + '/ccheckers.json',
uid=[],
),
]
43 changes: 43 additions & 0 deletions meshroom/ui/qml/Viewer/ColorCheckerEntity.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import QtQuick 2.11

Item {
id: root

// required for perspective transform
property real sizeX: 1675.0 // might be overrided in ColorCheckerViewer
property real sizeY: 1125.0 // might be overrided in ColorCheckerViewer

property var colors: null
property var window: null


Rectangle {
id: canvas
anchors.centerIn: parent

width: parent.sizeX
height: parent.sizeY

color: "transparent"
border.width: Math.max(1, (4.0 / zoom))
border.color: "red"

transformOrigin: Item.TopLeft
transform: Matrix4x4 {
id: transformation
matrix: Qt.matrix4x4()
}

}


function transform(matrix) {
var m = matrix
transformation.matrix = Qt.matrix4x4(
m[0][0], m[0][1], 0, m[0][2],
m[1][0], m[1][1], 0, m[1][2],
0, 0, 1, 0,
m[2][0], m[2][1], 0, m[2][2] )
}

}
42 changes: 42 additions & 0 deletions meshroom/ui/qml/Viewer/ColorCheckerPane.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import QtQuick 2.11
import QtQuick.Layouts 1.3

import Controls 1.0

FloatingPane {
id: root

property var colors: null

clip: true
padding: 4
anchors.rightMargin: 0


ColumnLayout {
anchors.fill: parent

Grid {
id: grid

spacing: 5
x: spacing
y: spacing
rows: 4
columns: 6

Repeater {
model: root.colors

Rectangle {
id: cell
width: root.width / grid.columns - grid.spacing * (grid.columns+1) / grid.columns
height: root.height / grid.rows - grid.spacing * (grid.rows+1) / grid.rows
color: Qt.rgba(modelData.r, modelData.g, modelData.b, 1.0)
}

}
}
}

}
102 changes: 102 additions & 0 deletions meshroom/ui/qml/Viewer/ColorCheckerViewer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import QtQuick 2.11

Item {
id: root

property url source: undefined
property var json: null
property var image: null
property var viewpoint: null
property real zoom: 1.0

// required for perspective transform
// Match theoretical values in AliceVision
// see https://github.com/alicevision/AliceVision/blob/68ab70bcbc3eb01b73dc8dea78c78d8b4778461c/src/software/utils/main_colorCheckerDetection.cpp#L47
readonly property real ccheckerSizeX: 1675.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this value come from?

readonly property real ccheckerSizeY: 1125.0

// offset the cchecker top left corner to match the image top left corner
x: -image.width / 2 + ccheckerSizeX / 2
y: -image.height / 2 + ccheckerSizeY / 2

property var ccheckers: []
property int selectedCChecker: -1

Component.onCompleted: { readSourceFile(); }
onSourceChanged: { readSourceFile(); }
onViewpointChanged: { loadCCheckers(); }
property var updatePane: null


function getColors() {
if (ccheckers[selectedCChecker] === undefined)
return null;

if (ccheckers[selectedCChecker].colors === undefined)
return null;

return ccheckers[selectedCChecker].colors;
}

function readSourceFile() {
var xhr = new XMLHttpRequest;
// console.warn("readSourceFile: " + root.source)
xhr.open("GET", root.source);

xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status == 200) {
try {
root.json = null;
// console.warn("readSourceFile: update json from " + root.source)
root.json = JSON.parse(xhr.responseText);
// console.warn("readSourceFile: root.json.checkers.length=" + root.json.checkers.length)
}
catch(exc)
{
console.warn("Failed to parse ColorCheckerDetection JSON file: " + source);
return;
}
}
loadCCheckers();
};
xhr.send();
}

function loadCCheckers() {
emptyCCheckers();
if (root.json === null)
{
return;
}

var currentImagePath = (root.viewpoint && root.viewpoint.attribute && root.viewpoint.attribute.childAttribute("path")) ? root.viewpoint.attribute.childAttribute("path").value : null
var viewId = (root.viewpoint && root.viewpoint.attribute && root.viewpoint.attribute.childAttribute("viewId")) ? root.viewpoint.attribute.childAttribute("viewId").value : null
for (var i = 0; i < root.json.checkers.length; i++) {
// Only load ccheckers for the current view
var checker = root.json.checkers[i]
if (checker.viewId == viewId ||
checker.imagePath == currentImagePath) {
var cpt = Qt.createComponent("ColorCheckerEntity.qml");

var obj = cpt.createObject(root, {
sizeX: root.ccheckerSizeX,
sizeY: root.ccheckerSizeY,
colors: root.json.checkers[i].colors
});
obj.transform(root.json.checkers[i].transform);
ccheckers.push(obj);
selectedCChecker = ccheckers.length-1;
break;
}
}
updatePane();
}

function emptyCCheckers() {
for (var i = 0; i < ccheckers.length; i++)
ccheckers[i].destroy();
ccheckers = [];
selectedCChecker = -1;
}

}
Loading