Skip to content

Commit

Permalink
add real coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
yuichiroaoki committed Aug 8, 2023
1 parent 3175698 commit abe2a82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cnceye/cmm/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class SingleImage:
def __init__(self, image, center_coordinate: Coordinate, camera: Camera) -> None:
self.image = image
# z coordinate is the height of the object
self.center = center_coordinate
self.camera = camera

Expand All @@ -36,7 +37,7 @@ def from_opencv_coord(self, distance: float, opencv_xy: tuple) -> Coordinate:
return Coordinate(
opencv_origin.x + opencv_xy[0] / pixel_per_mm,
opencv_origin.y - opencv_xy[1] / pixel_per_mm,
self.center.z - distance,
self.center.z,
)

def from_pixel_length(self, distance: float, pixel_length) -> float:
Expand Down Expand Up @@ -66,8 +67,8 @@ def vertex(self, distance: float) -> Coordinate:
return self.from_opencv_coord(distance, (x, y))

def add_real_coordinate(self, distance):
point_id = self.center.unique_key()
real_coordinate = self.vertex(distance)
point_id = self.center.unique_key()

cnx = mysql.connector.connect(**MYSQL_CONFIG, database="coord")
cursor = cnx.cursor()
Expand Down
16 changes: 14 additions & 2 deletions tests/test_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def test_image_0():
image = cv2.imread("tests/fixtures/images/image_0.png")
center_coordinates = Coordinate(-50.0, 65.0, camera_height)
center_coordinates = Coordinate(-50.0, 65.0, object_height)

cmm = SingleImage(image, center_coordinates, camera)
vertex = cmm.vertex(distance)
Expand All @@ -24,4 +24,16 @@ def test_image_0():
y_diff_in_micron = diff_in_micron(65.0, vertex.y)
print(f"y: {y_diff_in_micron:.2f} μm")
assert y_diff_in_micron < 1.0
cmm.add_real_coordinate(distance)
cmm.add_real_coordinate(distance)

def test_add_real_coordinate():
index = 0
with open("scripts/coordinates.txt") as f:
for line in f:
xyz = line.strip().split(",")
x, y, z = [float(i) for i in xyz]

image = cv2.imread(f"tests/fixtures/images/image_{index}.png")
center_coordinates = Coordinate(x, y, z)
cmm = SingleImage(image, center_coordinates, camera)
cmm.add_real_coordinate(distance)

0 comments on commit abe2a82

Please sign in to comment.