Skip to content

Commit

Permalink
Merge pull request #47 from RichieHakim/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
RichieHakim authored Jan 30, 2024
2 parents 76d752a + d2d5bb7 commit 1d62bd2
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Change the following files in GitHub language stats
### '*.filesuffix linguist-vendored': ignored
### '*.filesuffix linguist-detectable': detected as the language
### '*.filesuffix linguist-language=Python': forced to be Python
*.ipynb linguist-vendored
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
# "3.12",
]
extra: [
all,
all_latest,
all_cv2Headless,
all_latest_cv2Headless,
]
install-level: [
system,
Expand Down
45 changes: 44 additions & 1 deletion face_rhythm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,50 @@

import torch ## For some reason, it crashes if I don't import torch before other packages... RH 20221128


## Prepare cv2.imshow
import pkg_resources
installed_packages = {pkg.key for pkg in pkg_resources.working_set}
has_cv2_headless = 'opencv-contrib-python-headless' in installed_packages
has_cv2_normal = 'opencv-contrib-python' in installed_packages
if has_cv2_normal and not has_cv2_headless:
run_cv2_imshow = True
elif has_cv2_headless and not has_cv2_normal:
run_cv2_imshow = False
elif has_cv2_headless and has_cv2_normal:
raise ValueError("Both opencv-contrib-python and opencv-contrib-python-headless are installed. Please uninstall one of them.")
elif not has_cv2_headless and not has_cv2_normal:
run_cv2_imshow = False
import warnings
warnings.warn("Neither opencv-contrib-python nor opencv-contrib-python-headless are installed. Please install one of them to use cv2.imshow().")
else:
raise ValueError("This should never happen. Please report this error to the developer.")

if run_cv2_imshow:
def prepare_cv2_imshow():
"""
This function is necessary because cv2.imshow()
can crash the kernel if called after importing
av and decord.
RH 2022
"""
import numpy as np
import cv2
test = np.zeros((1,300,400,3))
for frame in test:
cv2.putText(frame, "WELCOME TO FACE RHYTHM!", (10,50), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255), 2)
cv2.putText(frame, "Prepping CV2", (10,100), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,255,255), 2)
cv2.putText(frame, "Calling this figure allows cv2.imshow ", (10,150), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 1)
cv2.putText(frame, "to work without crashing if this function", (10,170), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 1)
cv2.putText(frame, "is called before importing av and decord", (10,190), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 1)
cv2.imshow('startup', frame)
cv2.waitKey(1000)
cv2.destroyWindow('startup')
prepare_cv2_imshow()


for pkg in __all__:
exec('from . import ' + pkg)

__version__ = '0.2.1'

__version__ = '0.2.2'
4 changes: 0 additions & 4 deletions face_rhythm/decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

import numpy as np
from tqdm import tqdm
import decord
import cv2
import torch
import scipy.sparse
import tensorly as tl
import tensorly.decomposition
import einops

from . import util
Expand Down
7 changes: 6 additions & 1 deletion face_rhythm/point_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,12 @@ def __init__(
self._violation_event = False

## Prepare a playback visualizer
self._handle_cv2Imshow = "PointTracker"
if self._visualize_video:
print("FR: Preparing playback visualizer") if self._verbose > 1 else None
self.visualizer = FrameVisualizer(
display=True,
handle_cv2Imshow='point_tracking',
handle_cv2Imshow=self._handle_cv2Imshow,
path_save=None,
frame_height_width=self.buffered_video_reader.frame_height_width,
error_checking=False,
Expand Down Expand Up @@ -345,6 +346,10 @@ def track_points(self):
self.points_tracked.append(points)
self.violations.append(self.violations_currentVideo.tocoo())

## Destroy the cv2.imshow window
if self._visualize_video:
cv2.destroyWindow(self._handle_cv2Imshow)

print(f"FR: Tracking complete") if self._verbose > 1 else None
print(f"FR: Placing points_tracked into dictionary self.points_tracked where keys are video indices") if self._verbose > 1 else None
self.points_tracked = {f"{ii}": points for ii, points in enumerate(self.points_tracked)}
Expand Down
5 changes: 3 additions & 2 deletions face_rhythm/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def prepare_project(
path to the project directory
"""
## initialize cv2.imshow
print('Initializing cv2.imshow') if verbose > 1 else None
helpers.prepare_cv2_imshow() if initialize_visualization else None
if initialize_visualization:
print('Initializing cv2.imshow') if verbose > 1 else None
helpers.prepare_cv2_imshow()

def _create_config_file():
"""
Expand Down
2 changes: 1 addition & 1 deletion face_rhythm/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def visualize_image_with_points(
def close(self):
if self.video_writer is not None:
self.video_writer.release()
cv2.destroyAllWindows()
cv2.destroyWindow(self.handle_cv2Imshow)

def __call__(self, *args, **kwds):
"""
Expand Down
18 changes: 16 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def read_requirements():
### remove everything starting and after the first =,>,<,! sign
deps_names = [req.split('=')[0].split('>')[0].split('<')[0].split('!')[0] for req in deps_all]
deps_all_dict = dict(zip(deps_names, deps_all))

deps_all_latest = dict(zip(deps_names, deps_names))


Expand Down Expand Up @@ -74,6 +73,13 @@ def read_requirements():
]]


## Make versions with cv2 headless (for servers)
deps_all_dict_cv2Headless = copy.deepcopy(deps_all_dict)
deps_all_dict_cv2Headless['opencv-contrib-python'] = 'opencv-contrib-python-headless' + deps_all_dict_cv2Headless['opencv-contrib-python'][21:]
deps_all_latest_cv2Headless = copy.deepcopy(deps_all_latest)
deps_all_latest_cv2Headless['opencv-contrib-python'] = 'opencv-contrib-python-headless'


## Get README.md
with open(str(dir_parent / "README.md"), "r") as f:
readme = f.read()
Expand Down Expand Up @@ -129,7 +135,15 @@ def read_requirements():
# packages=setuptools.find_packages(),
packages=['face_rhythm'],

install_requires=[deps_core,],
install_requires=[],

extras_require={
'all': list(deps_all_dict.values()),
'all_latest': list(deps_all_latest.values()),
'all_cv2Headless': list(deps_all_dict_cv2Headless.values()),
'all_latest_cv2Headless': list(deps_all_latest_cv2Headless.values()),
'core': deps_core,
},

include_package_data=True,
)

0 comments on commit 1d62bd2

Please sign in to comment.