예제 #1
0
파일: capture.py 프로젝트: harto/sauron
 def diffs(self, other):
     diff = cv2.absdiff(self.processed, other.processed)
     _, diff = cv2.threshold(diff, int(config.get("MIN_CHANGE_THRESHOLD")), 255, cv2.THRESH_BINARY)
     # dilate to join broken contours
     diff = cv2.dilate(diff, None, iterations=2)
     (_, contours, _) = cv2.findContours(diff, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
     return [cv2.boundingRect(c) for c in contours if cv2.contourArea(c) >= int(config.get("MIN_CHANGE_AREA"))]
예제 #2
0
파일: capture.py 프로젝트: harto/sauron
def process(image):
    # Discard colour information; irrelevant to motion detection
    processed = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    # Remove noise
    blur_kernel = (int(config.get("BLUR_KERNEL_WIDTH")), int(config.get("BLUR_KERNEL_HEIGHT")))
    processed = cv2.GaussianBlur(processed, blur_kernel, 0)
    return processed
예제 #3
0
파일: recording.py 프로젝트: harto/sauron
 def finalise(self, name):
     print 'finalising recording'
     input_paths = sorted(glob(path.join(self.output_dir, '*')))
     output_path = path.join(tempfile.gettempdir(), name + '.gif')
     args = ['convert',
             '-delay', str(int(100.0 / int(config.get('OUTPUT_FPS')))),
             '-loop', '0']
     args += input_paths
     args += [output_path]
     exit_status = subprocess.call(args)
     if exit_status == 0:
         print 'wrote %s' % output_path
         shutil.rmtree(self.output_dir)
         return output_path
     else:
         print 'error writing %s' % output_path
예제 #4
0
파일: recording.py 프로젝트: harto/sauron
 def exceeds_max_duration(self, frame):
     return self.first_write_time and \
         frame.time - self.first_write_time > int(config.get('MAX_RECORDING_SECONDS'))
예제 #5
0
파일: recording.py 프로젝트: harto/sauron
 def exceeds_max_fps(self, frame):
     return self.last_write_time and \
         frame.time - self.last_write_time < 1.0 / int(config.get('OUTPUT_FPS'))
예제 #6
0
파일: capture.py 프로젝트: harto/sauron
def downscale(image):
    orig_h, orig_w = image.shape[:2]
    width = int(config.get("FRAME_WIDTH"))
    ratio = width / float(orig_w)
    height = int(orig_h * ratio)
    return cv2.resize(image, (width, height), interpolation=cv2.INTER_AREA)