Commit 150bb5fe authored by VIOLANTE Nicolas's avatar VIOLANTE Nicolas
Browse files

use dataset.json for polyscope instead of records

parent b58de127
import json
import cv2 as cv
import numpy as np
from scipy.spatial.transform import Rotation
from collections import namedtuple
import polyscope as ps
from collections import namedtuple
ObjectBox = namedtuple("ObjectBox", ["coord_system", "vertices", "faces", "name"])
CoordSystem = namedtuple("CoordSystem", ["basis", "origin"])
......@@ -199,14 +199,14 @@ eg3d_object_sys = CoordSystem(
)
if __name__ == "__main__":
nums = [1046, 1052, 1063, 1071, 1075, 1132, 1133, 1134]
cams = {}
with open("./camera_calib/data/dataset.json", "r+") as f:
data = json.load(f)
# Load cars annoations
for num in nums:
record = np.load(
f"./camera_calib/results/img0000{num}.npy", allow_pickle=True
).item()
cam2world = np.array(record["cam2world"]).reshape(4, 4)
cams = {}
for annot in data["labels"]:
num = annot[0][3:-4]
cam2world = np.array(annot[1][:16]).reshape(4, 4)
cam = transform_coord_system(eg3d_object_sys, cam2world)
cams[num] = cam
......
{
"labels": [
[
"img00001134.png",
[
0.9052826944401778,
0.02071332292852569,
-0.4243043735343648,
1.0679541540464565,
-0.02748353048292094,
-0.9938623395217085,
-0.10715552077531973,
0.3026884270960466,
-0.42391968425555043,
0.10866742075569047,
-0.899157101382723,
2.3494933527342234,
0.0,
0.0,
0.0,
1.0,
4.2647,
0.0,
0.5,
0.0,
4.2647,
0.5,
0.0,
0.0,
1.0
]
],
[
"img00001132.png",
[
0.7955038111179689,
0.023344898347068977,
-0.6054987218962167,
1.7790080327254527,
-0.03712814284363518,
-0.99550217260176,
-0.08716034278362063,
0.30947425694901465,
-0.6048100424974521,
0.09181742790092057,
-0.7910590195604176,
2.390564206546818,
0.0,
0.0,
0.0,
1.0,
4.2647,
0.0,
0.5,
0.0,
4.2647,
0.5,
0.0,
0.0,
1.0
]
],
[
"img00001071.png",
[
0.8443416124628496,
-0.008881967639274988,
0.5357316045507207,
-1.6736065277108438,
0.04540825072156987,
-0.9950793591821253,
-0.0880633845369249,
0.2984278778290829,
0.5338776378816048,
0.09868221511775145,
-0.8397835960468697,
2.6774747621305015,
0.0,
0.0,
0.0,
1.0,
4.2647,
0.0,
0.5,
0.0,
4.2647,
0.5,
0.0,
0.0,
1.0
]
],
[
"img00001063.png",
[
0.6544798335902652,
-0.0025163520158360078,
0.7560752709857607,
-2.670089342808706,
0.05562971185445911,
-0.9971237843855066,
-0.051473233546333284,
0.22060798729504083,
0.7540301602606152,
0.07574844279097634,
-0.6524574245359571,
2.3185540624130123,
0.0,
0.0,
0.0,
1.0,
4.2647,
0.0,
0.5,
0.0,
4.2647,
0.5,
0.0,
0.0,
1.0
]
],
[
"img00001133.png",
[
0.8750864551771395,
0.01920380455962355,
-0.48358547316471734,
1.306529934546605,
-0.03158084091979072,
-0.9948169421226886,
-0.09665351598603329,
0.2976235790969666,
-0.4829351368996738,
0.09985221858376156,
-0.8699443591354531,
2.4397028273339614,
0.0,
0.0,
0.0,
1.0,
4.2647,
0.0,
0.5,
0.0,
4.2647,
0.5,
0.0,
0.0,
1.0
]
],
[
"img00001046.png",
[
-0.033770746531918,
0.004352933814657819,
-0.9994201261961267,
3.744233453709123,
-0.05251686440590181,
-0.998616717759052,
-0.002574871862855026,
-0.026355284025602794,
-0.9980488543311138,
0.052399455906938626,
0.033952634492889565,
-0.11725595521819378,
0.0,
0.0,
0.0,
1.0,
4.2647,
0.0,
0.5,
0.0,
4.2647,
0.5,
0.0,
0.0,
1.0
]
],
[
"img00001052.png",
[
0.8843494278322417,
0.0018537949174591247,
0.46682186424501415,
-1.4396190054343736,
0.03736093581877585,
-0.9970655001329393,
-0.06681728009577584,
0.20846640489093718,
0.4653281100122061,
0.076530725130865,
-0.8818235640667648,
2.777213098213149,
0.0,
0.0,
0.0,
1.0,
4.2647,
0.0,
0.5,
0.0,
4.2647,
0.5,
0.0,
0.0,
1.0
]
],
[
"img00001075.png",
[
0.873230488585378,
-0.0023582884014324364,
0.4873017056000913,
-1.573570181922337,
0.027435195098408756,
-0.9981643118866942,
-0.05399367134835601,
0.16387210343896882,
0.48653450430041917,
0.06051813737696889,
-0.8715628096549136,
2.8188505021907955,
0.0,
0.0,
0.0,
1.0,
4.2647,
0.0,
0.5,
0.0,
4.2647,
0.5,
0.0,
0.0,
1.0
]
]
]
}
\ No newline at end of file
import numpy as np
import polyscope as ps
import cv2 as cv
import json
from cam2world import (
CoordSystem,
......@@ -13,16 +14,14 @@ from cam2world import (
)
if __name__ == "__main__":
nums = [1046, 1052, 1063, 1071, 1075, 1132, 1133, 1134]
with open("./camera_calib/data/dataset.json", "r+") as f:
data = json.load(f)
boxes = []
for num in nums:
record = np.load(
f"./camera_calib/results/img0000{num}.npy", allow_pickle=True
).item()
cam2world = np.array(record["cam2world"]).reshape(4, 4)
for annot in data["labels"]:
num = annot[0][3:-4]
cam2world = np.array(annot[1][:16]).reshape(4, 4)
world2cam = np.linalg.inv(cam2world)
angles = cv.Rodrigues(world2cam[:3, :3])[0][:, 0] * 180 / np.pi
print(angles)
box = create_box(
world2cam,
eg3d_object_sys,
......@@ -39,5 +38,4 @@ if __name__ == "__main__":
for box in boxes:
c = np.random.rand(3)
add_box(box, color=(c[0], c[1], c[2]))
ps.show()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment