Skip to content

fix: 640 camera with distortion v2 to v4 #644

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions doc/changelog.d/644.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
640 camera with distortion v2 to v4
35 changes: 35 additions & 0 deletions src/ansys/speos/core/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
from difflib import SequenceMatcher
from typing import List, Mapping, Optional, Union
import uuid
import warnings

import grpc
import numpy as np

from ansys.api.speos.sensor.v1 import camera_sensor_pb2, common_pb2, sensor_pb2
Expand Down Expand Up @@ -1941,6 +1943,39 @@ def set_axis_system(self, axis_system: Optional[List[float]] = None) -> SensorCa
self._sensor_instance.camera_properties.axis_system[:] = axis_system
return self

def commit(self) -> SensorCamera:
"""Save feature: send the local data to the speos server database.

Returns
-------
ansys.speos.core.sensor.SensorCamera
Sensor feature.
"""
msg = (
"Please note following values {} were over written by the values"
" stored in the distortion file"
)
values_v2 = ["focal_length", "imager_distance", "f_number"]
values_v4 = ["focal_length", "imager_distance", "f_number", "Transmittance Spectrum"]
try:
super().commit()
except grpc.RpcError:
for value in values_v2:
self._sensor_template.camera_sensor_template.ClearField(value)
try:
super().commit()
warnings.warn(msg.format(str(values_v2)), stacklevel=2)
except grpc.RpcError:
self._sensor_template.camera_sensor_template.sensor_mode_photometric.ClearField(
"transmittance_file_uri"
)
try:
super().commit()
warnings.warn(msg.format(str(values_v4)), stacklevel=2)
except grpc.RpcError as e:
raise e
return self


