Beispiel #1
0
 def __init__(self,
              name='Dual Webcam',
              camera1=1,
              camera2=3,
              x_resolution=720,
              y_resolution=480,
              timeout=10):
     self.name = name
     self.cam_left = Webcam('cam1', camera1, x_resolution, y_resolution)
     self.cam_right = Webcam('cam2', camera2, x_resolution, y_resolution)
     self.tryTimeOut = 10
Beispiel #2
0
    def __init__(self):

        # initialise webcams
        self.webcam_one = Webcam(0)
        self.webcam_two = Webcam(1)

        # initialise config
        self.config_provider = ConfigProvider()

        # initialise features
        self.features = Features(self.config_provider)

        # initialise texture
        self.texture_background = None
Beispiel #3
0
    def __init__(self,
                 height,
                 width,
                 n_inputs,
                 n_hidden,
                 n_outputs,
                 non_linearity,
                 device,
                 webcam=False):
        self.height = height
        self.width = width

        self.n_inputs = n_inputs
        self.n_hidden = n_hidden
        self.n_outputs = n_outputs
        self.non_linearity = non_linearity
        self.device = device

        self.network = Network(n_inputs, n_hidden, n_outputs, non_linearity)
        self.network.to(device)

        self.network_new = Network(n_inputs, n_hidden, n_outputs,
                                   non_linearity)
        self.network_new.to(device)

        self.sound = Sound()

        self.visualisation_input = self._create_visualisation_tensor()

        if webcam:
            self.webcam = Webcam()
            self.webcam.start()
Beispiel #4
0
 def __init__(self, btAddr):
     # init needed values
     self.btAddr = btAddr
     self.player = None
     self.texture_background = None
     self.set_ids = []
     self.set_players = []
     self.players = []
     self.calc_values()
     # initialise webcam and start thread
     self.webcam = Webcam()
     self.webcam.start()
     # connect wiimote and create model
     wiiModel = WiiModel.WiiModel(self.btAddr)
     # init openGl, Qt and Wiimote
     self.initOpenGL()
     self.initGUI()
     # run wiimote-connection-loop
     thread = threading.Thread(target=wiiModel.wiimoteLoop, args=(self.mainWindow, self.cursor))
     thread.start()
     # run opengl and camera in a thread
     thread = threading.Thread(target=glutMainLoop, args=())
     thread.start()
     # run Qt
     self.app.exec_()
Beispiel #5
0
    def _create_cameras(self):

        cameras = []

        for camera_number in range(self.config_provider.number_of_cameras):
            cameras.append(Webcam(camera_number))

        return cameras
 def __init__(self):
     self.cam = Webcam()
     self.textura_cam = 0
     self.ancho = 640
     self.alto = 480
     self.obj = None
     self.x = -5
     self.y = 0.1
Beispiel #7
0
    def __init__(self):
        # initialise webcam and start thread
        self.webcam = Webcam()
        self.webcam.start()

        # textures
        self.texture_background = None
        self.texture_cube = None
Beispiel #8
0
 def __init__(self):
     self.MU = Webcam()
     self.img_intensity = []
     self.img_time = []
     self.MU.start()
     self.filtered_average = []
     self.MU.register_callback(self._average_intensity, 1)
     self.img = []
     self.euclidean_dist = None
Beispiel #9
0
    def __init__(self):
        self.webcam = Webcam()
        self.webcam.start()

        self.glyphs = Glyphs()
        self.cone = None
        self.sphere = None

        self.texture_background = None
Beispiel #10
0
 def __init__(self):
     self.w = Webcam()
     self.start = self.w.start()
     self.im = self.w.grab_image()
     self.w.register_callback(self.average_intensity, 1)
     self.avg_intensity = []
     self.images = []
     self.filtered = []
     self.f, self.ax = plt.subplots(1, 1)
Beispiel #11
0
    def __init__(self):
        self.webcam = Webcam()
        self.webcam.start()

        self.detection = Detection()

        self.x_axis = 0.0
        self.y_axis = 0.0
        self.z_axis = 0.0
        self.z_pos = -7.0
Beispiel #12
0
    def __init__(self):
        self.webcam = Webcam()
        self.webcam.start()

        self.detection = Detection()

        self.x_axis = 0.0
        self.z_axis = 0.0
        self.show_cube = False
        self.texture_background = None
        self.texture_cube = None
 def __init__(self):
     self.webcam = Webcam()
     self.buffer_size = 40
     self.fps = 0
     self.times = []
     self.t0 = time.time()
     self.data_buffer = []
     #self.vidmag_frames = []
     self.frame_out = np.zeros((10, 10, 3), np.uint8)
     self.webcam.start()
     print("init")
