def __init__(self): self.api_endpoint_base = Knob(env_name="AZURE_API_ENDPOINT", default="www.google.com", description="C# API endpoint") self.api_access_key = Knob(env_name="AZURE_API_HOST_KEY", default="12345678", description="C# API host key")
def test_registry(): Knob.clear_registry() assert Knob.get_knob_defaults() == '' k1 = Knob('K1', 'First knob', description='Omi') k2 = Knob('K2', 'Second knob', description='Padre') k1 = Knob('K3', 'Third knob', description='Magnifici') print(Knob.get_knob_defaults()) print(repr(Knob.get_knob_defaults())) envout = '# Omi\n# K1=First knob\n\n# Padre\n# K2=Second knob\n\n# Magnifici\n# K3=Third knob\n' assert Knob.get_knob_defaults() == envout
def test_set(): setknob = Knob('KNOB_NAME', 'KNOB_VAL') assert setknob.get_type() == str assert setknob.get() == 'KNOB_VAL' setknob.set('XX123') assert setknob.get() == 'XX123'
def cli( shape_predictor, blink_ratio, trigger, set_alarm, alarm_sound, alert_msg, webcam, frame_width, print_knobs, ): """ Dedrowse drowsines detector """ if print_knobs: print(Knob.get_knob_defaults()) sys.exit(1) alarmer = AlarmDetector(blink_ratio, trigger=trigger, alert_message=alert_msg) # initialize dlib's face detector (HOG-based) and then create # the facial landmark predictor click.echo('Loading facial landmark predictor...') detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(shape_predictor) # grab the indexes of the facial landmarks for the left and # right eye, respectively l_start, l_end = face_utils.FACIAL_LANDMARKS_IDXS['left_eye'] r_start, r_end = face_utils.FACIAL_LANDMARKS_IDXS['right_eye'] # start the video stream thread click.echo('Starting video stream thread') vs = VideoStream(webcam).start() # loop over frames from the video stream while True: # grab the frame from the threaded video file stream, resize # it, and convert it to grayscale # channels) frame = vs.read() if frame is None: click.echo('No frame') time.sleep(1) continue frame = imutils.resize(frame, width=frame_width) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # detect faces in the grayscale frame faces = detector(gray, 0) # loop over the face detections for face in faces: # determine the facial landmarks for the face region, then # convert the facial landmark (x, y)-coordinates to a NumPy # array shape = predictor(gray, face) shape = face_utils.shape_to_np(shape) # extract the left and right eye coordinates, then use the # coordinates to compute the eye aspect ratio for both eyes left_eye = shape[l_start:l_end] right_eye = shape[r_start:r_end] left_ear = eye_aspect_ratio(left_eye) right_ear = eye_aspect_ratio(right_eye) # average the eye aspect ratio together for both eyes ear = (left_ear + right_ear) / 2.0 alarmer.check(ear, frame) draw_eyes(ear, frame, left_eye, right_eye) # show the frame cv2.imshow('Dedrowser is looking out for you', frame) key = cv2.waitKey(1) & 0xFF # if the `q` key was pressed, break from the loop if key == ord("q"): break # do a bit of cleanup cv2.destroyAllWindows() vs.stop()
from knobs import Knob VALIDATION_FAILED_SQS = Knob( env_name="VALIDATION_FAILED_SQS", default="", description="SQS queue name for data that fails validation") UNKNOWN_ERROR_SQS = Knob(env_name="UNKNOWN_ERROR_SQS", default="", description="All other SQS errors") SQS_REGION = Knob(env_name="SQS_REGION", default="us-east-1", description="Region where SQS is.")
from knobs import Knob import pkg_resources __version__ = '0.1.0' ALARM_SOUND = Knob('DEDROWSE_ALARM_SOUND_PATH', pkg_resources.resource_filename('dedrowse', 'data/alarm.wav'), description='Alarm sound file') ALERT_MESSAGE = Knob('DEDROWSE_ALERT_MESSAGE', 'DROWSINESS DETECTED', description='Alert message') SHAPE_PREDICTOR = Knob('DEBROWSE_SHAPE_PREDICTOR', pkg_resources.resource_filename('dedrowse', 'data/face.dat'), description='Path to facial landmark predictor') WEBCAM = Knob('DEBROWSE_WEBCAM', 0, description='Webcam number') ALARM = Knob('DEBROWSE_ALARM', True, description='Sound the Alarm') BLINK_ASPECT_RATIO = Knob( 'DEBROWSE_BLINK_ASPECT_RATIO', 0.3, description='Eye aspect ratio indicating blink', ) EYE_AR_CONSEC_FRAMES = Knob( 'DEBROWSE_AR_CONSEC_FRAMES',
def test_cast_to_string(): rope = Knob('ROPE_TO_HANG_BY', 'A stiff rope for yer nek, mate') assert rope.get_type() == str
def test_serialize(): knob = Knob('WUNDER', 'BAR', description='Foo Bar') assert repr( knob ) == "Knob('WUNDER', 'BAR', unit='', description='Foo Bar', validator=None)"
def test_repr(): pirate_count = Knob('JOLLY_ROGER_PIRATES', 124, description='Yar') assert repr( pirate_count ) == "Knob('JOLLY_ROGER_PIRATES', 124, unit='', description='Yar', validator=None)"
def test_typle_from_env(): os.environ['TUPLE'] = 'DEAD BEEF COFFEE' assert type(os.environ['TUPLE']) == str knob = Knob('LIST', ('LOVE', 'THEY', 'NEIGHBOUR')) assert knob.get_type() == tuple assert knob() == ('DEAD', 'BEEF', 'COFFEE')
def test_list_from_env(): os.environ['LIST'] = 'DEAD BEEF COFFEE' assert type(os.environ['LIST']) == str knob = Knob('LIST', ['LOVE', 'THEY', 'NEIGHBOUR']) assert knob.get_type() == list assert knob() == ['DEAD', 'BEEF', 'COFFEE']
def test_tuple(): knob = Knob('LIST', ('LOVE', 'THEY', 'NEIGHBOUR')) assert knob() == ('LOVE', 'THEY', 'NEIGHBOUR')
def test_knob_cast_str_auto_corrected_to_int(): knob = Knob('WUNDER', 22) assert knob.get() == 22
def test_knob(): knob = Knob('WUNDER', 'BAR', description='Foo Bar') assert knob() == 'BAR' assert knob.get() == 'BAR' assert knob.description == 'Foo Bar' knob.rm()
from knobs import Knob from socket import gethostname CAMERA_NUMBER = Knob( env_name="CAMERA_NUMBER", default=0, description="Raspberry Pi camera number according to " "https://picamera.readthedocs.io/en/release-1.13/api_camera.html#picamera") INVERT_CAMERA = Knob(env_name="CAMERA_INVERT", default=True, description="Vertical invert camera") GPS_SERIAL_PORT = Knob(env_name="GPS_SERIAL_PORT", default="/dev/ttyUSB0", description="Serial port for GPS") GPS_BAUD_RATE = Knob(env_name="GPS_BAUD_RATE", default=9600, description="Baud rate on GPS") MODEL_PATH = Knob(env_name="MODEL_PATH", default='/home/pi/thirdstep.model', description="Pytorch Model Location") BASE_URL = Knob(env_name="BASE_URL", default='https://foo.execute-api.us-east-1.amazonaws.com', description="Base URL to send HTTP post to") DEVICE_NAME = Knob(env_name="DEVICE_NAME", default=gethostname(),
from knobs import Knob from socket import gethostname # Knobs are basically wrappers for os.getenvs that have some niceties CAMERA_NUMBER = Knob( env_name="CAMERA_NUMBER", default=0, description="Raspberry Pi camera number according to " "https://picamera.readthedocs.io/en/release-1.13/api_camera.html#picamera") INVERT_CAMERA = Knob(env_name="CAMERA_INVERT", default=True, description="Vertical invert camera") DEVICE_NAME = Knob(env_name="DEVICE_NAME", default=gethostname(), description="Device Name") AWS_REGION = Knob(env_name="AWS_REGION", default='us-east=1', description="AWS region that your resources live in") MODEL_ENDPOINT_NAME = Knob( env_name="AWS_MODEL_ENDPOINT_NAME", default=False, description="AWS Model endpoint for CVEDIA Human Detector") AWS_API_GATEWAY = Knob( env_name="AWS_API_GATEWAY", default="https://m5k4jhx1ka.execute-api.us-east-1.amazonaws.com/dev/", description="AWS API Gateway Endpoint")
def test_cast_to_int(): pirate_count = Knob('JOLLY_ROGER_PIRATES', 124, description='Yar') assert pirate_count.get() == 124 assert pirate_count.description == 'Yar'