예제 #1
0
    def initialize(self, device_type="auto", width=320, height=240):
        Camera.device_type = device_type
        if device_type == "auto":
            Camera.device_type = thermal() if lepton_in(
                modules) else raspberrypi() if is_linux() else default()

        self.width = width
        self.height = height

        if Camera.thread is None:
            Camera.thread = threading.Thread(target=self._thread)
            Camera.thread.stop_event = threading.Event()
            Camera.thread.start()

            # Return control to calling class when frame becomes available or when thread terminates
            print("Camera class initialised with device '{}'".format(
                Camera.device_type))
            while self.frame is None and self.thread is not None:
                sleep(0)
            print("Returning control to calling class")

            return self.thread is None
        else:
            print("Camera thread already initialised")
            return False
예제 #2
0
파일: sorcery.py 프로젝트: mgupton/sorcery
def get_host_id():

    if not util.does_host_exec_exists():
        return None

    if util.is_windows():
        phost_exec = util.WIN_PHOST_EXEC
    elif util.is_linux():
        phost_exec = util.LINUX_PHOST_EXEC
    else:
        return None

    cmd_output = check_output([phost_exec, "print-config"],
                              stderr=subprocess.STDOUT)

    cmd_output = iter(cmd_output.splitlines())

    for line in cmd_output:

        line = line.decode('UTF-8')

        m = re.search("source_id: \"([a-fA-F0-9-]+)\"", line)

        if m != None:
            return m.group(1)

    return None
예제 #3
0
파일: sorcery.py 프로젝트: mgupton/sorcery
def name_lm_source(api_key, cid, source_id, name):

    global API_BASE_URL
    err_msg = "Error naming log source."

    if util.is_windows():
        api_endpoint = "/api/lm/v1/%s/sources/eventlog/%s" % (cid, source_id)
        post_data = '{"eventlog": { "name": "%s" }}' % (name)

    elif util.is_linux():
        api_endpoint = "/api/lm/v1/%s/sources/syslog/%s" % (cid, source_id)
        post_data = '{"syslog": { "name": "%s" }}' % (name)

    url = API_BASE_URL + api_endpoint

    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "Authorization": "Basic %s" % (api_key)
    }

    result = requests.post(url, data=post_data, headers=headers)

    if result.status_code != 200:
        print(err_msg, file=sys.stderr)
        print(url)
        raise Exception(err_msg)
예제 #4
0
    def server_stop():
        # 服务器结束
        logging.info('stopping gate...')
        zmq_server.close()
        ioloop.IOLoop.instance().stop()

    def sig_stop(sig, frame):
        # 退出信号处理
        logging.warning('caught signal: %s', sig)
        ioloop.IOLoop.instance().add_callback(server_stop)

    def server_reload():
        # 服务器重载
        logging.info('gate reloading...')
        reload(conf)
        reload(util)
        logging.info('gate reloaded.')

    def sig_reload(sig, frame):
        # 重载信号处理
        logging.warning('caught signal: %s', sig)
        ioloop.IOLoop.instance().add_callback(server_reload)

    if util.is_linux():
        signal.signal(signal.SIGHUP, sig_reload)

    signal.signal(signal.SIGTERM, sig_stop)
    signal.signal(signal.SIGINT, sig_stop)

    ioloop.IOLoop.instance().start()
예제 #5
0
import io
from sys import modules
import threading
# from datetime import datetime
from time import sleep
import numpy as np

from util import default, raspberrypi, is_linux, thermal, lepton_in

if is_linux():
    import picamera

    try:
        from pylepton.Lepton3 import Lepton3
        import cv2
    except ImportError:
        pass
else:
    import cv2


class Camera(object):
    thread = None
    frame = None
    # last_access = datetime.now()
    device_type = ""
    width = 320
    height = 240
    size = height * width

    def initialize(self, device_type="auto", width=320, height=240):