Beispiel #14
0
def main():
    webcam = Webcam()
    webcam.start()
    mnp = MarkNplay()

    while True:
        image = webcam.get_current_frame()
        mnp.screen_thread(image)

        cv2.imshow('AR Book Reader', image)
        cv2.waitKey(10)
Beispiel #15
0
    def __init__(self):
        # initialise webcam and start thread
        self.webcam = Webcam()
        self.webcam.start()
 
        # initialise glyphs
        self.glyphs = Glyphs()
 
        # initialise shapes
        self.cone = None
        self.sphere = None
        # self.hp = HP()
        # initialise texture
        self.texture_background = None
Beispiel #16
0
 def __init__(self):
     super(GUI, self).__init__()
     self.initUI()
     self.webcam = Webcam()
     #self.video = Video()
     self.input = self.webcam
     self.dirname = ""
     print("Input: webcam")
     self.statusBar.showMessage("Input: webcam", 5000)
     self.process = Process()
     self.status = False
     self.frame = np.zeros((10, 10, 3), np.uint8)
     #self.plot = np.zeros((10,10,3),np.uint8)
     self.bpm = 0
Beispiel #17
0
    def __init__(self):
        #initialize the webcam
        self.camera = Webcam()

        #initialize optical debug mode
        self.opticalDebugMode = False

        #initialize the video window
        cv2.namedWindow(WIN_NAME, cv2.CV_WINDOW_AUTOSIZE)

        #start collecting frames for processing
        self.init_frames()

        #initialize Algorithm instance
        self.alg = Algorithm()
Beispiel #18
0
    def __init__(self):
        self._debug = conf['debug'] or False
        self._cv_debug = conf['cv_debug'] or False
        self.webcam = Webcam()
        self.tracker = Tracker()
        self.detector = FaceClassifier()
        self.last_tick = cv.getTickCount()
        self.got_face = False

        self.sample_stream = self.webcam.as_observable() \
            .sample(1000) \
            .do_action(lambda f: self._debug and print('sampled at {}'.format(datetime.now()))) \
            .map(self.detect) \
            .publish() \
            .auto_connect()
Beispiel #19
0
    def __init__(self):
        # sigint interrupt initialize
        signal.signal(signal.SIGINT, self.signal_handler)    

        # initialize webcam
        self.webcam = Webcam()
        self.webcam.start()
          
        self.x_axis = 0.0
        self.y_axis = 0.0
        self.z_axis = 0.0
        self.z_pos = -7.0
        
        self.win = 0
        self.texture_background = None
        self.texture_teapot = None
def take_imgs(chessboard_size=(11,7), kSaveImageDeltaTime=1):
    sys.path.append("../")
    os.makedirs("./calib_images", exist_ok=True)
    camera_num = 0
    if len(sys.argv) == 2:
            camera_num = int(sys.argv[1])
    print('opening camera: ', camera_num)

    webcam = Webcam(camera_num)
    webcam.start()
    
    lastSaveTime = time.time()
 
    while True:
        
        # get image from webcam
        image = webcam.get_current_frame()
        if image is not None: 

            # check if pattern found
            ret, corners = cv2.findChessboardCorners(cv2.cvtColor(image,cv2.COLOR_BGR2GRAY), chessboard_size, None)
        
            if ret == True:     
                print('found chessboard')
                # save image
                filename = datetime.now().strftime('%Y%m%d_%Hh%Mm%Ss%f') + '.bmp'
                image_path="./calib_images/" + filename
                
                elapsedTimeSinceLastSave = time.time() - lastSaveTime
                do_save = elapsedTimeSinceLastSave > kSaveImageDeltaTime
                print(elapsedTimeSinceLastSave, kSaveImageDeltaTime)
                if do_save:
                    lastSaveTime = time.time()
                    print('saving file ', image_path)
                    cv2.imwrite(image_path, image)

                # draw the corners
                image = cv2.drawChessboardCorners(image, chessboard_size, corners, ret)                       

            cv2.imshow('camera', image)                

        else: 
            pass
            #print('empty image')                
                            
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break    
    def __init__(self):
        if os.path.exists("data.json"):
            os.remove("data.json")

        super(GUI, self).__init__()
        self.initUI()
        self.webcam = Webcam()
        self.video = Video()
        self.input = self.webcam
        self.dirname = ""
        print("Input: webcam")
        self.statusBar.showMessage("Input: webcam", 5000)
        self.btnOpen.setEnabled(False)
        self.process = Process()
        self.status = False
        self.frame = np.zeros((10, 10, 3), np.uint8)
        #self.plot = np.zeros((10,10,3),np.uint8)
        self.bpm = 0
