Skip to content

Commit

Permalink
MultiViewIO
Browse files Browse the repository at this point in the history
- Added backwards compatibility check for SceneStructureMetric
  • Loading branch information
lessthanoptimal committed Sep 7, 2024
1 parent a4ed1bc commit 3e18970
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 7 deletions.
36 changes: 29 additions & 7 deletions main/boofcv-io/src/test/java/boofcv/io/geo/TestMultiViewIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
import org.ejml.dense.row.RandomMatrices_DDRM;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -314,19 +311,44 @@ private SceneWorkingGraph createWorkingGraph( PairwiseImageGraph pairwise ) {

var output = new ByteArrayOutputStream();
MultiViewIO.save(expected, new OutputStreamWriter(output, UTF_8));
System.out.println(output.toString(UTF_8));

var input = new ByteArrayInputStream(output.toByteArray());
SceneStructureMetric found = MultiViewIO.load(new InputStreamReader(input, UTF_8), (SceneStructureMetric)null);
assertTrue(expected.isIdentical(found, UtilEjml.TEST_F64));
}
}

/** Test backwards compatibility by loading an older saved file */
@Test void backwards_SceneStructureMetric() {
try (var input = getClass().getResource("scene_metric.yaml").openStream()) {
SceneStructureMetric found = MultiViewIO.load(new InputStreamReader(input, UTF_8), (SceneStructureMetric)null);

// basic sanity check
assertEquals(3, found.views.size);
assertEquals(2, found.motions.size);
assertEquals(2, found.rigids.size);
assertEquals(2, found.cameras.size);
assertEquals(4, found.points.size);
assertEquals(true, found.isHomogeneous());

// Check the value of one of the points
assertArrayEquals(new double[]{
0.5297796154781623, -0.14287775801607175, -0.589691194962917, 0.042599130798539914},
found.points.get(0).coordinate);

// this won't catch all possible errors but will catch most errors which break backwards compatibility
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private SceneStructureMetric createSceneStructureMetric() {
var ret = new SceneStructureMetric(rand.nextBoolean());

int numMotions = 1 + rand.nextInt(4);
ret.initialize(1 + rand.nextInt(4), rand.nextInt(4),
numMotions, rand.nextInt(4), rand.nextInt(4));
int numMotions = 2;
ret.initialize(2, 3,
2, 4, 2);

for (int i = 0; i < numMotions; i++) {
SceneStructureMetric.Motion m = ret.motions.grow();
Expand Down
147 changes: 147 additions & 0 deletions main/boofcv-io/src/test/resources/boofcv/io/geo/scene_metric.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# SceneStructureMetric in YAML format. BoofCV 1.1.7-SNAPSHOT
cameras:
- known: true
model:
f: 0.20761246400921188
k1: -0.46088237974384527
k2: -0.162030555545339
type: PinholeSimplified
- known: false
model:
f: 1.5048724010069527
k1: -0.48658249180944985
k2: 0.40414871036031635
type: PinholeSimplified
motions:
- known: false
motion:
R:
- 0.32671811809927165
- -0.803351178079751
- 0.4978776516209044
- -0.1930630644762411
- 0.4589502504885895
- 0.8672319878276536
- -0.9251929120138747
- -0.37946218817470767
- -0.0051500781498539155
x: -0.9384684558499732
y: 0.3833892546696617
z: -0.9171050084345489
- known: false
motion:
R:
- 0.12950092699138846
- 0.984032558743777
- 0.12210419010233053
- -0.977932190128107
- 0.14710644352772517
- -0.1483520332987328
- -0.16394554406758116
- -0.1001978922173476
- 0.9813675361329136
x: 0.7591895124739547
y: -0.5544830953293928
z: 1.0297458124907035
rigids:
- known: true
object_to_world:
R:
- 0.3140746490838585
- -0.14715529892599727
- -0.937924534704606
- -0.613298755646805
- -0.7855706406894805
- -0.08211823676139035
- -0.7247218439683819
- 0.6010192064191623
- -0.33697798502327825
x: 0.6116157968152922
y: -1.239961248433883
z: 0.415167663727025
indexFirst: 4
points:
- coordinate:
- 0.16059095583255734
- -0.09293038691788402
- -0.2034143688180055
- -0.3968434370734817
views:
- 2
- 2
- 0
- coordinate:
- 0.9602722994622256
- 0.32809730148913063
- 0.10558526069812868
- 0.2499283145243806
views:
- 3
- 2
- 2
- coordinate:
- 1.3961865412218015
- -1.0765261297950028
- -0.32202784578818167
- 0.9897983612473604
views:
- 2
- known: false
object_to_world:
R:
- 0.9030299921545282
- -0.4295472377440316
- 0.005099393676212316
- 0.3973492181727075
- 0.8307117680871192
- -0.38991224292026294
- 0.1632496005720402
- 0.3541286897556374
- 0.9208379005042227
x: -0.5228738472806529
y: 0.14443888166505617
z: 0.7118665016808619
indexFirst: 0
points: []
data_type: SceneStructureMetric
homogenous: true
version: 0
views:
- parent_to_view: 1
camera: 0
- parent_to_view: 1
camera: 0
- parent: 0
parent_to_view: 1
camera: 1
points:
- coordinate:
- 0.5297796154781623
- -0.14287775801607175
- -0.589691194962917
- 0.042599130798539914
views:
- 1
- coordinate:
- -0.28481221072715185
- -0.04975872980620485
- 1.2424021169636152
- 0.7243988298037435
views:
- 1
- coordinate:
- 1.854258912507951
- -1.2986404653349994
- -0.12095099229357216
- 0.25568158777007394
views:
- 3
- coordinate:
- 1.438490351915261
- -0.5290818471910753
- 0.8679390345243388
- -0.07089176363523368
views:
- 3
- 2
- 1

0 comments on commit 3e18970

Please sign in to comment.