def search_for_command_codes(host, port, frequencies, crop_box=None, bit_depth=None): """Iterates through commands and looks for changes in the webcam.""" diffs = deque() pictures = deque() base = normalize(get_picture(crop_box=crop_box), bit_depth=bit_depth) base.save('normalized-test.png') time.sleep(1) print('Filling base photos for difference analysis') for _ in range(20): recent = normalize(get_picture(crop_box=crop_box), bit_depth=bit_depth) diff = percent_difference(base, recent) time.sleep(1) diffs.append(diff) pictures.append(recent) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) print('Searching for command codes on {frequencies}'.format( frequencies=', '.join((str(f) for f in frequencies)))) for frequency in frequencies: for command_tuple in command_iterator(frequency): # pylint: disable=star-args command = format_command(*command_tuple) if sys.version_info.major == 3: command = bytes(command, 'utf-8') sock.sendto(command, (host, port)) time.sleep(1) recent = normalize(get_picture(crop_box=crop_box), bit_depth=bit_depth) # Let's compare the most recent photo to the oldest one, in case a # cloud passes over and the brightness changes diff = percent_difference(pictures[0], recent) std_dev = standard_deviation(diffs) mean_ = mean(diffs) # I should be doing a z-test or something here... eh if abs(diff - mean_) > (std_dev * 3.0) and diff > 2.0: print('Found substantially different photo, saving...') print('diff={diff}, mean={mean}, std dev={std_dev}' ' at {time}'.format(diff=diff, mean=mean_, std_dev=std_dev, time=str(datetime.datetime.now()))) file_name = '-'.join(str(i) for i in command_tuple) os.rename('photo.png', file_name + '.png') time.sleep(2) diffs.popleft() diffs.append(diff) pictures.popleft() pictures.append(recent)
def send_signal_repeats_full(host, port, command_array): """Reads signal repeat bursts and sends commands to the Raspberry Pi.""" sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # pylint: disable=star-args command = format_command(*command_array) if sys.version_info.major == 3: command = bytes(command, 'utf-8') sock.sendto(command, (host, port))
def send_signal_repeats(host, port, command_array): """Reads signal repeat bursts and sends commands to the Raspberry Pi.""" sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) read_int = input_function(int) while True: try: command_array[4] = read_int('Signal repeats? ') except ValueError: pass # pylint: disable=star-args command = format_command(*command_array) if sys.version_info.major == 3: command = bytes(command, 'utf-8') sock.sendto(command, (host, port))
def search_for_command_codes(host, port, frequencies, get_picture_function=None, bit_depth=None): """Iterates through commands and looks for changes in the webcam.""" if get_picture_function is not None: diffs = deque() pictures = deque() base = normalize(get_picture_function(), bit_depth=bit_depth) try: base.save('normalized-test.png') except Exception: pass time.sleep(1) print('Filling base photos for difference analysis') for _ in range(20): recent = normalize(get_picture_function(), bit_depth=bit_depth) diff = percent_difference(base, recent) time.sleep(1) diffs.append(diff) pictures.append(recent) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) print('Searching for command codes on {frequencies}'.format( frequencies=', '.join((str(f) for f in frequencies)))) command_tuple_description = ('freq', 'useconds', 'multiplier', 'sync_repeats', 'signal_repeats') start = time.time() previous_image = None if get_picture_function is not None: previous_image = get_picture_function() for frequency in frequencies: for command_tuple in command_iterator(frequency): # pylint: disable=star-args command = format_command(*command_tuple) if sys.version_info.major == 3: command = bytes(command, 'utf-8') sock.sendto(command, (host, port)) if get_picture_function is not None: # Normalizing and processing the image takes a long time, so # we'll do the normalization while we're waiting for the # command to broadcast for a full second recent = normalize(previous_image, bit_depth=bit_depth) # Let's compare the most recent photo to the oldest one, # in case a cloud passes over and the brightness changes diff = percent_difference(pictures[0], recent) std_dev = standard_deviation(diffs) mean_ = mean(diffs) while time.time() < start + 1.0: time.sleep(0.1) start = time.time() if get_picture_function is None: print(' '.join( ((desc + ':' + str(value)) for desc, value in zip( command_tuple_description, command_tuple)))) else: previous_image = get_picture_function() # I should be doing a z-test or something here... eh if abs(diff - mean_) > (std_dev * 3.0) and diff > 2.0: print('Found substantially different photo, saving...') print('diff={diff}, mean={mean}, std dev={std_dev}' ' at {time}'.format(diff=diff, mean=mean_, std_dev=std_dev, time=str( datetime.datetime.now()))) file_name = '-'.join( (desc + '-' + str(value)) for desc, value in zip( command_tuple_description, command_tuple)) try: image = get_picture_function() image.save(file_name + '.png') except Exception as exc: print(file_name) print('Unable to save photo: ' + str(exc)) time.sleep(2) diffs.popleft() diffs.append(diff) pictures.popleft() pictures.append(recent)
def search_for_command_codes( host, port, frequencies, get_picture_function=None, bit_depth=None ): """Iterates through commands and looks for changes in the webcam.""" if get_picture_function is not None: diffs = deque() pictures = deque() base = normalize(get_picture_function(), bit_depth=bit_depth) try: base.save('normalized-test.png') except Exception: pass time.sleep(1) print('Filling base photos for difference analysis') for _ in range(20): recent = normalize(get_picture_function(), bit_depth=bit_depth) diff = percent_difference(base, recent) time.sleep(1) diffs.append(diff) pictures.append(recent) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) print( 'Searching for command codes on {frequencies}'.format( frequencies=', '.join((str(f) for f in frequencies)) ) ) command_tuple_description = ('freq', 'useconds', 'multiplier', 'sync_repeats', 'signal_repeats') start = time.time() previous_image = None if get_picture_function is not None: previous_image = get_picture_function() for frequency in frequencies: for command_tuple in command_iterator(frequency): # pylint: disable=star-args command = format_command(*command_tuple) if sys.version_info.major == 3: command = bytes(command, 'utf-8') sock.sendto(command, (host, port)) if get_picture_function is not None: # Normalizing and processing the image takes a long time, so # we'll do the normalization while we're waiting for the # command to broadcast for a full second recent = normalize(previous_image, bit_depth=bit_depth) # Let's compare the most recent photo to the oldest one, # in case a cloud passes over and the brightness changes diff = percent_difference(pictures[0], recent) std_dev = standard_deviation(diffs) mean_ = mean(diffs) while time.time() < start + 1.0: time.sleep(0.1) start = time.time() if get_picture_function is None: print( ' '.join(( (desc + ':' + str(value)) for desc, value in zip( command_tuple_description, command_tuple ) )) ) else: previous_image = get_picture_function() # I should be doing a z-test or something here... eh if abs(diff - mean_) > (std_dev * 3.0) and diff > 2.0: print('Found substantially different photo, saving...') print( 'diff={diff}, mean={mean}, std dev={std_dev}' ' at {time}'.format( diff=diff, mean=mean_, std_dev=std_dev, time=str(datetime.datetime.now()) ) ) file_name = '-'.join( (desc + '-' + str(value)) for desc, value in zip( command_tuple_description, command_tuple ) ) try: image = get_picture_function() image.save(file_name + '.png') except Exception as exc: print(file_name) print('Unable to save photo: ' + str(exc)) time.sleep(2) diffs.popleft() diffs.append(diff) pictures.popleft() pictures.append(recent)
def search_for_command_codes(host, port, frequencies, get_picture_function=None, bit_depth=None): """Iterates through commands and looks for changes in the webcam.""" if get_picture_function is not None: diffs = deque() pictures = deque() base = normalize(get_picture_function(), bit_depth=bit_depth) try: base.save('normalized-test.png') except Exception: pass time.sleep(1) print('Filling base photos for difference analysis') for _ in range(20): recent = normalize(get_picture_function(), bit_depth=bit_depth) diff = percent_difference(base, recent) time.sleep(1) diffs.append(diff) pictures.append(recent) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) print('Searching for command codes on {frequencies}'.format( frequencies=', '.join((str(f) for f in frequencies)))) command_tuple_description = ('freq', 'useconds', 'multiplier', 'sync_repeats', 'signal_repeats') start = time.time() previous_image = None if get_picture_function is not None: previous_image = get_picture_function() for frequency in frequencies: for command_tuple in command_iterator(frequency): # pylint: disable=star-args command = format_command(*command_tuple) if sys.version_info.major == 3: command = bytes(command, 'utf-8') sock.sendto(command, (host, port)) #if get_picture_function is not None: # # Normalizing and processing the image takes a long time, so # # we'll do the normalization while we're waiting for the # # command to broadcast for a full second # recent = normalize(previous_image, bit_depth=bit_depth) # # Let's compare the most recent photo to the oldest one, # # in case a cloud passes over and the brightness changes # diff = percent_difference(pictures[0], recent) # std_dev = standard_deviation(diffs) # mean_ = mean(diffs) while time.time() < start + 1.0: time.sleep(0.1) start = time.time() if get_picture_function is None: print(' '.join( ((desc + ':' + str(value)) for desc, value in zip( command_tuple_description, command_tuple))))
def search_for_command_codes(host, port, frequencies, crop_box=None, bit_depth=None): """Iterates through commands and looks for changes in the webcam.""" diffs = deque() pictures = deque() base = normalize(get_picture(crop_box=crop_box), bit_depth=bit_depth) base.save('normalized-test.png') time.sleep(1) print('Filling base photos for difference analysis') for _ in range(20): recent = normalize(get_picture(crop_box=crop_box), bit_depth=bit_depth) diff = percent_difference(base, recent) time.sleep(1) diffs.append(diff) pictures.append(recent) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) print( 'Searching for command codes on {frequencies}'.format( frequencies=', '.join((str(f) for f in frequencies)) ) ) for frequency in frequencies: for command_tuple in command_iterator(frequency): # pylint: disable=star-args command = format_command(*command_tuple) if sys.version_info.major == 3: command = bytes(command, 'utf-8') sock.sendto(command, (host, port)) time.sleep(1) recent = normalize( get_picture(crop_box=crop_box), bit_depth=bit_depth ) # Let's compare the most recent photo to the oldest one, in case a # cloud passes over and the brightness changes diff = percent_difference(pictures[0], recent) std_dev = standard_deviation(diffs) mean_ = mean(diffs) # I should be doing a z-test or something here... eh if abs(diff - mean_) > (std_dev * 3.0) and diff > 2.0: print('Found substantially different photo, saving...') print( 'diff={diff}, mean={mean}, std dev={std_dev}' ' at {time}'.format( diff=diff, mean=mean_, std_dev=std_dev, time=str(datetime.datetime.now()) ) ) file_name = '-'.join(str(i) for i in command_tuple) os.rename('photo.png', file_name + '.png') time.sleep(2) diffs.popleft() diffs.append(diff) pictures.popleft() pictures.append(recent)