Beispiel #22
0
    def __init__(self, *args, **kwargs):
        super(Studio, self).__init__(*args, **kwargs)
        self.setupUi(self)

        # Device
        self.device_default = 0
        self.device = self.device_default

        # Webcam
        self.webcam = Webcam()

        # Image
        self.image_dir = 'outputs'
        self.image_ext = 'jpg'
        self.num_images_max_default = 10
        self.num_images_max = self.num_images_max_default
        self.num_images = 0

        self.saved_width_default = 416  # In pixel
        self.saved_height_default = 416
        self.saved_width = self.saved_width_default
        self.saved_height = self.saved_height_default

        self.flip_image = False
        self.cb_flip_image.stateChanged.connect(self.change_flip_image)

        # Filename prefix
        self.filename_prefix = 'class_memo'

        # Recording flag
        self.is_recording = False

        # Timer
        self.timer_is_on = False
        self.timer_duration = 500  # msec
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.process_image)

        # Plot min/max
        self.plot_min = 0.0
        self.plot_max = -1.0

        # Initialize
        self.initialize()
Beispiel #23
0
    def __init__(self):
        # initialise config
        self.config_provider = ConfigProvider()

        # initialise robots
        self.rocky_robot = RockyRobot()
        self.sporty_robot = SportyRobot()

        # initialise webcam
        self.webcam = Webcam()

        # initialise markers
        self.markers = Markers()
        self.markers_cache = None

        # initialise features
        self.features = Features(self.config_provider)

        # initialise texture
        self.texture_background = None
Beispiel #24
0
    def __start_record_clicked(self, widget):
        container_remove_all(self.under_camera_box)
        self.under_camera_box.pack_start(self.keep_few_minutes)

        self.webcam_align = gtk.Alignment(0, 0.5, 0, 0)
        self.webcam_align.set_padding(5, 5, 5, 5)
        if not hasattr(self.account_setting, "record_webcam"):
            self.account_setting.record_webcam = Webcam()
            self.account_setting.record_webcam.set_size_request(
                WEBCAM_SIZE, min(WEBCAM_SIZE, 240))
            self.account_setting.record_webcam.create_video_pipeline(320, 240)
        self.webcam_align.add(self.account_setting.record_webcam)
        container_remove_all(self.camera_box)
        self.camera_box.add(self.webcam_align)
        self.account_setting.record_webcam.play()
        gobject.timeout_add(2000, self.__do_save_photo, 0)
        gobject.timeout_add(2500, self.__do_save_photo, 1)
        gobject.timeout_add(3000, self.__do_save_photo, 2)
        gobject.timeout_add(3500, self.__do_save_photo, 3)

        gobject.timeout_add(4000, self.__do_action)
Beispiel #25
0
    def __init__(self):
        # initialise webcam and start thread
        self.webcam = Webcam()
        self.webcam.start()
        self.find = fp()
        self.find.set_img('sample.jpg')

        self.hei, self.wid = self.webcam.get_frame_shape()[:2]
        # initialise cube
        # self.d_obj = None
        self.img = None
        # initialise texture
        self.texture_background = None
        self.K = None
        self.mark_kp = None
        self.mark_des = None
        self.set_keypoint()
        self.new_kp = None

        self.mat_kp = None
        self.mat_des = None
        self.H = None
def real_time_lrp(conf):
    """Method to display feature relevance scores in real time.

    Args:
        conf: Dictionary consisting of configuration parameters.
    """
    record_video = conf["playback"]["record_video"]

    webcam = Webcam()
    lrp = RelevancePropagation(conf)

    if record_video:
        recorder = VideoRecorder(conf)

    while True:
        t0 = time.time()

        frame = webcam.get_frame()
        heatmap = lrp.run(frame)
        heatmap = post_processing(frame, heatmap, conf)
        cv2.imshow("LRP", heatmap)

        if record_video:
            recorder.record(heatmap)

        t1 = time.time()
        fps = 1.0 / (t1 - t0)
        print("{:.1f} FPS".format(fps))

        if cv2.waitKey(1) % 256 == 27:
            print("Escape pressed.")
            break

    if record_video:
        recorder.release()

    webcam.turn_off()
    cv2.destroyAllWindows()
