def __init__(self): #I am not shure this is correct. According to docs, you do not instantate a logger. os.system('sudo ifconfig wlan0 down') # Can't have this up at comp logging.basicConfig(filename="../logs/runLogs.log", level=logging.DEBUG) logging.debug("\n--------------------New run------------------") logging.debug("Run started at: ") logging.debug(datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')) logging.debug("---------------------------------------------\n") self.windowName = "picamera" self.target = comm.Target() self.commChan = None self.parseArgs() print("testPCam pid: %d args:" % os.getpid()) print(self.args) print("OpenCV version: {}".format(cv2.__version__)) if self.args.robot != "none": if self.args.robot == "roborio": logging.debug( datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')) logging.debug("Connecting to robot at 10.49.15.2...") ip = "10.49.15.2" else: ip = "localhost" print("starting comm to " + ip) self.commChan = comm.Comm(ip) self.picam = picam.PiCam(resolution=(self.args.iwidth, self.args.iheight), framerate=(self.args.fps)) # Push something down the pipe. self.commChan.SetTarget(self.target)
def __init__(self): self.commChan = None self.parseArgs() # logger init: # - we write logging info to file, for performance this should be # minimized. # - during debugging, set the loglevel to debug and see the 'spew' # via: "tail -f /tmp/runPiCam.log" if self.args.debug: logLevel = logging.DEBUG else: logLevel = logging.INFO logging.basicConfig( level=logLevel, format="%(asctime)s %(levelname)-6s: %(message)s", datefmt="%m/%d %H:%M:%S", # This file is avible to write to, even when the pi is in 'read-only' mode filename="/tmp/runPiCam.log", filemode="a") logging.info("--------------------New run------------------") logging.info("pid: %d" % os.getpid()) logging.info("args: " + str(self.args)) logging.info("opencv version: {}".format(cv2.__version__)) logging.debug("Parsed the following args:") logging.debug(self.args) if self.args.robot != "none": if self.args.robot == "roborio": fmt = "%Y/%m/%d %H:%M:%S" logging.debug(datetime.datetime.now().strftime(fmt)) logging.debug("Connecting to robot at 10.49.15.2...") ip = "10.49.15.2" else: ip = self.args.robot logging.info("starting comm to " + ip) self.commChan = comm.Comm(ip) # parameter configuration ----- self.config = getattr(config, self.args.config) # reads named dict self.picam = picam.PiCam(self.config["picam"]) self.algoConfig = self.config["algo"] # Updating config with passed commands # XXX: Need logic to check if these values exist in the chosen config # Unsure if an error will be thrown # Overriding config values with passed values if (self.args.display): self.algoConfig["display"] = True if (self.args.algo is not None): self.algoConfig["algo"] = self.args.algo
def do_GET(self): # we respond with a stream if the url ends in either .mjpg or .mjpeg # we select between direct or algorithm-filtered streams based # on the filename. If the algostr (below) is "direct.mjpeg", we # get fast/raw/direct streaming. Otherwise the algostr is passed # to the algo entrypoint. if self.path.endswith('.mjpg') or self.path.endswith('.mjpeg'): algostr = os.path.basename(self.path).split(".")[0] self.send_response(200) self.send_header( 'Content-type', 'multipart/x-mixed-replace; boundary=--jpgboundary') self.end_headers() cam = None try: time.sleep(1) # wait for shutdown of alt stream cam = picam.PiCam(s_config["picam"]) if not cam: raise Exception("Hey no camera!") if algostr == "direct": self.streamDirect(cam) else: self.streamAlgo(cam, algostr) except BrokenPipeError: logging.warning("broken pipe error") except KeyboardInterrupt: logging.info("keyboard interrupt") except Exception as e: # Critical for anything that happens in algo or below exc_info = sys.exc_info() logging.error("algo exception: " + str(e)) traceback.print_exception(*exc_info) finally: logging.info("done streaming ----------------------") if cam: cam.stop() # triggers PiCamera.close() else: logging.info("(cam init problem)") else: self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(bytes(s_mainPage, 'utf-8')) return
def run(self): cam = picam.PiCam() last_frame_time = time.time() while not self.stop_event.is_set(): t0 = time.time() a = cam.capture() t1 = time.time() if self.queue.full(): self.queue.get() self.queue.put(a) t2 = time.time() if not self.cmds.empty(): cmd = self.cmds.get() n = cmd[1] r = None if not hasattr(cam, n): r = Exception("invalid property: %s" % n) else: if cmd[0] == 'get': try: r = getattr(cam, n) if n in ('resolution', 'framerate'): r = tuple(r) except Exception as e: r = e else: try: setattr(cam, n, cmd[2]) except Exception as e: r = e self.results.put((n, r)) t3 = time.time() if print_timing: print("capture: %0.4f" % (t1 - t0)) print("queue : %0.4f" % (t2 - t1)) print("cmds : %0.4f" % (t3 - t2)) fps = 1. / (t2 - last_frame_time) print("fps : %0.2f" % fps) last_frame_time = t2 print("Releasing capture") cam.close() del cam
def __init__(self): self.windowName = "picamera" self.target = comm.Target() self.commChan = None self.parseArgs() print("testPCam pid: %d args:" % os.getpid()) print(self.args) print("OpenCV version: {}".format(cv2.__version__)) if self.args.robot != "none": if self.args.robot == "roborio": ip = "10.49.15.2" else: ip = "localhost" print("starting comm on " + ip) self.commChan = comm.Comm(ip) self.picam = picam.PiCam(resolution=(self.args.iwidth, self.args.iheight), framerate=(self.args.fps))
def __init__(self): self.commChan = None self.parseArgs() # logger init: # - we write logging info to file, for performance this should be # minimized. # - during debugging, set the loglevel to debug and see the 'spew' # via: "tail -f /tmp/runPiCam.log" if self.args.debug: logLevel = logging.DEBUG else: logLevel = logging.INFO logging.basicConfig(level=logLevel, format="%(asctime)s %(levelname)-6s: %(message)s", datefmt="%m/%d %H:%M:%S", filename="/tmp/runPiCam.log", filemode="a") logging.info("--------------------New run------------------") logging.info("pid: %d" % os.getpid()) logging.info("args: " + str(self.args)) logging.info("opencv version: {}".format(cv2.__version__)) logging.debug("Parsed the following args:") logging.debug(self.args) if self.args.robot != "none": if self.args.robot == "roborio": fmt = "%Y/%m/%d %H:%M:%S" logging.debug(datetime.datetime.now().strftime(fmt)) logging.debug("Connecting to robot at 10.49.15.2...") ip = "10.49.15.2" else: ip = self.args.robot logging.info("starting comm to " + ip) self.commChan = comm.Comm(ip) # parameter configuration ----- self.config = getattr(config, self.args.config) # reads named dict self.picam = picam.PiCam(self.config["picam"])
from picamera import PiCamera from picamera.array import PiRGBArray import time import picam cfg = { "resolution": (1920, 1080), # cv2.resize() later "framerate": 30, # TODO: Come back to "iso": 400, "brightness": 40, "contrast": 100, "flip": False, "rotation": 0, "exposure_mode": "off", #"fixedfps", "exposure_compensation": -25, "sensormode": 7 } framesCap = 0 camera = picam.PiCam(config=cfg) camera.start() times = [] initTime = time.monotonic() while framesCap < 10: frame = camera.next() framesCap += 1 finalTime = time.monotonic() print("Frames Capped: {}".format(framesCap)) print("Average Time : {}".format((finalTime - initTime) / framesCap))