Ejemplo n.º 1
0
    def __init__(self, height=480, width=680):

        # set setting from config file
        config_path = 'config/config.json'

        with open(config_path) as config_file:
            config = json.load(config_file)

        # init file creation handling
        self.writing_to_image_list = False
        self.fileCount = 0
        self.writing_to_file = False

        # init thread handling flag
        self.stopped = False

        # init image_list handling

        self.image_list = []
        self.image_counter = 0
        self.image_limit = config["file_writer_config"]["image_limit"]

        # init flag to handle reference background resetting after file is created
        self.background_image_set = False

        # init writing to image_list flag
        self.motion_detected = False

        # init inactivity handling; needed if frames are skipped or contours are not found in inbetween frames
        self.inactivityCounter = 0
        self.inactivity_limit = config["file_writer_config"][
            "inactivity_limit"]

        # handle modes
        self.mode = config["file_writer_config"]["mode"]
        self.create_jpg_only = boolcheck(
            config["file_writer_config"]["create_jpg_only"])

        if self.mode == "avi":
            self.fps = config["file_writer_config"]["fps_in_avi_mode"]
            self.frame_width = width
            self.frame_height = height
            self.writer = cv2.VideoWriter(
                "avi/output" + str(self.fileCount) + ".avi",
                cv2.VideoWriter_fourcc(*"MJPG"), self.fps,
                (self.frame_width, self.frame_height))

        self.verbose = boolcheck(config["general_config"]["verbose"])

        # init buffer_mode
        self.buffer_mode = boolcheck(config["general_config"]["create_buffer"])
        self.create_buffer = True
        self.buffer_length = config["file_writer_config"]["buffer_length"]
        self.lock = threading.Lock()
Ejemplo n.º 2
0
    def __init__(self, frame, resize_factors):

        # get settings from config file
        config_path = 'config/config.json'

        with open(config_path) as config_file:
            config = json.load(config_file)

        self.frame = frame

        # init thread handling
        self.stopped = False

        # set verbose mode
        self.verbose = boolcheck(config["general_config"]["verbose"])

        # red color
        self.low_red = np.array([161, 100, 84])
        self.high_red = np.array([179, 255, 255])

        self.brush_x = 0
        self.brush_y = 0
        self.brush_radius = 0

        self.resize_width_factor = resize_factors[0]
        self.resize_heigth_factor = resize_factors[1]

        self.resize_width = 200
Ejemplo n.º 3
0
    def __init__(self, src=0, name="VideoStream"):

        config_path = 'config/config.json'

        with open(config_path) as config_file:
            config = json.load(config_file)

        if boolcheck(config["general_config"]["stream_via_url"]) == True:
            src = config["general_config"]["stream_url"]

        # initialize the video camera stream and read the first frame
        # from the stream
        self.stream = cv2.VideoCapture(src)
        # self.stream = cv2.VideoCapture("tcp://192.168.178.51:5000")
        # time.sleep(1.0)
        #self.stream.set(cv2.CAP_PROP_BUFFERSIZE, 2)
        self.stream.set(3, 640)
        self.stream.set(4, 480)
        self.stream.set(cv2.CAP_PROP_BUFFERSIZE, 2)

        (self.grabbed, self.frame) = self.stream.read()

        # initialize the variable used to indicate if the thread should
        # be stopped
        self.stopped = False

        self.frame_count = 0
Ejemplo n.º 4
0
import time
import json
from modules.painter import Painter
from modules.canvas import Canvas_painter

# function to parse bool value from config file
from utils.boolcheck import boolcheck

# get settings from config file
config_path = 'config/config.json'

with open(config_path) as config_file:
    config = json.load(config_file)

## mode selection
enable_fps_timer = boolcheck(config["general_config"]["enable_fps_timer"])

camera_mode = "webcam"

# init videostream (separate thread)
if camera_mode == "webcam":

    # start raspivid in a subprocess
    # import subprocess
    # cmd = "raspivid -n -t 0 -n  -w 1024 -h 768  -ih -fl -l -o - | /bin/nc -lvp 5000"
    # subprocess.Popen(cmd, shell=True)
    from modules.cam import VideoStream
    time.sleep(2)
    cap = VideoStream(src=2).start()
else:
    from modules.PiCam import PiCam
Ejemplo n.º 5
0
from PIL import Image
import glob 
import json
import cv2

# function to parse bool value from config file
from utils.boolcheck import boolcheck

config_path = 'config/config.json'

with open(config_path) as config_file:
    config = json.load(config_file)

gif_duration = config["gif_config"]['gif_duration']
loop_gif = config["gif_config"]['loop_gif']
imagemagick_installed = boolcheck(config["gif_config"]['imagemagick_installed'])

