Esempio n. 1
0
def start():
    cams = [{
        "tz":
        "ID",
        "url":
        'https://cf-stream.coastalwatch.com/cw/' +
        os.environ.get('CAMNAME', 'bondicamera') + '.stream/chunklist.m3u8',
        "framerate":
        int(os.environ.get('FR', '20')),
        "videolength":
        os.environ.get('LENGTH', '00:06:00')
    }]

    cam = Camera(cams, test=TEST)
    cam.start = True
    for img in cam:
        if cam.start:
            height, width, _ = img.shape
            panarama = Panarama(img, height, width)
            cam.start = False
        else:
            panarama.stitch(img)

        # if no more states
        if not panarama.REQUIREDSTATESBEFORERESET:
            cam.resetnext = True

        # either display at constant framerate (if zero display last frame)
        if (cam.framerate > 0
                and cam.f % cam.framerate == 0) or (cam.framerate == 0
                                                    and cam.resetnext):
            if TEST:
                img = cv2.imencode('.jpg', img)[1]
                frame = img.tostring()
                # yield (b'--frame\r\n'
                #       b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
            else:
                frame = np.flip(panarama.raw, axis=2)
                (h, w, _) = frame.shape
                im = Image.fromarray(frame)
                name = cams[0]['url'][:-22].split('/')[-1]
                dir = "/tmp/frame-" + name + ".jpeg"
                #im = im.resize((w, h*2), Image.ANTIALIAS)
                im.save(dir, quality=100)
                sp.check_call('gsutil -m mv -a public-read ' + dir +
                              ' gs://handy-contact-219622.appspot.com/frame-' +
                              name + '.jpeg',
                              shell=True)
Esempio n. 2
0
class Main:

    config_filename = 'config'
    cam = None
    parking_lot = None
    backend_notifier = None

    def __init__(self):

        # read config file
        config = configparser.ConfigParser()
        config.read(self.config_filename)
        refresh_in_seconds = 1

        # exit on unavailable config file
        if len(config) == 1:
            sys.exit("Config file not found or empty, please create ./%s" %
                     (self.config_filename))

        # exit if sections not present
        if 'default' not in config.sections():
            sys.exit("Default settings not found")

        refresh_in_seconds = int(config['default']['refresh_in_seconds'])
        # exit if sections not present
        if 'camera' not in config.sections():
            sys.exit("Camera settings not found")

        self.cam = Camera(config['camera'])

        # exit if sections not present
        if 'backend' not in config.sections():
            sys.exit("Backend settings not found")
        self.backend_notifier = BackendNotifier(config['backend'])

        # exit if sections not present
        if 'parking_lot' not in config.sections():
            sys.exit("Parking lot settings not found")

        self.parking_lot = ParkingLot(config['parking_lot'], self.cam)

        # write any changes to config
        with open(self.config_filename, 'w') as configfile:
            config.write(configfile)

        # Execute Main Loop
        self.execute(refresh_in_seconds)

    def execute(self, refresh_in_seconds):
        self.cam.start()
        frame_num = -1
        while (True):
            check, frame = self.cam.getNextFrame()
            frame_num += 1
            if (check and
                (frame_num %
                 (self.cam.fps * refresh_in_seconds) == 0 or frame_num == 0)):
                spots.find(frame, self.parking_lot)
                frame_small = cv2.resize(frame, (1280, 720))
                cv2.imshow('Free spots marked with green (press q to close)',
                           frame_small)
                if (frame_num % (self.cam.fps * 2) == 0):
                    self.backend_notifier.notifyAll(
                        self.parking_lot.parking_spots)
                    frame_num = 0
            if (cv2.waitKey(1) & 0xFF == ord('q')):
                break
        self.cam.stop()