Skip to content

Commit 4cc8174

Browse files
committed
2 parents 5796904 + aabeca3 commit 4cc8174

File tree

8 files changed

+39
-28
lines changed

8 files changed

+39
-28
lines changed

.vscode/settings.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2-
"python.pythonPath": "~/miniconda3/bin/python",
3-
"python.formatting.provider": "yapf"
4-
}
2+
"python.formatting.provider": "yapf",
3+
"python.linting.pylintPath": "~/miniconda3/bin/pylint",
4+
"python.linting.pylintEnabled": true
5+
}

install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rm -rf venv_sa_conv
1111
python${PYTHON_VER} -m venv venv_sa_conv
1212
source venv_sa_conv/bin/activate
1313

14+
pip install shapely
1415
pip install -e .
1516
# pip install --pre superannotate
1617
# pip install superannotate

superannotate/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@
2222
from .consensus_benchmark.benchmark import benchmark
2323
from .consensus_benchmark.consensus import consensus
2424
except:
25-
pass
25+
26+
def benchmark(*args, **kwargs):
27+
raise RuntimeError(
28+
"To use superannotate.benchmark or superannotate.consensus functions please install shapely package with # conda install shapely or # pip install shapely"
29+
)
30+
31+
def consensus(*args, **kwargs):
32+
raise RuntimeError(
33+
"To use superannotate.benchmark or superannotate.consensus functions please install shapely package with # conda install shapely or # pip install shapely"
34+
)
35+
2636

2737
from .dataframe_filtering import (
2838
filter_annotation_instances, filter_images_by_comments,

superannotate/db/projects.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,43 +249,44 @@ def upload_video_to_project(
249249
rot
250250
)
251251
except Exception as e:
252-
logger.warning("Couldn't read video metadata. %s", e)
252+
logger.warning("Couldn't read video metadata %s", e)
253253

254254
video = cv2.VideoCapture(str(video_path), cv2.CAP_FFMPEG)
255255
if not video.isOpened():
256256
raise SABaseException(0, "Couldn't open video file " + str(video_path))
257257

258258
total_num_of_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
259259
if total_num_of_frames < 0:
260-
if target_fps is not None:
261-
logger.warning(
262-
"Number of frames indicated in the video is negative number. Disabling FPS change."
263-
)
264-
target_fps = None
265-
else:
266-
logger.info("Video frame count is %s.", total_num_of_frames)
260+
total_num_of_frames = 0
261+
flag = True
262+
while flag:
263+
flag, frame = video.read()
264+
if flag:
265+
total_num_of_frames += 1
266+
else:
267+
break
268+
video = cv2.VideoCapture(str(video_path), cv2.CAP_FFMPEG)
269+
logger.info("Video frame count is %s.", total_num_of_frames)
267270

268271
if target_fps is not None:
269-
video_fps = video.get(cv2.CAP_PROP_FPS)
272+
video_fps = float(video.get(cv2.CAP_PROP_FPS))
270273
logger.info(
271274
"Video frame rate is %s. Target frame rate is %s.", video_fps,
272275
target_fps
273276
)
274-
if target_fps > video_fps:
277+
if target_fps >= video_fps:
275278
target_fps = None
276279
else:
277280
r = video_fps / target_fps
278-
frames_count_to_drop = total_num_of_frames - (
279-
total_num_of_frames / r
280-
)
281-
percent_to_drop = frames_count_to_drop / total_num_of_frames
281+
percent_to_drop = 1.0 - 1.0 / r
282282
my_random = random.Random(122222)
283283

284284
zero_fill_count = len(str(total_num_of_frames))
285285
tempdir = tempfile.TemporaryDirectory()
286286

287287
video_name = Path(video_path).stem
288288
frame_no = 1
289+
logger.info("Extracting frames from video to %s.", tempdir.name)
289290
while True:
290291
success, frame = video.read()
291292
if not success:

superannotate/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.5.9"
1+
__version__ = "2.5.12"

tests/consensus_benchmark/test_benchmark.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pathlib import Path
22

3-
from superannotate.consensus_benchmark.benchmark import benchmark
3+
import superannotate as sa
44

55
test_root = Path().resolve() / 'tests'
66

@@ -15,7 +15,7 @@ def test_benchmark():
1515
]
1616
export_path = test_root / 'consensus_benchmark'
1717
for annot_type in annot_types:
18-
res_df = benchmark(
18+
res_df = sa.benchmark(
1919
gt_project_name,
2020
project_names,
2121
export_root=export_path,
@@ -39,7 +39,7 @@ def test_benchmark():
3939
]
4040

4141
#test filtering images with given image names list
42-
res_images = benchmark(
42+
res_images = sa.benchmark(
4343
gt_project_name,
4444
project_names,
4545
export_root=export_path,

tests/consensus_benchmark/test_consensus.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pathlib import Path
22

3-
from superannotate.consensus_benchmark.consensus import consensus
3+
import superannotate as sa
44

55
test_root = Path().resolve() / 'tests'
66

@@ -14,7 +14,7 @@ def test_consensus():
1414
]
1515
export_path = test_root / 'consensus_benchmark'
1616
for annot_type in annot_types:
17-
res_df = consensus(
17+
res_df = sa.consensus(
1818
project_names, export_root=export_path, annot_type=annot_type
1919
)
2020
#test content of projectName column
@@ -35,7 +35,7 @@ def test_consensus():
3535
]
3636

3737
#test filtering images with given image names list
38-
res_images = consensus(
38+
res_images = sa.consensus(
3939
project_names, export_root=export_path, image_list=image_names
4040
)
4141

tests/test_dicom.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ def test_dicom_convesion(tmpdir):
77
print("Using temp dir", tmpdir)
88
path = pydicom.data.get_testdata_file("CT_small.dcm")
99
print("Using dicom file", path)
10-
paths = sa.dicom_to_rgb_sequence(
11-
path, tmpdir
12-
)
10+
paths = sa.dicom_to_rgb_sequence(path, tmpdir)
1311
assert len(paths) == 1

0 commit comments

Comments
 (0)