Beispiel #27
0
#2D image points. If you change the image, you need to change vector
image_points = np.array(
    [
        (359, 391),  # Nose tip
        (399, 561),  # Chin
        (337, 297),  # Left eye left corner
        (513, 301),  # Right eye right corne
        (345, 465),  # Left Mouth corner
        (453, 469)  # Right mouth corner
    ],
    dtype="double")

# 2d points in image plane.

webcam = Webcam()
#webcam.start()


def draw(img, corners, imgpts):
    corner = tuple(corners[0].ravel())
    img = cv2.line(img, corner, tuple(imgpts[0].ravel()), (255, 0, 0), 5)
    img = cv2.line(img, corner, tuple(imgpts[1].ravel()), (0, 255, 0), 5)
    img = cv2.line(img, corner, tuple(imgpts[2].ravel()), (0, 0, 255), 5)
    return img


while True:

    # get image from webcam
    webcam.update_frame()
Beispiel #28
0
    "%.0f" % frame_width_meters, "%.0f" % DISTANCE_METERS))

# -- other values used in program
base_image = None
abs_chg = 0
mph = 0
secs = 0.0
ix, iy = -1, -1
fx, fy = -1, -1
drawing = False
setup_complete = False
tracking = False
text_on_image = 'No cars'
prompt = ''

webcam = Webcam("calibrated.avi", FPS)

# create an image window and place it in the upper left corner of the screen
cv2.namedWindow("Speed Camera")
cv2.moveWindow("Speed Camera", 10, 40)

# call the draw_rectangle routines when the mouse is used
cv2.setMouseCallback('Speed Camera', draw_rectangle)

# grab a reference image to use for drawing the monitored area's boundry
image = webcam.get_image()
org_image = image.copy()

if SAVE_CSV:
    csvfileout = "carspeed_{}.cvs".format(
        datetime.datetime.now().strftime("%Y%m%d_%H%M"))
from webcam import Webcam
import cv2
from datetime import datetime

# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001)

webcam = Webcam(1)
webcam.start()


def main():
    while True:

        #get the image
        image = webcam.get_current_frame()
        image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        cv2.imshow('grid', image)

        ret, corners = cv2.findChessboardCorners(
            image_gray, (9, 6), flags=cv2.cv.CV_CALIB_CB_ADAPTIVE_THRESH)

        if ret == True:
            print "found a chessboard"
            cv2.drawChessboardCorners(image, (9, 6), corners, ret)
            cv2.imshow('grid', image)

            corners2 = cv2.cornerSubPix(image_gray, corners, (11, 11),
                                        (-1, -1), criteria)
def main():
    try:

        camera_type = sys.argv[1]
        recording = False

        if len(sys.argv) == 3:
            if sys.argv[2] == "record":
                recording = True
            else:
                recording = False

        if camera_type == "webcam":

            collector = Webcam(video_width=640, video_height=480)
            collector.start()

        else:
            print("No such camera {camera_type}")
            collector = None
            exit(-1)

        if not os.path.isfile(MODEL_PATH):
            print("Downloading model, please wait...")
            download_file_from_google_drive(SOURCE, MODEL_PATH)
            print("Done downloading the model.")

        # get device
        device = torch.device(
            'cuda') if torch.cuda.is_available() else torch.device('cpu')
        # initialise model
        model = get_model_instance_segmentation(NUMBER_OF_CLASSES)
        model.load_state_dict(
            torch.load('./models/frcnn_hands.pth', map_location=device))
        model.to(device)
        model.eval()

        if recording:
            movie = cv2.VideoWriter(
                f'./recordings/hand_frcnn_{camera_type}.avi',
                cv2.VideoWriter_fourcc(*'DIVX'), 8, (640, 480))

        with torch.no_grad():

            while collector.started:

                image, _ = collector.read()

                if image is not None:

                    orig = image.copy()

                    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
                    image = transforms.ToTensor()(image).to(device)

                    out = model([image])

                    boxes = get_prediction(pred=out, threshold=.7)

                    try:

                        for box in boxes:
                            cv2.rectangle(img=orig,
                                          pt1=(box[0], box[1]),
                                          pt2=(box[2], box[3]),
                                          color=(0, 255, 255),
                                          thickness=2)

                        if recording:
                            movie.write(orig)

                        cv2.imshow("mask", orig)
                        k = cv2.waitKey(1)

                        if k == ord('q'):
                            collector.stop()

                    except Exception as e:
                        print(e)

    finally:
        print("Stopping stream.")
        collector.stop()
        if recording:
            movie.release()
        cv2.destroyAllWindows()