Skip to content

Commit 09caa3c

Browse files
committed
[bugfix] Fix for circular import errors #350
1 parent 9bf4dd9 commit 09caa3c

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

scenedetect/backends/moviepy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import cv2
2424
from moviepy.video.io.ffmpeg_reader import FFMPEG_VideoReader
25-
from numpy import ndarray
25+
import numpy as np
2626

2727
from scenedetect.frame_timecode import FrameTimecode
2828
from scenedetect.platform import get_file_name
@@ -63,8 +63,8 @@ def __init__(self, path: AnyStr, framerate: Optional[float] = None, print_infos:
6363
# This will always be one behind self._reader.lastread when we finally call read()
6464
# as MoviePy caches the first frame when opening the video. Thus self._last_frame
6565
# will always be the current frame, and self._reader.lastread will be the next.
66-
self._last_frame: Union[bool, ndarray] = False
67-
self._last_frame_rgb: Optional[ndarray] = None
66+
self._last_frame: Union[bool, np.ndarray] = False
67+
self._last_frame_rgb: Optional[np.ndarray] = None
6868
# Older versions don't track the video position when calling read_frame so we need
6969
# to keep track of the current frame number.
7070
self._frame_number = 0
@@ -193,15 +193,15 @@ def reset(self):
193193
self._frame_number = 0
194194
self._eof = False
195195

196-
def read(self, decode: bool = True, advance: bool = True) -> Union[ndarray, bool]:
197-
"""Read and decode the next frame as a numpy.ndarray. Returns False when video ends.
196+
def read(self, decode: bool = True, advance: bool = True) -> Union[np.ndarray, bool]:
197+
"""Read and decode the next frame as a np.ndarray. Returns False when video ends.
198198
199199
Arguments:
200200
decode: Decode and return the frame.
201201
advance: Seek to the next frame. If False, will return the current (last) frame.
202202
203203
Returns:
204-
If decode = True, the decoded frame (numpy.ndarray), or False (bool) if end of video.
204+
If decode = True, the decoded frame (np.ndarray), or False (bool) if end of video.
205205
If decode = False, a bool indicating if advancing to the the next frame succeeded.
206206
"""
207207
if not advance:

scenedetect/backends/opencv.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import os.path
2525

2626
import cv2
27-
from numpy import ndarray
27+
import numpy as np
2828

2929
from scenedetect.frame_timecode import FrameTimecode, MAX_FPS_DELTA
3030
from scenedetect.platform import get_file_name
@@ -262,16 +262,16 @@ def reset(self):
262262
self._cap.release()
263263
self._open_capture(self._frame_rate)
264264

265-
def read(self, decode: bool = True, advance: bool = True) -> Union[ndarray, bool]:
266-
"""Read and decode the next frame as a numpy.ndarray. Returns False when video ends,
265+
def read(self, decode: bool = True, advance: bool = True) -> Union[np.ndarray, bool]:
266+
"""Read and decode the next frame as a np.ndarray. Returns False when video ends,
267267
or the maximum number of decode attempts has passed.
268268
269269
Arguments:
270270
decode: Decode and return the frame.
271271
advance: Seek to the next frame. If False, will return the current (last) frame.
272272
273273
Returns:
274-
If decode = True, the decoded frame (numpy.ndarray), or False (bool) if end of video.
274+
If decode = True, the decoded frame (np.ndarray), or False (bool) if end of video.
275275
If decode = False, a bool indicating if advancing to the the next frame succeeded.
276276
"""
277277
if not self._cap.isOpened():
@@ -497,16 +497,16 @@ def reset(self):
497497
"""Not supported."""
498498
raise NotImplementedError("Reset is not supported.")
499499

500-
def read(self, decode: bool = True, advance: bool = True) -> Union[ndarray, bool]:
501-
"""Read and decode the next frame as a numpy.ndarray. Returns False when video ends,
500+
def read(self, decode: bool = True, advance: bool = True) -> Union[np.ndarray, bool]:
501+
"""Read and decode the next frame as a np.ndarray. Returns False when video ends,
502502
or the maximum number of decode attempts has passed.
503503
504504
Arguments:
505505
decode: Decode and return the frame.
506506
advance: Seek to the next frame. If False, will return the current (last) frame.
507507
508508
Returns:
509-
If decode = True, the decoded frame (numpy.ndarray), or False (bool) if end of video.
509+
If decode = True, the decoded frame (np.ndarray), or False (bool) if end of video.
510510
If decode = False, a bool indicating if advancing to the the next frame succeeded.
511511
"""
512512
if not self._cap.isOpened():

scenedetect/backends/pyav.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# pylint: disable=c-extension-no-member
1919
import av
20-
from numpy import ndarray
20+
import numpy as np
2121

2222
from scenedetect.frame_timecode import FrameTimecode, MAX_FPS_DELTA
2323
from scenedetect.platform import get_file_name
@@ -261,15 +261,15 @@ def reset(self):
261261
except Exception as ex:
262262
raise VideoOpenFailure() from ex
263263

264-
def read(self, decode: bool = True, advance: bool = True) -> Union[ndarray, bool]:
265-
"""Read and decode the next frame as a numpy.ndarray. Returns False when video ends.
264+
def read(self, decode: bool = True, advance: bool = True) -> Union[np.ndarray, bool]:
265+
"""Read and decode the next frame as a np.ndarray. Returns False when video ends.
266266
267267
Arguments:
268268
decode: Decode and return the frame.
269269
advance: Seek to the next frame. If False, will return the current (last) frame.
270270
271271
Returns:
272-
If decode = True, the decoded frame (numpy.ndarray), or False (bool) if end of video.
272+
If decode = True, the decoded frame (np.ndarray), or False (bool) if end of video.
273273
If decode = False, a bool indicating if advancing to the the next frame succeeded.
274274
"""
275275
has_advanced = False

scenedetect/detectors/adaptive_detector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from logging import getLogger
2121
from typing import List, Optional
2222

23-
from numpy import ndarray
23+
import numpy as np
2424

2525
from scenedetect.detectors import ContentDetector
2626

@@ -114,14 +114,14 @@ def stats_manager_required(self) -> bool:
114114
"""Not required for AdaptiveDetector."""
115115
return False
116116

117-
def process_frame(self, frame_num: int, frame_img: Optional[ndarray]) -> List[int]:
117+
def process_frame(self, frame_num: int, frame_img: Optional[np.ndarray]) -> List[int]:
118118
""" Similar to ThresholdDetector, but using the HSV colour space DIFFERENCE instead
119119
of single-frame RGB/grayscale intensity (thus cannot detect slow fades with this method).
120120
121121
Arguments:
122122
frame_num: Frame number of frame that is being passed.
123123
124-
frame_img: Decoded frame image (numpy.ndarray) to perform scene
124+
frame_img: Decoded frame image (np.ndarray) to perform scene
125125
detection on. Can be None *only* if the self.is_processing_required() method
126126
(inhereted from the base SceneDetector class) returns True.
127127

scenedetect/video_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from logging import getLogger
2525

2626
from typing import Iterable, List, Optional, Tuple, Union
27-
from numpy import ndarray
27+
import numpy as np
2828
import cv2
2929

3030
from scenedetect.platform import get_file_name
@@ -630,14 +630,14 @@ def grab(self) -> bool:
630630
self._correct_frame_length()
631631
return grabbed
632632

633-
def retrieve(self) -> Tuple[bool, Optional[ndarray]]:
633+
def retrieve(self) -> Tuple[bool, Optional[np.ndarray]]:
634634
""" Retrieve (cv2.VideoCapture method) - retrieves and returns a frame.
635635
636636
Frame returned corresponds to last call to :meth:`grab()`.
637637
638638
Returns:
639639
Tuple of (True, frame_image) if a frame was grabbed during the last call to grab(),
640-
and where frame_image is a numpy ndarray of the decoded frame. Otherwise (False, None).
640+
and where frame_image is a numpy np.ndarray of the decoded frame. Otherwise (False, None).
641641
"""
642642
if not self._started:
643643
self.start()
@@ -653,7 +653,7 @@ def retrieve(self) -> Tuple[bool, Optional[ndarray]]:
653653
self._last_frame = None
654654
return (retrieved, self._last_frame)
655655

656-
def read(self, decode: bool = True, advance: bool = True) -> Union[ndarray, bool]:
656+
def read(self, decode: bool = True, advance: bool = True) -> Union[np.ndarray, bool]:
657657
""" Return next frame (or current if advance = False), or False if end of video.
658658
659659
Arguments:

scenedetect/video_stream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from logging import getLogger
3737
from typing import Tuple, Optional, Union
3838

39-
from numpy import ndarray
39+
import numpy as np
4040

4141
from scenedetect.frame_timecode import FrameTimecode
4242

@@ -178,15 +178,15 @@ def frame_number(self) -> int:
178178
#
179179

180180
@abstractmethod
181-
def read(self, decode: bool = True, advance: bool = True) -> Union[ndarray, bool]:
182-
"""Read and decode the next frame as a numpy.ndarray. Returns False when video ends.
181+
def read(self, decode: bool = True, advance: bool = True) -> Union[np.ndarray, bool]:
182+
"""Read and decode the next frame as a np.ndarray. Returns False when video ends.
183183
184184
Arguments:
185185
decode: Decode and return the frame.
186186
advance: Seek to the next frame. If False, will return the current (last) frame.
187187
188188
Returns:
189-
If decode = True, the decoded frame (numpy.ndarray), or False (bool) if end of video.
189+
If decode = True, the decoded frame (np.ndarray), or False (bool) if end of video.
190190
If decode = False, a bool indicating if advancing to the the next frame succeeded.
191191
"""
192192
raise NotImplementedError

website/pages/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Releases
1313
**API Changes:**
1414

1515
- [bugfix] Fix `AttributeError` thrown when accessing `aspect_ratio` on certain videos using `VideoStreamAv` [#355](https://github.com/Breakthrough/PySceneDetect/issues/355)
16+
- [bugfix] Fix circular imports due to partially initialized module for some development environments [#350](https://github.com/Breakthrough/PySceneDetect/issues/350)
1617

1718

1819
### 0.6.2 (July 23, 2023)

0 commit comments

Comments
 (0)