Skip to content

Commit

Permalink
OpenCV 4.9 update: check if frames are writable
Browse files Browse the repository at this point in the history
  • Loading branch information
carienmol committed Mar 26, 2024
1 parent 3f97cfa commit 7ce96d0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions birdwatcher/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
'framegray', 'framenoise']


def _check_writable(frame):
if not frame.flags.writeable:
return frame.copy()
else:
return frame


def frameiterator(func):
@wraps(func)
def wrapper(*args, **kwargs):
Expand Down Expand Up @@ -244,6 +251,7 @@ def draw_circles(self, centers, radius=6, color=(255, 100, 0),
"""
for frame, center in zip(self._frames, centers):
frame = _check_writable(frame)
center = np.asanyarray(center)
if not np.isnan(center).any():
(x, y) = center.astype('int16')
Expand Down Expand Up @@ -279,6 +287,7 @@ def draw_rectangles(self, points, color=(255, 100, 0), thickness=2):
"""
for frame, framepoints in zip(self._frames, points):
frame = _check_writable(frame)
framepoints = np.asanyarray(framepoints)
if not np.isnan(framepoints).any():
(pt1, pt2) = framepoints.astype('int16')
Expand Down Expand Up @@ -351,6 +360,7 @@ def draw_framenumbers(self, startat=0, org=(2, 25),
"""
for frameno, frame in enumerate(self._frames):
frame = _check_writable(frame)
yield cv.putText(frame, str(frameno + startat), org=org,
fontFace=fontface, fontScale=fontscale,
color=color, thickness=thickness,
Expand Down Expand Up @@ -390,6 +400,7 @@ def draw_text(self, textiterator, org=(2, 25),
"""
for frame, text in zip(self._frames, textiterator):
frame = _check_writable(frame)
yield cv.putText(frame, str(text), org=org,
fontFace=fontface, fontScale=fontscale,
color=color, thickness=thickness,
Expand Down

0 comments on commit 7ce96d0

Please sign in to comment.