Esempio n. 1
0
 def SavePreview(self, frame):
     dir = os.path.join(config.GetScriptDir(), "web/static/previews/",
                        self.name + ".jpg")
     if os.path.exists(dir):
         os.remove(dir)
     self.SaveImage(frame, dir)
     self.nextPreviewTime = time.time() + config.GetValue("previewTimer")
Esempio n. 2
0
    def GetOuputDir(self):
        outputDir = os.path.abspath(config.GetValue("outputDir"))
        outputDir = os.path.join(outputDir, self.name)

        if not os.path.exists(outputDir):
            os.makedirs(outputDir)
        return outputDir
Esempio n. 3
0
    def SaveVideo(self):
        outputDir = self.GetOuputDir()

        fileName = str(int(time.time())) + ".mp4"
        fileName = os.path.join(outputDir, fileName)

        height, width = self.cap.read().shape[:2]
        print("Size: ", width, "x", height)
        print("fps:", self.fps)
        print("Saving video to: " + fileName + "...", end="")

        #videoWriter = cv2.VideoWriter(fileName, cv2.VideoWriter_fourcc(*"mp4v"), int(self.fps), (width, height))
        self.videoWriter.Start(fileName, self.fps, width, height, "mp4v")
        videoLength = config.GetValue("saveVideoLength")

        if self.prevFrames:
            self.videoWriter.Feed(self.prevFrames.pop())

        saveFrame = None

        sent = False
        count = 0
        startTime = time.time()
        while time.time() - startTime < videoLength:
            self.prevFrames.appendleft(self.cap.read())

            frame = self.prevFrames.pop()
            self.videoWriter.Feed(frame)
            #cv2.imshow(self.name + " Security Feed", frame)
            count += 1

            if time.time() - startTime > videoLength / 2 and not sent:
                sent = True
                saveFrame = frame

        fps = count / (time.time() - startTime)
        print("Actual FPS:", fps)
        self.videoWriter.Stop()

        self.compareFrame = None
        if config.GetValue("email", "enabled"):
            fileName = self.SaveImage(frame)
            email.SendImage(fileName)
        #os.sys("ffmpeg -y -r 30 -i 6bad.mp4 6out.mp4")

        print("Done!")
        return fileName
Esempio n. 4
0
    def __init__(self, name, url, sensitivity, ID):
        self.name = name
        self.ID = ID
        self.compareFrame = None
        self.currentFrame = None
        self.url = url
        self.threshold = 0
        self.sensitivity = sensitivity
        self.refreshRate = config.GetValue("refreshComparisonRate")
        self.missedFrameLimit = config.GetValue("missedFrameLimit")
        self.motionEnabled = config.GetValue("motionEnabled")
        self.videoWriter = VideoWriter()
        self.initialized = False
        self.dead = False
        self.missedFrames = 0
        self.nextRefreshTime = time.time()
        self.nextPreviewTime = time.time()
        self.cap = None

        # Start update thread
        self.updateThread = threading.Thread(target=self.Update)
        self.updateThread.start()
Esempio n. 5
0
    def Init(self):
        if self.dead:
            return

        Log("Initializing...", self)
        try:
            self.cap = VideoCapture(self.url, self)
        except Exception as e:
            Log(e, self, "ERROR")
            restartTime = config.GetValue("cameraRestartTime")
            Log("Waiting " + str(restartTime) + " seconds to try again...",
                self)
            time.sleep(restartTime)
            self.Init()
            return

        self.fps = self.cap.fps
        self.prevFrames = collections.deque(
            maxlen=int(self.fps * config.GetValue("secondsBefore")))
        self.initialized = True
        Log(
            "Initialized with {} fps. Will keep a buffer of {} frames".format(
                self.fps, self.prevFrames.maxlen), self)
Esempio n. 6
0
def InitCams():
    self.cams = []
    self.nextCamID = 0

    for cam in config.GetValue("cams"):
        try:
            c = VideoDevice(cam["name"], cam["url"], 1.5, self.nextCamID)
            self.cams.append(c)
            self.nextCamID += 1

        except KeyError as e:
            print(
                "================================================================"
            )
            print("Error reading config value:")
            print(cam)
            print("Error reading key:", e)
            print(
                "================================================================"
            )

    Log("Cameras loaded", self)
def Init():
    self.port = config.GetValue("email", "port")
    self.smtp_server = config.GetValue("email", "smtp_server")
    self.sender_email = config.GetValue("email", "sender_email")
    self.receiver_email = config.GetValue("email", "receiver_email")
    self.password = config.GetValue("email", "password")
Esempio n. 8
0
def get_motion():
    state = config.GetValue("motionEnabled")
    response = json.dumps({
        "enabled": state
    })
    return Response(response, 200)
Esempio n. 9
0
def get_messages():
    state = config.GetValue("email", "enabled")
    response = json.dumps({
        "enabled": state
    })
    return Response(response, 200)
Esempio n. 10
0
def Run(debug=False):
    port = config.GetValue("webserver", "port")
    app.run(host="0.0.0.0", port=port, debug=debug)
Esempio n. 11
0
def api_versions():
    versions = {
        "latest": updater.GetLatestVersion(),
        "current": config.GetValue("version")
    }
    return Response(json.dumps(versions))
Esempio n. 12
0
def GetCurrentVersion():
    version = config.GetValue("version")
    return version