Skip to content

Commit

Permalink
Fixed warning in case there are no clefs
Browse files Browse the repository at this point in the history
  • Loading branch information
liebharc committed Jul 7, 2024
1 parent 8238794 commit 2b37c2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions homr/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ def __init__(self, duration: int) -> None:
self.duration = duration

def __str__(self) -> str:
if self.duration == self.NONE:
if self == self.NONE:
return ""
elif self.duration == self.DOT:
elif self == self.DOT:
return "."
elif self.duration == self.TRIPLET:
elif self == self.TRIPLET:
return "³"
else:
return "Invalid duration"
Expand Down
9 changes: 8 additions & 1 deletion homr/staff_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ def __init__(self, staff_lines: list[StaffLineSegment], symbol: RotatedBoundingB
)
y_deltas = [abs(y_positions[i] - y_positions[i - 1]) for i in range(1, len(y_positions))]
self.unit_sizes = y_deltas
self.average_unit_size = float(np.mean(y_deltas))
if len(y_deltas) == 0:
self.average_unit_size = 0
else:
self.average_unit_size = float(np.mean(y_deltas))
self.symbol = symbol
self.max_y = max([line.max_y for line in staff_lines])
self.min_y = min([line.min_y for line in staff_lines])
Expand Down Expand Up @@ -269,6 +272,8 @@ def are_lines_parallel(lines: list[StaffLineSegment], unit_size: float) -> bool:
for fragment in line.staff_fragments:
all_angles.append(fragment.angle)
all_fragments.append(fragment)
if len(all_angles) == 0:
return False
average_angle = np.mean(all_angles)
for fragment in all_fragments:
if abs(
Expand Down Expand Up @@ -588,6 +593,8 @@ def find_horizontal_lines(
def predict_other_anchors_from_clefs(
clef_anchors: list[StaffAnchor], image: NDArray
) -> list[RotatedBoundingBox]:
if len(clef_anchors) == 0:
return []
average_unit_size = float(np.mean([anchor.average_unit_size for anchor in clef_anchors]))
anchor_symbols = [anchor.symbol for anchor in clef_anchors]
clef_zones = init_zone(clef_anchors, image.shape)
Expand Down

0 comments on commit 2b37c2c

Please sign in to comment.