class SensorIrradiance(BaseSensor):
"""Sensor feature: Irradiance.
Expand Down
55 changes: 55 additions & 0 deletions tests/assets/CameraInputFiles/distortionV1.OPTDistortion
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
OPTIS - Optical distortion file v1.0
created by LMR 2011-01-22
0
51
0.0000 0.0000
0.0227 0.0211
0.0454 0.0421
0.0681 0.0631
0.0908 0.0840
0.1134 0.1048
0.1361 0.1255
0.1588 0.1461
0.1815 0.1665
0.2042 0.1868
0.2269 0.2069
0.2496 0.2268
0.2723 0.2465
0.2950 0.2660
0.3176 0.2852
0.3403 0.3043
0.3630 0.3231
0.3857 0.3416
0.4084 0.3599
0.4311 0.3779
0.4538 0.3956
0.4765 0.4131
0.4992 0.4302
0.5219 0.4471
0.5445 0.4637
0.5672 0.4800
0.5899 0.4961
0.6126 0.5118
0.6353 0.5273
0.6580 0.5424
0.6807 0.5573
0.7034 0.5719
0.7261 0.5862
0.7487 0.6002
0.7714 0.6139
0.7941 0.6274
0.8168 0.6406
0.8395 0.6535
0.8622 0.6662
0.8849 0.6786
0.9076 0.6907
0.9303 0.7026
0.9529 0.7143
0.9756 0.7257
0.9983 0.7368
1.0210 0.7478
1.0437 0.7585
1.0664 0.7690
1.0891 0.7792
1.1118 0.7893
1.1345 0.7991
159 changes: 159 additions & 0 deletions tests/assets/CameraInputFiles/distortionV2.OPTDistortion
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
OPTIS - Light Transfer Function file v2.0
Comment
Spherical
Cartesian
Disk
30
0.0 0.1053 0.2106 0.3158 0.4211 0.5264 0.6317 0.7369 0.8422 0.9475 1.0528 1.158 1.2633 1.3686 1.4739 1.5791 1.6844 1.7897 1.895 2.0002 2.1055 2.2108 2.3161 2.4213 2.5266 2.6319 2.7372 2.8425 2.9477 3.053
5
0 90 180 270 360
0.0 0 -0.0002 -0.0 -3.8832 1 268.6805 0.08605 0.4785
0.0 90 -0.0 -0.0002 -3.8832 1 268.6805 0.08605 0.4785
0.0 180 0.0002 -0.0 -3.8832 1 268.6805 0.08605 0.4785
0.0 270 0.0 0.0002 -3.8832 1 268.6805 0.08605 0.4785
0.0 360 -0.0002 0.0 -3.8832 1 268.6805 0.08605 0.4785
1.7435 0 -0.036 -0.0 -3.8826 1 249.817 0.08759 0.4782
1.7435 90 -0.0 -0.036 -3.8826 1 249.817 0.08759 0.4782
1.7435 180 0.036 -0.0 -3.8826 1 249.817 0.08759 0.4782
1.7435 270 0.0 0.036 -3.8826 1 249.817 0.08759 0.4782
1.7435 360 -0.036 0.0 -3.8826 1 249.817 0.08759 0.4782
3.4822 0 -0.0743 -0.0 -3.8805 1 243.2237 0.08987 0.4773
3.4822 90 -0.0 -0.0743 -3.8805 1 243.2237 0.08987 0.4773
3.4822 180 0.0743 -0.0 -3.8805 1 243.2237 0.08987 0.4773
3.4822 270 0.0 0.0743 -3.8805 1 243.2237 0.08987 0.4773
3.4822 360 -0.0743 0.0 -3.8805 1 243.2237 0.08987 0.4773
5.2153 0 -0.11 -0.0 -3.8773 1 282.9998 0.0894 0.4768
5.2153 90 -0.0 -0.11 -3.8773 1 282.9998 0.0894 0.4768
5.2153 180 0.11 -0.0 -3.8773 1 282.9998 0.0894 0.4768
5.2153 270 0.0 0.11 -3.8773 1 282.9998 0.0894 0.4768
5.2153 360 -0.11 0.0 -3.8773 1 282.9998 0.0894 0.4768
6.937 0 -0.1468 -0.0 -3.8724 1 306.8624 0.09146 0.4749
6.937 90 -0.0 -0.1468 -3.8724 1 306.8624 0.09146 0.4749
6.937 180 0.1468 -0.0 -3.8724 1 306.8624 0.09146 0.4749
6.937 270 0.0 0.1468 -3.8724 1 306.8624 0.09146 0.4749
6.937 360 -0.1468 0.0 -3.8724 1 306.8624 0.09146 0.4749
8.6472 0 -0.1813 -0.0 -3.8668 1 218.3407 0.09613 0.473
8.6472 90 -0.0 -0.1813 -3.8668 1 218.3407 0.09613 0.473
8.6472 180 0.1813 -0.0 -3.8668 1 218.3407 0.09613 0.473
8.6472 270 0.0 0.1813 -3.8668 1 218.3407 0.09613 0.473
8.6472 360 -0.1813 0.0 -3.8668 1 218.3407 0.09613 0.473
10.3414 0 -0.2156 -0.0 -3.8601 1 187.6375 0.10077 0.4707
10.3414 90 -0.0 -0.2156 -3.8601 1 187.6375 0.10077 0.4707
10.3414 180 0.2156 -0.0 -3.8601 1 187.6375 0.10077 0.4707
10.3414 270 0.0 0.2156 -3.8601 1 187.6375 0.10077 0.4707
10.3414 360 -0.2156 0.0 -3.8601 1 187.6375 0.10077 0.4707
12.0177 0 -0.2484 -0.0 -3.8523 1 254.0728 0.10192 0.468
12.0177 90 -0.0 -0.2484 -3.8523 1 254.0728 0.10192 0.468
12.0177 180 0.2484 -0.0 -3.8523 1 254.0728 0.10192 0.468
12.0177 270 0.0 0.2484 -3.8523 1 254.0728 0.10192 0.468
12.0177 360 -0.2484 0.0 -3.8523 1 254.0728 0.10192 0.468
13.6746 0 -0.2804 -0.0 -3.8439 1 127.8964 0.11683 0.4647
13.6746 90 -0.0 -0.2804 -3.8439 1 127.8964 0.11683 0.4647
13.6746 180 0.2804 -0.0 -3.8439 1 127.8964 0.11683 0.4647
13.6746 270 0.0 0.2804 -3.8439 1 127.8964 0.11683 0.4647
13.6746 360 -0.2804 0.0 -3.8439 1 127.8964 0.11683 0.4647
15.3088 0 -0.3123 -0.0 -3.8342 1 115.0285 0.12586 0.4611
15.3088 90 -0.0 -0.3123 -3.8342 1 115.0285 0.12586 0.4611
15.3088 180 0.3123 -0.0 -3.8342 1 115.0285 0.12586 0.4611
15.3088 270 0.0 0.3123 -3.8342 1 115.0285 0.12586 0.4611
15.3088 360 -0.3123 0.0 -3.8342 1 115.0285 0.12586 0.4611
16.9196 0 -0.3443 -0.0 -3.8234 1 99.8582 0.13566 0.457
16.9196 90 -0.0 -0.3443 -3.8234 1 99.8582 0.13566 0.457
16.9196 180 0.3443 -0.0 -3.8234 1 99.8582 0.13566 0.457
16.9196 270 0.0 0.3443 -3.8234 1 99.8582 0.13566 0.457
16.9196 360 -0.3443 0.0 -3.8234 1 99.8582 0.13566 0.457
18.5075 0 -0.3739 -0.0 -3.8122 1 92.6182 0.1406 0.4521
18.5075 90 -0.0 -0.3739 -3.8122 1 92.6182 0.1406 0.4521
18.5075 180 0.3739 -0.0 -3.8122 1 92.6182 0.1406 0.4521
18.5075 270 0.0 0.3739 -3.8122 1 92.6182 0.1406 0.4521
18.5075 360 -0.3739 0.0 -3.8122 1 92.6182 0.1406 0.4521
20.0703 0 -0.4046 -0.0 -3.7996 1 82.8437 0.14669 0.4475
20.0703 90 -0.0 -0.4046 -3.7996 1 82.8437 0.14669 0.4475
20.0703 180 0.4046 -0.0 -3.7996 1 82.8437 0.14669 0.4475
20.0703 270 0.0 0.4046 -3.7996 1 82.8437 0.14669 0.4475
20.0703 360 -0.4046 0.0 -3.7996 1 82.8437 0.14669 0.4475
21.61 0 -0.4328 -0.0 -3.787 1 71.9755 0.15562 0.4425
21.61 90 -0.0 -0.4328 -3.787 1 71.9755 0.15562 0.4425
21.61 180 0.4328 -0.0 -3.787 1 71.9755 0.15562 0.4425
21.61 270 0.0 0.4328 -3.787 1 71.9755 0.15562 0.4425
21.61 360 -0.4328 0.0 -3.787 1 71.9755 0.15562 0.4425
23.1267 0 -0.4617 -0.0 -3.7734 1 69.9928 0.15965 0.4378
23.1267 90 -0.0 -0.4617 -3.7734 1 69.9928 0.15965 0.4378
23.1267 180 0.4617 -0.0 -3.7734 1 69.9928 0.15965 0.4378
23.1267 270 0.0 0.4617 -3.7734 1 69.9928 0.15965 0.4378
23.1267 360 -0.4617 0.0 -3.7734 1 69.9928 0.15965 0.4378
24.6192 0 -0.4905 -0.0 -3.7582 1 58.0917 0.17267 0.432
24.6192 90 -0.0 -0.4905 -3.7582 1 58.0917 0.17267 0.432
24.6192 180 0.4905 -0.0 -3.7582 1 58.0917 0.17267 0.432
24.6192 270 0.0 0.4905 -3.7582 1 58.0917 0.17267 0.432
24.6192 360 -0.4905 0.0 -3.7582 1 58.0917 0.17267 0.432
26.09 0 -0.5193 -0.0 -3.7417 1 62.5415 0.17343 0.4256
26.09 90 -0.0 -0.5193 -3.7417 1 62.5415 0.17343 0.4256
26.09 180 0.5193 -0.0 -3.7417 1 62.5415 0.17343 0.4256
26.09 270 0.0 0.5193 -3.7417 1 62.5415 0.17343 0.4256
26.09 360 -0.5193 0.0 -3.7417 1 62.5415 0.17343 0.4256
27.5407 0 -0.5478 -0.0 -3.7239 1 53.9496 0.18515 0.4206
27.5407 90 -0.0 -0.5478 -3.7239 1 53.9496 0.18515 0.4206
27.5407 180 0.5478 -0.0 -3.7239 1 53.9496 0.18515 0.4206
27.5407 270 0.0 0.5478 -3.7239 1 53.9496 0.18515 0.4206
27.5407 360 -0.5478 0.0 -3.7239 1 53.9496 0.18515 0.4206
28.9796 0 -0.572 -0.0 -3.7078 1 54.3289 0.18946 0.4142
28.9796 90 -0.0 -0.572 -3.7078 1 54.3289 0.18946 0.4142
28.9796 180 0.572 -0.0 -3.7078 1 54.3289 0.18946 0.4142
28.9796 270 0.0 0.572 -3.7078 1 54.3289 0.18946 0.4142
28.9796 360 -0.572 0.0 -3.7078 1 54.3289 0.18946 0.4142
30.4031 0 -0.5972 -0.0 -3.6899 1 49.0202 0.19941 0.4076
30.4031 90 -0.0 -0.5972 -3.6899 1 49.0202 0.19941 0.4076
30.4031 180 0.5972 -0.0 -3.6899 1 49.0202 0.19941 0.4076
30.4031 270 0.0 0.5972 -3.6899 1 49.0202 0.19941 0.4076
30.4031 360 -0.5972 0.0 -3.6899 1 49.0202 0.19941 0.4076
31.82 0 -0.6221 -0.0 -3.6713 1 46.9482 0.2044 0.4008
31.82 90 -0.0 -0.6221 -3.6713 1 46.9482 0.2044 0.4008
31.82 180 0.6221 -0.0 -3.6713 1 46.9482 0.2044 0.4008
31.82 270 0.0 0.6221 -3.6713 1 46.9482 0.2044 0.4008
31.82 360 -0.6221 0.0 -3.6713 1 46.9482 0.2044 0.4008
33.2269 0 -0.6471 -0.0 -3.6508 1 44.5472 0.21483 0.3937
33.2269 90 -0.0 -0.6471 -3.6508 1 44.5472 0.21483 0.3937
33.2269 180 0.6471 -0.0 -3.6508 1 44.5472 0.21483 0.3937
33.2269 270 0.0 0.6471 -3.6508 1 44.5472 0.21483 0.3937
33.2269 360 -0.6471 0.0 -3.6508 1 44.5472 0.21483 0.3937
34.6382 0 -0.6712 -0.0 -3.6302 1 44.342 0.22135 0.3856
34.6382 90 -0.0 -0.6712 -3.6302 1 44.342 0.22135 0.3856
34.6382 180 0.6712 -0.0 -3.6302 1 44.342 0.22135 0.3856
34.6382 270 0.0 0.6712 -3.6302 1 44.342 0.22135 0.3856
34.6382 360 -0.6712 0.0 -3.6302 1 44.342 0.22135 0.3856
36.0551 0 -0.6941 -0.0 -3.6089 1 42.4606 0.23194 0.3778
36.0551 90 -0.0 -0.6941 -3.6089 1 42.4606 0.23194 0.3778
36.0551 180 0.6941 -0.0 -3.6089 1 42.4606 0.23194 0.3778
36.0551 270 0.0 0.6941 -3.6089 1 42.4606 0.23194 0.3778
36.0551 360 -0.6941 0.0 -3.6089 1 42.4606 0.23194 0.3778
37.4892 0 -0.7182 -0.0 -3.5849 1 40.9186 0.24228 0.3697
37.4892 90 -0.0 -0.7182 -3.5849 1 40.9186 0.24228 0.3697
37.4892 180 0.7182 -0.0 -3.5849 1 40.9186 0.24228 0.3697
37.4892 270 0.0 0.7182 -3.5849 1 40.9186 0.24228 0.3697
37.4892 360 -0.7182 0.0 -3.5849 1 40.9186 0.24228 0.3697
38.9466 0 -0.7412 -0.0 -3.5601 1 40.6093 0.25444 0.36
38.9466 90 -0.0 -0.7412 -3.5601 1 40.6093 0.25444 0.36
38.9466 180 0.7412 -0.0 -3.5601 1 40.6093 0.25444 0.36
38.9466 270 0.0 0.7412 -3.5601 1 40.6093 0.25444 0.36
38.9466 360 -0.7412 0.0 -3.5601 1 40.6093 0.25444 0.36
40.4538 0 -0.765 -0.0 -3.5332 1 43.6315 0.26136 0.351
40.4538 90 -0.0 -0.765 -3.5332 1 43.6315 0.26136 0.351
40.4538 180 0.765 -0.0 -3.5332 1 43.6315 0.26136 0.351
40.4538 270 0.0 0.765 -3.5332 1 43.6315 0.26136 0.351
40.4538 360 -0.765 0.0 -3.5332 1 43.6315 0.26136 0.351
42.0054 0 -0.7888 -0.0 -3.503 1 40.833 0.27979 0.3409
42.0054 90 -0.0 -0.7888 -3.503 1 40.833 0.27979 0.3409
42.0054 180 0.7888 -0.0 -3.503 1 40.833 0.27979 0.3409
42.0054 270 0.0 0.7888 -3.503 1 40.833 0.27979 0.3409
42.0054 360 -0.7888 0.0 -3.503 1 40.833 0.27979 0.3409
43.6699 0 -0.8165 -0.0 -3.4659 1 50.7589 0.29008 0.3306
43.6699 90 -0.0 -0.8165 -3.4659 1 50.7589 0.29008 0.3306
43.6699 180 0.8165 -0.0 -3.4659 1 50.7589 0.29008 0.3306
43.6699 270 0.0 0.8165 -3.4659 1 50.7589 0.29008 0.3306
43.6699 360 -0.8165 0.0 -3.4659 1 50.7589 0.29008 0.3306
45.4669 0 -0.8424 -0.0 -3.4274 1 68.7931 0.31299 0.3184
45.4669 90 -0.0 -0.8424 -3.4274 1 68.7931 0.31299 0.3184
45.4669 180 0.8424 -0.0 -3.4274 1 68.7931 0.31299 0.3184
45.4669 270 0.0 0.8424 -3.4274 1 68.7931 0.31299 0.3184
45.4669 360 -0.8424 0.0 -3.4274 1 68.7931 0.31299 0.3184
Binary file not shown.
47 changes: 47 additions & 0 deletions tests/core/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def test_create_camera_sensor(speos: Speos):

# Default value
sensor1 = p.create_sensor(name="Camera.1", feature_type=SensorCamera)
if isinstance(sensor1, SensorCamera):
pass
else:
assert False
sensor1.set_mode_photometric().set_mode_color().set_red_spectrum_file_uri(
uri=str(Path(test_path) / "CameraInputFiles" / "CameraSensitivityRed.spectrum")
)
Expand Down Expand Up @@ -374,6 +378,49 @@ def test_create_camera_sensor(speos: Speos):
sensor1.commit()
assert sensor1._sensor_instance.camera_properties.HasField("layer_type_none")

# test distrotion v1,v2,v3
sensor1.set_f_number().set_imager_distance().set_focal_length()
sensor1.commit()
sensor1.set_distortion_file_uri(
str(Path(test_path) / "CameraInputFiles" / "distortionV{}.OPTDistortion".format(2))
)
camera_sensor_template = sensor1.sensor_template_link.get().camera_sensor_template
assert camera_sensor_template.f_number == 20.0
assert camera_sensor_template.imager_distance == 10.0
assert camera_sensor_template.focal_length == 5.0
sensor1.commit()
camera_sensor_template = sensor1.sensor_template_link.get().camera_sensor_template
assert camera_sensor_template.f_number == 0
assert camera_sensor_template.imager_distance == 0
assert camera_sensor_template.focal_length == 0
sensor1.set_distortion_file_uri(
str(Path(test_path) / "CameraInputFiles" / "distortionV{}.OPTDistortion".format(1))
)
sensor1.set_f_number().set_imager_distance().set_focal_length()
camera_sensor_template = sensor1.sensor_template_link.get().camera_sensor_template
assert camera_sensor_template.f_number == 0
assert camera_sensor_template.imager_distance == 0
assert camera_sensor_template.focal_length == 0
sensor1.commit()
camera_sensor_template = sensor1.sensor_template_link.get().camera_sensor_template
assert camera_sensor_template.f_number == 20.0
assert camera_sensor_template.imager_distance == 10.0
assert camera_sensor_template.focal_length == 5.0
sensor1.set_distortion_file_uri(
str(Path(test_path) / "CameraInputFiles" / "distortionV{}.OPTDistortion".format(4))
)
camera_sensor_template = sensor1.sensor_template_link.get().camera_sensor_template
assert camera_sensor_template.f_number == 20.0
assert camera_sensor_template.imager_distance == 10.0
assert camera_sensor_template.focal_length == 5.0
assert camera_sensor_template.sensor_mode_photometric.transmittance_file_uri != ""
sensor1.commit()
camera_sensor_template = sensor1.sensor_template_link.get().camera_sensor_template
assert camera_sensor_template.f_number == 0
assert camera_sensor_template.imager_distance == 0
assert camera_sensor_template.focal_length == 0
assert camera_sensor_template.sensor_mode_photometric.transmittance_file_uri == ""

sensor1.delete()


Expand Down