Forbid interrupt when initializing
This commit is contained in:
@@ -4,7 +4,7 @@ from time import time, sleep
|
|||||||
from math import cos, pi
|
from math import cos, pi
|
||||||
|
|
||||||
from .striker import Striker
|
from .striker import Striker
|
||||||
from .utils import read_config
|
from .utils import read_config, InterruptDelayed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -59,6 +59,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
try: # Hit Ctrl-C to stop, cleanup and exit
|
try: # Hit Ctrl-C to stop, cleanup and exit
|
||||||
cfg = read_config()
|
cfg = read_config()
|
||||||
|
with InterruptDelayed():
|
||||||
striker = Striker(
|
striker = Striker(
|
||||||
nao_ip=cfg['ip'], nao_port=cfg['port'],
|
nao_ip=cfg['ip'], nao_port=cfg['port'],
|
||||||
res=cfg['res'], ball_hsv=cfg['ball'],
|
res=cfg['res'], ball_hsv=cfg['ball'],
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import cv2
|
|||||||
|
|
||||||
from .imagereaders import VideoReader, NaoImageReader, PictureReader
|
from .imagereaders import VideoReader, NaoImageReader, PictureReader
|
||||||
from .finders import GoalFinder, BallFinder, FieldFinder
|
from .finders import GoalFinder, BallFinder, FieldFinder
|
||||||
from .utils import read_config, imresize, hsv_mask
|
from .utils import read_config, imresize, hsv_mask, InterruptDelayed
|
||||||
|
|
||||||
class Colorpicker(object):
|
class Colorpicker(object):
|
||||||
|
|
||||||
@@ -203,6 +203,7 @@ if __name__ == '__main__':
|
|||||||
if args.input_config:
|
if args.input_config:
|
||||||
cp.load(args.input_config, args.target)
|
cp.load(args.input_config, args.target)
|
||||||
|
|
||||||
|
with InterruptDelayed():
|
||||||
if args.video_file:
|
if args.video_file:
|
||||||
rdr = VideoReader(args.video_file, loop=True)
|
rdr = VideoReader(args.video_file, loop=True)
|
||||||
elif args.image_file:
|
elif args.image_file:
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ from __future__ import division
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import signal
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
|
|
||||||
HERE = os.path.dirname(os.path.realpath(__file__))
|
HERE = os.path.dirname(os.path.realpath(__file__))
|
||||||
@@ -40,3 +40,18 @@ def hsv_mask(hsv, hsv_lower, hsv_upper):
|
|||||||
return cv2.add(mask_l, mask_u)
|
return cv2.add(mask_l, mask_u)
|
||||||
else:
|
else:
|
||||||
return cv2.inRange(hsv, tuple(hsv_lower), tuple(hsv_upper))
|
return cv2.inRange(hsv, tuple(hsv_lower), tuple(hsv_upper))
|
||||||
|
|
||||||
|
class InterruptDelayed(object):
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.signal_received = False
|
||||||
|
self.old_handler = signal.signal(signal.SIGINT, self.handler)
|
||||||
|
|
||||||
|
def handler(self, sig, frame):
|
||||||
|
self.signal_received = (sig, frame)
|
||||||
|
print('SIGINT received. Delaying KeyboardInterrupt.')
|
||||||
|
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
signal.signal(signal.SIGINT, self.old_handler)
|
||||||
|
if self.signal_received:
|
||||||
|
self.old_handler(*self.signal_received)
|
||||||
|
|||||||
Reference in New Issue
Block a user