if imagemagick_installed == True:
    from wand.image import Image as ImageFromWand

def imgToGif(folderCount, image_list):
    
    if imagemagick_installed == False:

        pil_image_list = []

        for bgr_image in image_list:
            rgb_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)
            image = Image.fromarray(rgb_image, mode="RGB")
            pil_image_list.append(image)
Ejemplo n.º 6
0
from flask import Flask, request
from flask_cors import CORS

import json

# function to parse bool values from config file
from utils.boolcheck import boolcheck

# init settings
config_path = 'config/config.json'

with open(config_path) as config_file:
    config = json.load(config_file)

camera_mode = config["general_config"]["camera"]
bbox_mode = boolcheck(config["adjust_config"]["bbox_mode"])
gpio_motor = boolcheck(config["adjust_config"]["gpio_motor"])
preview_mode = config["adjust_config"]["preview_mode"]["set"]

if gpio_motor == True:
    from modules.gpio_motor import GPIO_motor
    motor = GPIO_motor()

# init flask
app = Flask(__name__)
CORS(app)

# init cam
if camera_mode == "webcam":
    from modules.cam import VideoStream
    cap = VideoStream(src=0).start()
Ejemplo n.º 7
0
    def __init__(self, frame):

        # set setting from config file
        config_path = 'config/config.json'

        with open(config_path) as config_file:
            config = json.load(config_file)

        # init frame analysis
        self.gauss_blur_factor = config["analyzer_config"]["gauss_blur_factor"]
        self.resize_width = config["analyzer_config"]["resize_width"]
        self.frame = frame
        self.background_image = imutils.resize(
            cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), self.resize_width)

        # set detection area
        self.detection_area_min = 0
        self.detection_area_max = 0
        self.detection_area_factor_min = config["analyzer_config"][
            "detection_area_factor_min"]
        self.detection_area_factor_max = config["analyzer_config"][
            "detection_area_factor_max"]

        # print current dimensions
        frame_height = frame.shape[0]
        frame_width = frame.shape[1]
        contour_threshold_min = int(
            (frame_width * frame_height) * (self.detection_area_factor_min))
        contour_threshold_max = int(
            (frame_width * frame_height) * (self.detection_area_factor_max))

        print("Total area: " + str(frame_width * frame_height) +
              " (frame width: " + str(frame_width) + " x " + "frame height: " +
              str(frame_height) + ")")
        print("Minimum detection area: " + str(contour_threshold_min) + " (" +
              str(self.detection_area_factor_min * 100) + " % of total area)")
        print("Maximum detection area: " + str(contour_threshold_max) + " (" +
              str(self.detection_area_factor_max * 100) + " % of total area)")

        # limit contours while detecting motion, ignore results with to many contours (e.g. detecting leaves in the wind)
        self.contours_limit = config["analyzer_config"]["contours_limit"]

        # init motion detection
        self.motion_detected = False

        # init thread handling
        self.stopped = False

        # set for drawing bounding box around detected area contour_threshold_min = int((frame_width * frame_height) * (self.detection_area_factor_min))
        self.bbox_mode = boolcheck(config["analyzer_config"]["bbox_mode"])

        # bbox has to be resized according to original frame size
        self.resize_factor = self.frame.shape[1] / self.resize_width

        # flag to stop analyzing while file is being written
        self.file_writing = False

        # set verbose mode
        self.verbose = boolcheck(config["general_config"]["verbose"])

        # fetch threshold values from config file
        self.threshold_black = config["analyzer_config"]["threshold_black"]
        self.threshold_white = config["analyzer_config"]["threshold_white"]

        # init preview mode as false, set true to show frames in window
        self.preview = False
Ejemplo n.º 8
0
from modules.file_writer import File_writer

# function to parse bool value from config file
from utils.boolcheck import boolcheck

# set setting from config file
config_path = 'config/config.json'

with open(config_path) as config_file:
    config = json.load(config_file)

print("[init] get startup settings from config.json file")

# init different modes
camera_mode = config["general_config"]["camera"]
enable_timer = boolcheck(config["general_config"]["enable_fps_timer"])
buffer_mode = boolcheck(config["general_config"]["create_buffer"])

verbose = boolcheck(config["general_config"]["verbose"])

# init videostream (separate thread)
if camera_mode == "webcam":
    from modules.cam import VideoStream
    #cap = VideoStream(src=0, resolution=(frame_width,frame_height)).start()
    cap = VideoStream(src=0).start()
else:
    from modules.PiCam import PiCam
    cap = PiCam().start()

# warm um camera - without first frame returns empty
time.sleep(2.0)