Commit 760e0c54 authored by Yuxin Wu's avatar Yuxin Wu

python-prctl dependency; imshow update

parent 7bcde8ad
...@@ -7,3 +7,4 @@ pyarrow>=0.9.0 ...@@ -7,3 +7,4 @@ pyarrow>=0.9.0
pyzmq>=16 pyzmq>=16
subprocess32; python_version < '3.0' subprocess32; python_version < '3.0'
functools32; python_version < '3.0' functools32; python_version < '3.0'
python-prctl; platform_system == 'Linux'
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# File: concurrency.py # File: concurrency.py
# Credit belongs to Xinyu Zhou # Some code taken from zxytim
import os
import threading import threading
import multiprocessing import multiprocessing
import atexit import atexit
...@@ -177,13 +178,15 @@ def enable_death_signal(): ...@@ -177,13 +178,15 @@ def enable_death_signal():
the current process will be cleaned with guarantee the current process will be cleaned with guarantee
in case the parent dies accidentally. in case the parent dies accidentally.
""" """
if os.name != 'posix':
return
try: try:
import prctl # pip install prctl-python import prctl # pip install python-prctl
except ImportError: except ImportError:
return return
else: else:
assert hasattr(prctl, 'set_pdeathsig'), \ assert hasattr(prctl, 'set_pdeathsig'), \
"prctl.set_pdeathsig does not exist! Note that you need to install 'prctl-python' instead of 'prctl'." "prctl.set_pdeathsig does not exist! Note that you need to install 'python-prctl' instead of 'prctl'."
# is SIGHUP a good choice? # is SIGHUP a good choice?
prctl.set_pdeathsig(signal.SIGHUP) prctl.set_pdeathsig(signal.SIGHUP)
......
...@@ -105,10 +105,15 @@ class FloatBox(BoxBase): ...@@ -105,10 +105,15 @@ class FloatBox(BoxBase):
intbox.x2 + 1, intbox.y2 + 1) intbox.x2 + 1, intbox.y2 + 1)
def clip_by_shape(self, shape): def clip_by_shape(self, shape):
"""
Args:
shape: h, w
"""
self.x1 = np.clip(self.x1, 0, shape[1]) self.x1 = np.clip(self.x1, 0, shape[1])
self.x2 = np.clip(self.x2, 0, shape[1]) self.x2 = np.clip(self.x2, 0, shape[1])
self.y1 = np.clip(self.y1, 0, shape[0]) self.y1 = np.clip(self.y1, 0, shape[0])
self.y2 = np.clip(self.y2, 0, shape[0]) self.y2 = np.clip(self.y2, 0, shape[0])
return self
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -58,7 +58,10 @@ def interactive_imshow(img, lclick_cb=None, rclick_cb=None, **kwargs): ...@@ -58,7 +58,10 @@ def interactive_imshow(img, lclick_cb=None, rclick_cb=None, **kwargs):
elif event == cv2.EVENT_RBUTTONUP and rclick_cb is not None: elif event == cv2.EVENT_RBUTTONUP and rclick_cb is not None:
rclick_cb(img, x, y) rclick_cb(img, x, y)
cv2.setMouseCallback(name, mouse_cb) cv2.setMouseCallback(name, mouse_cb)
key = chr(cv2.waitKey(-1) & 0xff) key = cv2.waitKey(-1)
while key >= 128:
key = cv2.waitKey(-1)
key = chr(key & 0xff)
cb_name = 'key_cb_' + key cb_name = 'key_cb_' + key
if cb_name in kwargs: if cb_name in kwargs:
kwargs[cb_name](img) kwargs[cb_name](img)
...@@ -68,6 +71,12 @@ def interactive_imshow(img, lclick_cb=None, rclick_cb=None, **kwargs): ...@@ -68,6 +71,12 @@ def interactive_imshow(img, lclick_cb=None, rclick_cb=None, **kwargs):
sys.exit() sys.exit()
elif key == 's': elif key == 's':
cv2.imwrite('out.png', img) cv2.imwrite('out.png', img)
elif key in ['+', '=']:
img = cv2.resize(img, None, fx=1.3, fy=1.3, interpolation=cv2.INTER_CUBIC)
interactive_imshow(img, lclick_cb, rclick_cb, **kwargs)
elif key == '-':
img = cv2.resize(img, None, fx=0.7, fy=0.7, interpolation=cv2.INTER_CUBIC)
interactive_imshow(img, lclick_cb, rclick_cb, **kwargs)
def _preprocess_patch_list(plist): def _preprocess_patch_list(plist):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment