def user_options(id): if machine_id != id: raise WrongMachineID return { "tracking": ControlThread.user_options(), "recording": ControlThreadVideoRecording.user_options() }
def user_options(id): ''' Passing back options regarding what information can be changed on the the device. This populates the form on the node GUI ''' if machine_id != id: raise WrongMachineID return { "tracking": ControlThread.user_options(), "recording": ControlThreadVideoRecording.user_options(), "streaming": {}, "update_machine": { "machine_options": [{ "overview": "Machine information that can be set by the user", "arguments": [{ "type": "number", "name": "etho_number", "description": "An ID number (1-999) unique to this ethoscope", "default": get_machine_info(id)['machine-number'] }, { "type": "boolean", "name": "isexperimental", "description": "Specify if the ethoscope is to be treated as experimental", "default": isExperimental() }, { "type": "str", "name": "node_ip", "description": "The IP address that you want to record as the node (do not change this value unless you know what you are doing!)", "default": get_machine_info(id)['node_ip'] }, { "type": "str", "name": "ESSID", "description": "The name of the WIFI SSID", "default": get_machine_info(id)['WIFI_SSID'] }, { "type": "str", "name": "Key", "description": "The WPA password for the WIFI SSID", "default": get_machine_info(id)['WIFI_PASSWORD'] }], "name": "Ethoscope Options" }], } }
def __init__(self, ethoscope_info, host='', port=5000): self.host = host self.port = port self.size = 1024 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind((self.host, self.port)) self.sock.listen(5) self.ethoscope_info = ethoscope_info self.control = ControlThread( machine_id=ethoscope_info['MACHINE_ID'], name=ethoscope_info['MACHINE_NAME'], version=ethoscope_info['GIT_VERSION'], ethoscope_dir=ethoscope_info['ETHOSCOPE_DIR'], data=None) self.running = True threading.Thread.__init__(self)
def controls(id, action): global control global record if id != machine_id: raise WrongMachineID if action == 'start': data = request.json tracking_json_data.update(data) control = None control = ControlThread(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOSCOPE_DIR, data=tracking_json_data) control.start() return info(id) elif action in ['stop', 'close', 'poweroff']: if control.info['status'] == 'running' or control.info['status'] == "recording" : # logging.info("Stopping monitor") logging.warning("Stopping monitor") control.stop() logging.warning("Joining monitor") control.join() logging.warning("Monitor joined") logging.warning("Monitor stopped") # logging.info("Monitor stopped") if action == 'close': close() if action == 'poweroff': logging.info("Stopping monitor due to poweroff request") logging.info("Powering off Device.") call('poweroff') return info(id) elif action == 'start_record': data = request.json #json_data.update(data) logging.warning("Recording video, data is %s" % str(data)) data = request.json recording_json_data.update(data) control = None control = ControlThreadVideoRecording(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOSCOPE_DIR, data=recording_json_data) control.start() return info(id) else: raise Exception("No such action: %s" % action)
ETHOSCOPE_DIR = option_dict["results_dir"] if option_dict["record_video"]: recording_json_data = json_data control = ControlThreadVideoRecording(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOSCOPE_DIR, data=recording_json_data) else: tracking_json_data = json_data control = ControlThread(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOSCOPE_DIR, data=tracking_json_data) if option_dict["debug"]: logging.basicConfig(level=logging.DEBUG) logging.info("Logging using DEBUG SETTINGS") if option_dict["stop_after_run"]: control.set_evanescent(True) # kill program after first run if option_dict["run"] or control.was_interrupted: control.start() try:
"path": OUTPUT, "take_frame_shots": False } }, "roi_builder": { "name": ARGS["roi_builder"], "arguments": { "target_coordinates_file": ARGS["target_coordinates_file"] } }, } control = ControlThread(MACHINE_ID, NAME, VERSION, ethoscope_dir=ETHOSCOPE_DIR, data=data, verbose=True, downsample=DOWNSAMPLE) control.start() # # this replicates the code in ControlThread._set_tracking_from_scratch # cam=MovieVirtualCamera(ARGS["input"]) # roi_builder=ROIBuilderClass() # try: # if roi_builder.__class__.__name__ == "FSLTargetROIBuilder": # img, M, rois=roi_builder.build(cam) # else: # rois=roi_builder.build(cam)
def controls(id, action): global control global record if id != machine_id: raise WrongMachineID if action == 'start': data = request.json tracking_json_data.update(data) control = None control = ControlThread(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOSCOPE_DIR, data=tracking_json_data) control.start() return info(id) elif action in ['stop', 'close', 'poweroff']: if control.info['status'] == 'running' or control.info[ 'status'] == "recording": # logging.info("Stopping monitor") logging.warning("Stopping monitor") control.stop() logging.warning("Joining monitor") control.join() logging.warning("Monitor joined") logging.warning("Monitor stopped") # logging.info("Monitor stopped") if action == 'close': close() if action == 'poweroff': logging.info("Stopping monitor due to poweroff request") logging.info("Powering off Device.") call('poweroff') return info(id) elif action == 'start_record': data = request.json #json_data.update(data) logging.warning("Recording video, data is %s" % str(data)) data = request.json recording_json_data.update(data) control = None control = ControlThreadVideoRecording(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOSCOPE_DIR, data=recording_json_data) control.start() return info(id) elif action == 'settime': # TODO check the status of ntp and maybe refuse to set the time if ntp is working timeString = "%02d%02d%02d%02d" % ( request.json["month"], request.json["date"], request.json["hours"], request.json["minutes"]) logging.warning("Requested that the time be set to " + str(timeString)) call(["date", "--utc", timeString]) return info(id) else: raise Exception("No such action: %s" % action)
def controls(id, action): global control global record try: if id != machine_id: raise WrongMachineID if action == 'start': data = request.json json_data.update(data) control = ControlThread(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOGRAM_DIR, data=json_data) control.start() return info(id) elif action in ['stop', 'close', 'poweroff']: if control.info['status'] == 'running': logging.info("Stopping monitor") control.stop() control.join() logging.info("Monitor stopped") if action == 'close': close() if action == 'poweroff': logging.info("Stopping monitor due to poweroff request") logging.info("Powering off Device.") call('poweroff') return info(id) elif action == 'start_record': data = request.json #json_data.update(data) logging.warning("Recording video, data is %s" % str(data)) record = RecordVideo(data=data) record.start() control.info['status'] = 'recording' return info(id) elif action == 'stop_record': if record is not None: recording_file = record.stop() record.join() control.info['status'] = 'stopped' control.info['recording_file'] = recording_file return info(id) else: logging.warning( "Can not stop video record. No video record started.") except Exception as e: return {'error': traceback.format_exc(e)}
machine_name = get_machine_info(MACHINE_NAME_FILE) version = get_version() if option_dict["json"]: import json with open(option_dict["json"]) as f: json_data = json.loads(f.read()) else: data = None ETHOGRAM_DIR = option_dict["results_dir"] control = ControlThread(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOGRAM_DIR, data=json_data) if option_dict["debug"]: logging.basicConfig(level=logging.DEBUG) logging.info("Logging using DEBUG SETTINGS") if option_dict["stop_after_run"]: control.set_evanescent(True) # kill program after first run if option_dict["run"]: control.start() try: run(api,
def controls(id, action): global control global record if id != machine_id: raise WrongMachineID if action == 'start': data = bottle.request.json tracking_json_data.update(data) control = None control = ControlThread(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOSCOPE_DIR, data=tracking_json_data) control.start() return info(id) elif action in ['stop', 'close', 'poweroff', 'reboot', 'restart']: if control.info['status'] in ['running', 'recording', 'streaming']: logging.info("Stopping monitor") control.stop() logging.info("Joining monitor") control.join() logging.info("Monitor joined") logging.info("Monitor stopped") if action == 'close': close() if action == 'poweroff': logging.info("Stopping monitor due to poweroff request") logging.info("Powering off Device.") subprocess.call('poweroff') if action == 'reboot': logging.info("Stopping monitor due to reboot request") logging.info("Powering off Device.") subprocess.call('reboot') if action == 'restart': logging.info("Restarting service") subprocess.call(['systemctl', 'restart', 'ethoscope_device']) return info(id) elif action in ['start_record', 'stream']: data = bottle.request.json recording_json_data.update(data) logging.warning("Recording or Streaming video, data is %s" % str(data)) control = None control = ControlThreadVideoRecording(machine_id=machine_id, name=machine_name, version=version, ethoscope_dir=ETHOSCOPE_DIR, data=recording_json_data) control.start() return info(id) else: raise Exception("No such action: %s" % action)
cam = MovieVirtualCamera("/data/pysolo_video_samples/sleepMonitor_5days.avi") roi_builder = SleepMonitorWithTargetROIBuilder() rois = roi_builder(cam) interactors = [SystemPlaySoundOnStop(i*10 + 100) for i,r in enumerate(rois)] track = ControlThread(cam, AdaptiveBGModel, rois, out_file="/tmp/test.csv", # save a csv out max_duration=None, # when to stop (in seconds) video_out=None, # when to stop (in seconds) interactors = interactors, draw_results=True, # draw position on image draw_every_n=1) # only draw 1 every 10 frames to save time track.start() try: while True: time.sleep(2) cv2.imshow("lastFrame", track.last_frame) finally: track.stop()
def action(self, action, data=None): ''' act on client's instructions ''' if not data and action in ['start', 'start_record']: return 'This action requires JSON data' if action == 'help': return "Commands that do not require JSON info: help, info, status, stop, stream.\nCommands that do require JSON info: start, start_record." elif action == 'info': return self.control.info elif action == 'status': return self.control.info['status'] elif action == 'start' and data: self.control = ControlThread( machine_id=self.ethoscope_info['MACHINE_ID'], name=self.ethoscope_info['MACHINE_NAME'], version=self.ethoscope_info['GIT_VERSION'], ethoscope_dir=self.ethoscope_info['ETHOSCOPE_DIR'], data=data) self.control.start() logging.info("Starting tracking") return "Starting tracking activity" elif action == 'stream': self.control = ControlThreadVideoRecording( machine_id=self.ethoscope_info['MACHINE_ID'], name=self.ethoscope_info['MACHINE_NAME'], version=self.ethoscope_info['GIT_VERSION'], ethoscope_dir=self.ethoscope_info['ETHOSCOPE_DIR'], data=data) self.control.start() return "Starting streaming activity" elif action == 'start_record' and data: self.control = ControlThreadVideoRecording( machine_id=self.ethoscope_info['MACHINE_ID'], name=self.ethoscope_info['MACHINE_NAME'], version=self.ethoscope_info['GIT_VERSION'], ethoscope_dir=self.ethoscope_info['ETHOSCOPE_DIR'], data=data) self.control.start() return "Starting recording or streaming activity" elif action == 'stop' and self.control.info['status'] in [ 'running', 'recording', 'streaming' ]: logging.info("Stopping monitor") self.control.stop() logging.info("Joining monitor") self.control.join() logging.info("Monitor joined") logging.info("Monitor stopped") return "Stopping ethoscope activity" else: #raise Exception("No such command: %s. Available commands are info, status, start, stop, start_record, stream " % action) return 'This ethoscope action is not available.'
data = { "camera": {"name": ARGS["camera"], "args": (ARGS["input"],), "kwargs": {"use_wall_clock": ARGS["use_wall_clock"], "drop_each": ARGS["drop_each"]}}, "result_writer": {"name": "SQLiteResultWriter", "kwargs": {"path": OUTPUT, "take_frame_shots": True}}, "roi_builder": {"name": ARGS["roi_builder"], "kwargs": {"target_coordinates_file": ARGS["target_coordinates_file"], "rois_pickle_file": ARGS["rois_pickle_file"]}}, "tracker": {"name": ARGS["tracker"], "kwargs": {}} } json_data.update(data) tracking_json_data = json_data control = ControlThread(MACHINE_ID, NAME, VERSION, ethoscope_dir=ETHOSCOPE_DIR, data=tracking_json_data, verbose=True) if DEBUG: logging.basicConfig(level=logging.DEBUG) logging.info("Logging using DEBUG SETTINGS") if ARGS["stop_after_run"]: control.set_evanescent(True) # kill program after first run if ARGS["run"] or control.was_interrupted: control.start() # try: # run(api, host='0.0.0.0', port=port, server='cherrypy',debug=ARGS["debug"]) try: