mmif-python 1.0.5__tar.gz → 1.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {mmif-python-1.0.5/mmif_python.egg-info → mmif-python-1.0.7}/PKG-INFO +1 -1
  2. mmif-python-1.0.7/VERSION +1 -0
  3. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/utils/video_document_helper.py +29 -15
  4. mmif-python-1.0.7/mmif/ver/__init__.py +2 -0
  5. {mmif-python-1.0.5 → mmif-python-1.0.7/mmif_python.egg-info}/PKG-INFO +1 -1
  6. mmif-python-1.0.5/VERSION +0 -1
  7. mmif-python-1.0.5/mmif/ver/__init__.py +0 -2
  8. {mmif-python-1.0.5 → mmif-python-1.0.7}/LICENSE +0 -0
  9. {mmif-python-1.0.5 → mmif-python-1.0.7}/MANIFEST.in +0 -0
  10. {mmif-python-1.0.5 → mmif-python-1.0.7}/README.md +0 -0
  11. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/__init__.py +0 -0
  12. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/res/__init__.py +0 -0
  13. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/res/clams.vocabulary.yaml +0 -0
  14. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/res/do-not-edit.txt +0 -0
  15. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/res/mmif.json +0 -0
  16. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/serialize/__init__.py +0 -0
  17. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/serialize/annotation.py +0 -0
  18. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/serialize/mmif.py +0 -0
  19. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/serialize/model.py +0 -0
  20. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/serialize/view.py +0 -0
  21. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/utils/__init__.py +0 -0
  22. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/ver/do-not-edit.txt +0 -0
  23. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/vocabulary/__init__.py +0 -0
  24. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/vocabulary/annotation_types.py +0 -0
  25. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/vocabulary/base_types.py +0 -0
  26. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/vocabulary/do-not-edit.txt +0 -0
  27. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif/vocabulary/document_types.py +0 -0
  28. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif_python.egg-info/SOURCES.txt +0 -0
  29. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif_python.egg-info/dependency_links.txt +0 -0
  30. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif_python.egg-info/requires.txt +0 -0
  31. {mmif-python-1.0.5 → mmif-python-1.0.7}/mmif_python.egg-info/top_level.txt +0 -0
  32. {mmif-python-1.0.5 → mmif-python-1.0.7}/requirements.cv +0 -0
  33. {mmif-python-1.0.5 → mmif-python-1.0.7}/requirements.txt +0 -0
  34. {mmif-python-1.0.5 → mmif-python-1.0.7}/setup.cfg +0 -0
  35. {mmif-python-1.0.5 → mmif-python-1.0.7}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mmif-python
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: Python implementation of MultiMedia Interchange Format specification. (https://mmif.clams.ai)
5
5
  Home-page: https://mmif.clams.ai
6
6
  Author: Brandeis Lab for Linguistics and Computation
@@ -0,0 +1 @@
1
+ 1.0.7
@@ -1,20 +1,24 @@
1
+ import importlib
2
+ import warnings
1
3
  from typing import List, Union, Tuple
2
4
 
3
- import numpy as np
4
- from PIL import Image
5
-
5
+ import mmif
6
6
  from mmif import Annotation, Document, Mmif
7
7
  from mmif.vocabulary import DocumentTypes
8
8
 
9
- try:
10
- import cv2
11
- import ffmpeg
12
- import PIL
13
- except ImportError as e:
14
- raise ImportError(
15
- f"Optional package {e.name} not found. You might want to install Computer-Vision dependencies by running `pip install mmif-python[cv]`")
9
+ for cv_dep in ('cv2', 'ffmpeg', 'PIL'):
10
+ try:
11
+ importlib.__import__(cv_dep)
12
+ except ImportError as e:
13
+ warnings.warn(f"Optional package \"{e.name}\" is not found. "
14
+ f"You might want to install Computer-Vision dependencies "
15
+ f"by running `pip install mmif-python[cv]=={mmif.__version__}`")
16
+
16
17
 
17
18
  FPS_DOCPROP_KEY = 'fps'
19
+ DURATION_DOCPROP_KEY = 'duration'
20
+ DURATIONUNIT_DOCPROP_KEY = 'durationTimeUnit'
21
+
18
22
  UNIT_NORMALIZATION = {
19
23
  'm': 'millisecond',
20
24
  'ms': 'millisecond',
@@ -33,12 +37,15 @@ UNIT_NORMALIZATION = {
33
37
  }
34
38
 
35
39
 
36
- def capture(vd: Document) -> cv2.VideoCapture:
40
+ def capture(vd: Document):
41
+ import cv2 # pytype: disable=import-error
37
42
  if vd is None or vd.at_type != DocumentTypes.VideoDocument:
38
43
  raise ValueError(f'The document does not exist.')
39
44
 
40
45
  v = cv2.VideoCapture(vd.location_path())
41
46
  vd.add_property(FPS_DOCPROP_KEY, v.get(cv2.CAP_PROP_FPS))
47
+ vd.add_property(DURATION_DOCPROP_KEY, v.get(cv2.CAP_PROP_FRAME_COUNT))
48
+ vd.add_property(DURATIONUNIT_DOCPROP_KEY, 'frames')
42
49
  return v
43
50
 
44
51
 
@@ -55,7 +62,7 @@ def get_framerate(vd: Document) -> float:
55
62
  return vd.get_property(FPS_DOCPROP_KEY)
56
63
 
57
64
 
58
- def extract_frames_as_images(vd: Document, framenums: List[int], as_PIL: bool = False) -> List[Union[np.ndarray, PIL.Image.Image]]:
65
+ def extract_frames_as_images(vd: Document, framenums: List[int], as_PIL: bool = False):
59
66
  """
60
67
  Extracts frames from a video document as a list of numpy arrays.
61
68
  Use `sample_frames` function in this module to get the list of frame numbers first.
@@ -65,6 +72,9 @@ def extract_frames_as_images(vd: Document, framenums: List[int], as_PIL: bool =
65
72
  :param as_PIL: use PIL.Image instead of numpy.ndarray
66
73
  :return: frames as a list of numpy arrays or PIL.Image objects
67
74
  """
75
+ import cv2 # pytype: disable=import-error
76
+ if as_PIL:
77
+ from PIL import Image
68
78
  frames = []
69
79
  video = capture(vd)
70
80
  for framenum in framenums:
@@ -77,15 +87,19 @@ def extract_frames_as_images(vd: Document, framenums: List[int], as_PIL: bool =
77
87
  return frames
78
88
 
79
89
 
80
- def extract_mid_frame(mmif: Mmif, tf: Annotation, as_PIL: bool = False) -> Union[np.ndarray, PIL.Image.Image]:
90
+ def get_mid_framenum(mmif: Mmif, tf: Annotation):
81
91
  """
82
92
  Extracts the middle frame from a video document
83
93
  """
84
94
  timeunit = get_annotation_property(mmif, tf, 'timeUnit')
85
95
  vd = mmif[get_annotation_property(mmif, tf, 'document')]
86
96
  fps = get_framerate(vd)
87
- midframe = sum(convert(float(tf.get_property(timepoint_propkey)), timeunit, 'frame', fps) for timepoint_propkey in ('start', 'end')) // 2
88
- return extract_frames_as_images(vd, [midframe], as_PIL=as_PIL)[0]
97
+ return sum(convert(float(tf.get_property(timepoint_propkey)), timeunit, 'frame', fps) for timepoint_propkey in ('start', 'end')) // 2
98
+
99
+
100
+ def extract_mid_frame(mmif: Mmif, tf: Annotation, as_PIL: bool = False):
101
+ vd = mmif[get_annotation_property(mmif, tf, 'document')]
102
+ return extract_frames_as_images(vd, [get_mid_framenum(mmif, tf)], as_PIL=as_PIL)[0]
89
103
 
90
104
 
91
105
  def sample_frames(start_frame: int, end_frame: int, sample_ratio: int = 1) -> List[int]:
@@ -0,0 +1,2 @@
1
+ __version__ = "1.0.7"
2
+ __specver__ = "1.0.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mmif-python
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: Python implementation of MultiMedia Interchange Format specification. (https://mmif.clams.ai)
5
5
  Home-page: https://mmif.clams.ai
6
6
  Author: Brandeis Lab for Linguistics and Computation
mmif-python-1.0.5/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.5
@@ -1,2 +0,0 @@
1
- __version__ = "1.0.5"
2
- __specver__ = "1.0.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes