def modify_frame(self, frame, vflip=None, hflip=None, gray=False, swap_rb=None, clone=False, croprect=None, size=None): if frame is not None: def _get_param(param, p): if param is None: return getattr(self, p) else: return param swap_rb = _get_param(swap_rb, 'swap_rb') vflip = _get_param(vflip, 'vflip') hflip = _get_param(hflip, 'hflip') if clone: frame = frame.clone() if swap_rb: frame = cv_swap_rb(frame) if gray: frame = grayspace(frame) if croprect: if len(croprect) == 2: # assume w, h w, h = get_size(frame) croprect = (w - croprect[0]) / 2, ( h - croprect[1]) / 2, croprect[0], croprect[1] else: pass rs = croprect[0] re = croprect[0] + croprect[2] cs = croprect[1] ce = croprect[1] + croprect[3] frame = asMat(frame.ndarray[cs:ce, rs:re]) if size: frame = resize(frame, *size) if not globalv.video_test: if vflip: if hflip: cv_flip(frame, -1) else: cv_flip(frame, 0) elif hflip: cv_flip(frame, 1) return frame
def _draw_crosshairs(self, src): r = 10 w, h = map(int, get_size(src)) pts = [[(w / 2, 0), (w / 2, h / 2 - r)], [(w / 2, h / 2 + r), (w / 2, h)], [(0, h / 2), (w / 2 - r, h / 2)], [(w / 2 + r, h / 2), (w, h / 2)], ] draw_lines(src, pts, color=(0, 255, 255), thickness=1)
def modify_frame(self, frame, vflip=None, hflip=None , gray=False, swap_rb=None, clone=False, croprect=None, size=None): # print size # size = (100, 100) if frame is not None: def _get_param(param, p): if param is None: return getattr(self, p) else: # setattr(self, p, param) return param swap_rb = _get_param(swap_rb, 'swap_rb') vflip = _get_param(vflip, 'vflip') hflip = _get_param(hflip, 'hflip') if clone: frame = frame.clone() if swap_rb: frame = cv_swap_rb(frame) if gray: frame = grayspace(frame) if croprect: if len(croprect) == 2: # assume w, h w, h = get_size(frame) croprect = (w - croprect[0]) / 2, (h - croprect[1]) / 2, croprect[0], croprect[1] else: pass rs = croprect[0] re = croprect[0] + croprect[2] cs = croprect[1] ce = croprect[1] + croprect[3] frame = asMat(frame.ndarray[cs:ce, rs:re]) if size: frame = resize(frame, *size) if not globalv.video_test: if vflip: if hflip: cv_flip(frame, -1) else: cv_flip(frame, 0) elif hflip: cv_flip(frame, 1) return frame