Exemplo n.º 1
0
def video_stream():
    def gen(camera):
        while True:
            frame = camera.get_frame()
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
    return Response(gen(Camera()), mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 2
0
def main():
    # Clear the screen
    subprocess.call('clear', shell=True)
    config_object = Config(os.getcwd() + '/config/config.ini').raw_config_object
    transport = UdpSocket(config_object)
    camera = Camera(config_object)

    if config_object['COMPRESSION']['switch'] == 'On':
        compressor = Compressor(config_object)
        transport.add_compression(compressor)

    if config_object['ENCRYPTION']['switch'] == 'On':
        # encryptor = Encryptor(config_object)
        # transport.add_encryption(encryptor)
        pass

    try:
        while True:
            time.sleep(float(config_object['QUALITY']['delay']))
            image = camera.get_frame()
            transport.send_data(image)

    except LookupError as e:
        print(e)
        sys.exit(2)

    except KeyboardInterrupt:
        print('keyboard interruption')
        sys.exit(1)
Exemplo n.º 3
0
    def __init__(self, url, id, token, save_record, default_mode):

        self.cam = Camera()
        self.detector = detector(self.cam)
        self.detector_thread = None
        self.save_record = save_record
        self.default_mode = default_mode
        self.running = False
        self.state = {
            "server": {
                "mode": default_mode
            },
            "client": {
                "mode": default_mode
            },
        }
        self.mode_change = False
        self.last_mode_check = 0
        self.save_path = "/dev/shm/"
        self.disk_space = {}

        self.url = url
        self.id = id
        self.token = token
        self.mask_image = (np.ones((100, 100)), 0, [])
    def __init__(self):
        threading.Thread.__init__(self)

        #MQTT IP for widefind
        self.broker_url = "130.240.114.24"
        self.broker_port = 1883

        #DATA must be sent inside an event object
        self.event = {}
        self.pos = {}

        self.ids = []

        self.debug = False

        self.person = [0, 0, 0]
        self.p1 = [0, 0, 0]
        #self.cameraRoof = [3141, -3812, 1220]
        self.camera = [3261, -3800, 740]
        self.cameraFloor = [3635, -4074, 418]

        # Object controlling the camera
        self.c = Camera()

        self.following = False
        self.rotation = 0

        self.client = mqtt.Client()
        self.client.on_connect = self.on_connect
        self.client.on_message = self.on_message
Exemplo n.º 5
0
 def __init__(self):
     Thread.__init__(self)
     self.camera = Camera()
     self.detector = Detector()
     self.stop_loop = False
     self.telemetry = Telemetry()
     self.position_calculator = PositionCalculator()
     self.frame = None
Exemplo n.º 6
0
 def __init__(self):
     self.distance = Echo()
     self.camera = Camera()
     self.imageMod = ImageMod()
     self.img = None
     self.cm = -1
     self.rec = ('None', 0)
     self.counter = 0
Exemplo n.º 7
0
    def __init__(self, mob, iterations=5, radius=10, alpha=30, camera=None):
        if camera is None:
            from camera.camera import Camera
            camera = Camera()
        arr = mob.get_binary_array()
        arr = ndimage.binary_dilation(
            arr,
            structure=circular_binary_structure(radius),
            iterations=iterations,
        )
        pixel_list = np.column_stack(np.where(arr == 1)).astype("float64")

        concave_hull = list(
            alpha_shape(pixel_list, alpha=alpha, only_outer=True))

        # sort edges
        for i, first in enumerate(concave_hull):
            loop = True
            for j, second in enumerate(concave_hull[i + 1:]):
                j += i + 1
                if first[1] == second[0]:
                    loop = False
                    concave_hull[i + 1], concave_hull[j] = \
                        concave_hull[j], concave_hull[i + 1]
            if loop and i != len(concave_hull) - 1:
                warnings.warn(
                    "the alpha shape in split into different parts. This can "
                    "be fixed by increasing alpha.")
                print(i, len(concave_hull))
                # breakpoint(context=9)
                pass

        temp = np.zeros((len(concave_hull) + 1, 2))
        for i, pair in enumerate(concave_hull):
            temp[i] = pixel_list[pair[0]]
        temp[-1] = pixel_list[concave_hull[0][0]]
        pixel_list = temp

        point_list = np.zeros((pixel_list.shape[0], pixel_list.shape[1] + 1))
        point_list[:,
                   0] = pixel_list[:,
                                   0] * camera.frame_height / camera.pixel_height
        point_list[:,
                   1] = -pixel_list[:,
                                    1] * camera.frame_width / camera.pixel_width

        # TODO: figure out optimal num_anchor_points
        ParametricFunction.__init__(
            self,
            lambda t, point_list=point_list: point_list[int(t)],
            t_min=0,
            t_max=len(point_list) - 1,
            scale_handle_to_anchor_distances_after_applying_functions=False,
        )
        self.move_to(mob.get_center())
Exemplo n.º 8
0
    def get_binary_array(self, camera=None):
        if camera is None:
            from camera.camera import Camera
            camera = Camera()
        camera.capture_mobject(self)

        camera.get_image().save("lmao.png")

        # why the transpose?
        arr = np.int16(np.all(camera.pixel_array[:, :, :3] == 0, axis=2)).T
        return arr
Exemplo n.º 9
0
    def add(self, model):

        if self.is_exist(model.manage_url):
            return False

        camera = Camera(model,
                        notifier=self.notifier,
                        object_detector_queue=self.object_detector_queue)
        camera.add_to_homekit(self.homekit_bridge)

        self.cameras[camera.id] = camera

        return camera
Exemplo n.º 10
0
 def __init__(self, config_path):
     self.config = configparser.ConfigParser()
     self.config.read(config_path)
     self.config_path = config_path
     self.instantiating_time = time.time()
     self.picture_interval = self.config['SCHEDULE'].getfloat('PictureInterval')
     self.start_time = self.convert_time_str(self.config['SCHEDULE'].get('StartTime'))
     self.end_time = self.convert_time_str(self.config['SCHEDULE'].get('EndTime')) - self.start_time
     self.w_capture = self.config['SCHEDULE'].get('WithCapture')
     self.w_prediction = self.config['SCHEDULE'].get('WithPrediction')
     self.buffer_time = self.config['SCHEDULE'].getint('PictureBufferTime')
     self.camera_output_dir = self.config['CAMERA'].get('CameraOutputDirectory')
     self.prediction_output_dir = self.config['PREDICTION'].get('PredictionOutputDirectory')
     self.compiler = Compiler(config_path)
     self.camera = Camera(config_path)
     self.schedule = sched.scheduler(time.time, time.sleep)
Exemplo n.º 11
0
def test():
    server = CameraServer()
    camera = Camera()
    tracker = ObjectTracker()

    def update(time):
        frame = camera.update()
        masked, pos, radius = tracker.find_object(frame, draw_circle=True)
        server.put_images(frame, masked)

    updater = Updater(0.01)
    updater.add(update)
    while updater.timer < 120:
        updater.update()

    server.stop()
Exemplo n.º 12
0
    def __init__(self):
        gpio = pigpio.pi()

        self.Color = Color(7)
        self.Distance = [Distance(2), Distance(3), Distance(0), Distance(1)]
        self.Gyroscope = Gyroscope('/dev/ttyAMA0')
        self.Temperature = [Temperature(i) for i in range(85, 89)]

        self.Camera = Camera()

        self.LedRed = Led(gpio, 20)
        self.LedYellow = Led(gpio, 21)

        self.LedRed.off()
        self.LedYellow.off()

        self.ButtonStart = Button(gpio, 9)
        self.ButtonStop = Button(gpio, 10)

        self.Motor = [Motor(19, 11, 26), Motor(13, 6, 5)]
        self.Servo = Servo(gpio, 12)

        self.Sensors = [
            self.Color, self.Distance, self.Gyroscope, self.Temperature
        ]
        self.Actuators = [self.LedRed, self.Servo]

        self.Maze = Maze(self.Sensors, self.Actuators, self.Camera)
        self.ActualX = self.Maze.StartX
        self.ActualY = self.Maze.StartY
        self.ActualZ = self.Maze.StartZ

        self.StartTime = 0
        self.StartHeading = 0

        self._stop()
Exemplo n.º 13
0
    def __init__(self):
        self.Serial = ArduinoSerial('/dev/ttyACM0', 115200)  # TODO: Riconoscere seriale

        self.Color = Color(self.Serial)
        self.Distance = [Distance(self.Serial, i) for i in range(1, 4)]
        self.Gyroscope = Gyroscope(self.Serial)
        self.Temperature = [Temperature(self.Serial, i) for i in range(1, 4)]

        self.Camera = Camera()

        self.Motor = Motor(self.Serial)
        self.Servo = Servo(self.Serial)

        self.Sensors = [self.Color, self.Distance, self.Gyroscope, self.Temperature]

        self.Maze = Maze(self.Sensors, self.Servo, self.Camera)
        self.ActualX = self.Maze.StartX
        self.ActualY = self.Maze.StartY
        self.ActualZ = self.Maze.StartZ

        self.StartTime = 0
        self.StartHeading = 0

        self.stop()
Exemplo n.º 14
0

"""
Module dependency initialization.
Creates an instance of each module used in the server
"""
# Database connection and ORM
db = SQLAlchemy()

# ORM Serializer
ma = Marshmallow()

# Machine Learning factory
ml = MLFactory()

# Camera factory
ca = Camera()

# Firebase Cloud Messaging service
fcm = FCM()

# Serial port connection
SERIAL_PORT = '/dev/ttyS0'
SERIAL_BAUDRATE = 9600
ser = None
try:
    ser = Serial(port=SERIAL_PORT, baudrate=SERIAL_BAUDRATE)
    print('Serial port opened successfully!')
except:
    print('\nSerial port failed to be opened!\n', file=sys.stderr)
Exemplo n.º 15
0
    if len(sys.argv) > 1:
        cfg = config.load(sys.argv[1])
    else:
        cfg = config.load("follow_person.yml")

    camera_id = int(cfg.getPropertyWithDefault("Camera", 0))

    network_model = cfg.getPropertyWithDefault(
        "Network.Model", 'ssdlite_mobilenet_v2_coco_2018_05_09_trt.pb')
    siamese_model = cfg.getPropertyWithDefault("Network.SiameseModel",
                                               'siamese_model.pb')
    mom_path = cfg.getPropertyWithDefault('Mom.ImagePath',
                                          'mom_img/sample_img.jpg')

    # # The camera does not need a dedicated thread, the callbacks have their owns.
    cam = Camera(camera_id)
    network = TrackingNetwork(network_model)
    network.setCamera(cam)

    siamese_network = SiameseNetwork(siamese_model, mom_path)

    follower = Follow_Person(network, siamese_network, cam)

    display_imgs = True

    while True:

        img = follower.follow()

        if display_imgs:
            cv2.imshow("RGB", img)
Exemplo n.º 16
0
def video_feed():
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 17
0
#yolo init
anchors = [
    8.0, 24.0, 8.0, 74.0, 13.0, 33.0, 20.0, 40.0, 23.0, 166.0, 24.0, 60.0,
    39.0, 69.0, 61.0, 114.0, 100.0, 200.0
]
anchors = np.array(anchors).reshape([-1, 3, 2])[::-1, :, :]
class_names = [
    "Car", "Van", 'Truck', 'Pedestrian', 'Person_sitting', 'Cyclist', 'Tram',
    'Misc'
]
yolo = YOLO(anchors=anchors, class_names=class_names)

#camera init
camera = Camera(
    'D:\\Project\\BarrierIdentificationWithMMW\\代码\\test_data\\video\\2020-09-02 16-48-36.mp4',
    pixel_size=(1280, 720))
camera_ratation = np.zeros((3), dtype=np.float)
camera_location = np.array((10, 10, 0.5), dtype=np.float)
camera2absolute_rotation_matrix = get_rotate_matrix(camera_ratation)

#coordinate
coordinate = Coordinate3D(actual_size=np.array((20, 20, 2)),
                          ratio=np.array((100, 100, 100)))

#radar init
radar = Radar(coordinate, '.\\utils\\can\\ControlCAN.dll')

#loop start
camera.start_camera_loop()
radar.start_update_loop()
    if ("stop" in transcription):
        print("Stop command recognized!")
        sensor.stop()

    #Two examples of easily recognizing transcript commands

    #This will trigger if the transcription contains the letters "example" in order, anywhere in the string
    #This is useful as if your speech is interpreted as "examples" it will trigger "example"
    #Might lead to unintended commands as some words can contain other words
    if ("example" in transcription):
        print("example command recognized! (partial match)")
        #Call function

    #This will only trigger if the transcription is exactly "example"
    #Might lead to problems if a string contains more words than just the command word(s) and if "example" is interpreted as "examples"
    if (transcription == "example"):
        print("example command recognized! (exact match)")
        #Call function


if __name__ == "__main__":
    # create recognizer and mic instances
    recognizer = sr.Recognizer()
    microphone = sr.Microphone()
    c = Camera()
    sensor = WidefindTracker()
    sensor.start()

    recordAudio(recognizer, microphone)
Exemplo n.º 19
0
from app.app import App
from camera.gopro_hero4_silver import GoProHero4Silver
from camera.camera import Camera

videos = ['videos/busstation.mp4', 'videos/india.mp4', 'videos/crosswalk.mp4']
input_video = videos[0]

# provide the video resolution and if available the horizontal (fov_x) and vertical (fov_y) field of view
cam = Camera(1280, 720)

# in case you have your own video and/or want to do some specific lens corrections
# input_video = 'videos/volley1.mp4'
# cam = GoProHero4Silver()

# in case you have a webcam you want to do something like this
# input_video = 0
# cam = Camera(960, 720, 90.0, 67.5)

class_list = 'models/classid.txt'
graph_definitions = 'models/frozen_inference_graph_ssdlite.pb'
# graph_definitions = 'models/frozen_inference_graph_mrcnn.pb'

app = App()
app.set_coco_data(graph_definitions, class_list)
app.set_capture_input(input_video, cam)
app.run()
Exemplo n.º 20
0
def video(request):

    return StreamingHttpResponse(
        gen(Camera()),
        content_type="multipart/x-mixed-replace; boundary=frame")
Exemplo n.º 21
0
 def __init__(self, results):
     super().__init__()
     print("DEBUG: CVProcess spawned")
     self.results = results
     self.camera = Camera(verbose=True)
     self.lane_recognizer = LaneRecognizer(self.camera)
Exemplo n.º 22
0
CC_EMAILS = CONFIG['MAIL']['CC_EMAILS'].split(',')
BCC_EMAILS = CONFIG['MAIL']['BCC_EMAILS'].split(',')
SUBJECT = CONFIG['MAIL']['SUBJECT']
BODY_TEMPLATE = CONFIG['MAIL']['BODY_TEMPLATE']

if not os.path.exists(CAMERA_CAPTURES_BASE_PATH):
    os.makedirs(CAMERA_CAPTURES_BASE_PATH)

if not os.path.exists(DETECTION_OUTPUT_BASE_PATH):
    os.makedirs(DETECTION_OUTPUT_BASE_PATH)

EXECUTION_PATH = os.getcwd()
print('Running application at ', EXECUTION_PATH)

print('Initializing Camera...')
CAMERA = Camera(camera_index=CAMERA_INDEX)
print('Camera initialized')

print('Loading object detection model...')
# Download this model from https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo.h5
OBJECT_DETECTOR = ObjectDetector(model_name=MODEL_NAME, model_path=MODEL_PATH)
print('Model loaded')

print('Initializing Mailer...')
MAILER = Mailer(smtp_server=SMTP_SERVER, smtp_port=SMTP_PORT)
MAILER.authenticate(username=USERNAME, password=PASSWORD)
print('Mailer initialized...')

IO.setwarnings(False)
IO.setmode(IO.BCM)
IO.setup(IR_PIN_NO, IO.IN)
Exemplo n.º 23
0

def estimate_silhouette(im):
    """
    因为图像数据是红色的,所有简单选取用红色通道大于其他两个通道的像素作为阴影轮廓
    :param im:
    :return:
    """
    return np.logical_and(im[:, :, 0] > im[:, :, 2], im[:, :, 0] > im[:, :, 1])


if __name__ == '__main__':
    estimate_better_bounds = True
    use_true_silhouette = True
    frames = sio.loadmat('../data/ps3/space_carving/frames.mat')['frames'][0]
    cameras = [Camera(x) for x in frames]

    # Generate the silhouettes based on a color heuristic
    if not use_true_silhouette:
        for i, c in enumerate(cameras):
            print(i)
            c.true_silhouette = c.silhouette
            c.silhouette = estimate_silhouette(c.image)
            if i == 0:
                plt.figure()
                plt.subplot(121)
                plt.imshow(c.true_silhouette, cmap='gray')
                plt.title('True Silhouette')
                plt.subplot(122)
                plt.imshow(c.silhouette, cmap='gray')
                plt.title('Estimated Silhouette')
Exemplo n.º 24
0
def run():
    # Initialize objects
    cam = Camera()
    print(cam.data())
Exemplo n.º 25
0
 def get_image(self, camera=None):
     if camera is None:
         from camera.camera import Camera
         camera = Camera()
     camera.capture_mobject(self)
     return camera.get_image()
Exemplo n.º 26
0
 def stack5UI(self):
     self.layout = QHBoxLayout()
     self.layout.addWidget(Camera())
     self.stack5.setLayout(self.layout)
Exemplo n.º 27
0
 def freeze_background(self):
     self.update_frame()
     self.set_camera(Camera(self.get_frame()))
     self.clear()
Exemplo n.º 28
0
import cv2
import numpy as np
import time
from camera.camera import Camera, CameraType
from camera.video import Video, Videos
from ImageProcessing.roadAnalyzer_birdeye import RoadAnalyzer
from client import start_connection_with_nxt
from communication.message import Message
from PIL import Image
SEND_PERIOD = 0.03  # time interval for data sent to nxt
SEND_ANGLE = True  # *for testing purposes*

#Set Up
#stream = Video(Videos.OBSTACLES)	# *for testing purposes*
stream = Camera(CameraType.PI)
roadAnalyzer = RoadAnalyzer()  # intialize Class

if SEND_ANGLE:
    com = start_connection_with_nxt()  # setup connection

# Read Captured camera feed
start = time.time()
while (True):

    frame = stream.getCurrentImage()

    # Image Processing

    drivingAngle, operation_flag, img_final = roadAnalyzer.getAngle(frame)

    # Display Images
Exemplo n.º 29
0
import sys
from PyQt4 import QtGui
from gui.gui import Gui
from gui.threadgui import ThreadGui
from camera.camera import Camera
from camera.threadcamera import ThreadCamera
import signal

signal.signal(signal.SIGINT, signal.SIG_DFL)

if __name__ == '__main__':

    camera = Camera()
    print(camera)
    app = QtGui.QApplication(sys.argv)
    window = Gui()
    window.setCamera(camera)
    window.show()

    t1 = ThreadCamera(camera)
    t1.start()

    t2 = ThreadGui(window)
    t2.start()

    sys.exit(app.exec_())
Exemplo n.º 30
0
 def loadCameraSystem(self):
     self.camera = Camera(self)
     self.camera.start()