Skip to content

Commit 406f8e9

Browse files
author
Ruben Cronie
committedApr 2, 2023
Remove vidutil dependency
1 parent 7c4cd43 commit 406f8e9

File tree

7 files changed

+1107
-62
lines changed

7 files changed

+1107
-62
lines changed
 

‎.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fail_fast: false
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.0.1
7+
rev: v4.4.0
88
hooks:
99
- id: mixed-line-ending
1010
args:
@@ -24,7 +24,7 @@ repos:
2424
args: ["--remove"]
2525

2626
- repo: https://github.com/pycqa/isort
27-
rev: 5.9.3
27+
rev: 5.12.0
2828
hooks:
2929
- id: isort
3030
name: isort (python)
@@ -38,7 +38,7 @@ repos:
3838
types: [ pyi ]
3939

4040
- repo: https://github.com/psf/black
41-
rev: 21.7b0
41+
rev: 23.3.0
4242
hooks:
4343
- id: black
4444
language_version: python3.9

‎.python-version

-1
This file was deleted.

‎poetry.lock

+1,035
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml

+30
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,33 @@ include_trailing_comma = true
2626
lines_after_imports = 2
2727
known_first_party = []
2828
known_third_party = []
29+
30+
[tool.poetry]
31+
name = "project-util"
32+
version = "0.1.0"
33+
description = ""
34+
authors = ["Ruben Cronie <rubencronie@gmail.com>"]
35+
readme = "README.md"
36+
packages = [{include = "src"}]
37+
38+
[tool.poetry.dependencies]
39+
python = "^3.9"
40+
numpy = "^1.22.4"
41+
opencv-contrib-python = "4.5.5.64"
42+
pillow = "9.1.1"
43+
loguru = "^0.6.0"
44+
boto3 = "^1.26.104"
45+
python-dotenv = "^1.0.0"
46+
fastapi-utils = "^0.2.1"
47+
48+
49+
[tool.poetry.group.dev.dependencies]
50+
black = "^23.3.0"
51+
isort = "^5.12.0"
52+
pre-commit = "^3.2.1"
53+
pyfakefs = "^5.2.0"
54+
pytest = "^7.2.2"
55+
56+
[build-system]
57+
requires = ["poetry-core"]
58+
build-backend = "poetry.core.masonry.api"

‎setup.py

-23
This file was deleted.

‎src/project_util/image_utils.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
from os.path import abspath, isdir, isfile, join
3+
from pathlib import Path
4+
from typing import List, Union
5+
6+
import cv2
7+
from numpy import ndarray
8+
9+
10+
def list_images(path: Union[str, Path], extensions=None) -> List[Path]:
11+
if not extensions:
12+
extensions = [".png", ".jpg", ".jpeg", ".tif", ".tiff"]
13+
if not isdir(path):
14+
raise ValueError(f"{path} is not a directory")
15+
paths = sorted(
16+
[
17+
abspath(join(path, f))
18+
for f in os.listdir(path)
19+
if not f.startswith(".")
20+
and isfile(join(path, f))
21+
and Path(f).suffix in extensions
22+
],
23+
key=str.lower,
24+
)
25+
return [Path(p) for p in paths]
26+
27+
28+
def load_images(paths: List[Union[str, Path]]) -> List[ndarray]:
29+
frames = []
30+
for p in paths:
31+
if isinstance(p, Path):
32+
frames.append(cv2.imread(p.as_posix()))
33+
else:
34+
frames.append(cv2.imread(p))
35+
36+
return frames

‎src/project_util/project/project.py

+3-35
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import numpy as np
99
from loguru import logger
1010
from PIL import Image
11-
from vidutil.encoder import VideoEncoder
1211

1312
from project_util.blueprint.blueprint import Blueprint
1413
from project_util.constants import FILE_SYSTEM, S3
14+
from project_util.image_utils import list_images, load_images
1515
from project_util.services.s3 import S3Client
1616

1717

@@ -88,10 +88,10 @@ def get_file_names(self):
8888

8989
def load_images(self) -> List[np.ndarray]:
9090
# Candidate for moving to an image-specific project lib
91-
paths = VideoEncoder.list_images(self.path)
91+
paths = list_images(self.path)
9292
logger.debug(f"Project path: {self.path}")
9393
logger.debug(f"Loading image paths: {paths}")
94-
return VideoEncoder.load_images(paths)
94+
return load_images(paths)
9595

9696
def _require_backend(self, backend):
9797
if self._backend != backend:
@@ -206,38 +206,6 @@ def _save_blueprint_to_s3(self, bucket, path):
206206
path=path,
207207
)
208208

209-
def export_frames_as_video(
210-
self,
211-
name: str,
212-
target_project: TProject = None,
213-
fps: int = 24,
214-
codec: Union[str, int] = "mp4v",
215-
) -> None:
216-
"""
217-
Exports images in current folder as a video file. You can add .mp4 as an
218-
extension in the name param.
219-
:param codec: fourcc code
220-
:param name: file name to export
221-
:return:
222-
"""
223-
# Candidate for moving to a video-specific project lib
224-
self._require_backend(FILE_SYSTEM)
225-
self.ensure_project_dir()
226-
if target_project:
227-
target_path = target_project.path
228-
else:
229-
target_path = self.path
230-
231-
frames = self.load_images()
232-
if frames:
233-
logger.debug(f"Video shape: {frames[0].shape[1::-1]}")
234-
VideoEncoder.save(
235-
path=join(target_path, name),
236-
frames=frames,
237-
fps=fps,
238-
codec=codec,
239-
)
240-
241209
def ensure_project_dir(self):
242210
if not self._project_dir.exists():
243211
self._make_project_dir()

0 commit comments

Comments
 (0)
Please sign in to comment.