Ejemplo n.º 1
0
def image(env):
    devname = dict(parse_qsl(env.get('QUERY_STRING', ''))).get('device')
    if not devname:
        return [('Content-Type', 'Image/jpeg'), ('Content-Lentgh', '0')], b''

    device_status = CAMERA_STATUS.get(devname, {})
    if device_status.get('in_use', False):
        data = device_status.get('data', b'')

    else:
        device_status['in_use'] =True
        CAMERA_STATUS[devname] = device_status
    
        imgpath = IMGPATH_TMPL % devname
        confpath = CONF_TMPL % devname
        conf = {'device': '/dev/' + devname, 'archive': imgpath, 'text': devname}
        write_webcam_config(conf, confpath)
        capture(confpath)
        with open(imgpath, mode='rb') as f:
            data = f.read()

        device_status['data'] = data
        device_status['in_use'] = False

    header = [('Content-Type', 'Image/jpeg'), ('Content-Length', str(len(data)))]
    return header, data
Ejemplo n.º 2
0
    def run_camera(self, devname, duration):
        finishtime = time() + duration

        while time() < finishtime:
            next = time() + self.setting.get('interval', 1)

            capture(self.confs[devname])
            print('Captured image with ' + devname)

            if next <= finishtime:
                now = time()
                if next - now > 0:
                    sleep(next - now)
            else:
                break
Ejemplo n.º 3
0
def take_training_photos(name, n):
    for i in range(n):
        for face in webcam.capture().faces():
            normalized = face.gray().scale(100, 100)

            face_path = 'training_images/{}'.format(name)
            ensure_dir_exists(face_path)
            normalized.save_to('{}/{}.pgm'.format(face_path, i + 1))

            normalized.show()
Ejemplo n.º 4
0
    def update_pixels(self, devname):
        if len(self.pxls[devname]) > 2:
            del(self.pxls[devname][2])
            os.rename(self.filenames[devname]['newest'], self.filenames[devname]['previous'])

        conffile = os.path.join(self.setting.get('tmpdir', '/run/shm'), devname + '.conf')
        conf = {
            'width': self.width,
            'height': self.height,
            'device': '/dev/' + devname,
            'archive': self.filenames[devname]['newest']
        }
        write_webcam_config(conf, conffile)
        capture(conffile)

        img = Image.open(self.filenames[devname]['newest'])
        pxs = [img.getpixel(cood) for cood in self.target_pixels]
        img.close()
        self.pxls[devname].insert(0, pxs)
def main(photo):
    get_photo.get_photo_func()
    if not photo:
        webcam.capture()
    paths = get_picture_paths()
    ordered_ids = [path.split('/')[1] for path in paths]
    results = facial_recog.face_recog(paths, 'filename.jpg')
    print(results)
    try:
        target = [
            ordered_ids[i].split('.')[0] for i in range(len(paths))
            if results[i]
        ][0]
    except:
        print('No one recgnized')
        return {'name': "No one recognized", 'id': "0"}
    graph = facebook.GraphAPI(access_token=ACCESS_TOKEN, version="3.0")
    target_info = graph.get_object(id=target)
    print(target_info)
    return target_info
Ejemplo n.º 6
0
def api(params):
    if params['source'] == 'webcam':
        import webcam
        scale = float(params['scale'])
        return webcam.capture(scale)

    if params['source'] == 'video':
        import sys
        import video
        scale = float(params['scale'])
        return video.capture(scale, sys.argv[1])

    if params['source'] == 'microphone':
        import microphone
        return microphone.capture(params['duration'])

    return
Ejemplo n.º 7
0
file1Ver = False
file2Ver = False
while applicationSwitch:
    title = 'Difference Checker'
    instruction = 'Please Capture image 1 and 2 then begin.'

    if file1Ver == False or file2Ver == False:
        buttons = ['Capture Image 1', 'Capture Image 2']
    else:
        buttons = ['Capture Image 1', 'Capture Image 2', 'Begin Application']

    selection = easygui.indexbox(msg=instruction, title=title, choices=buttons)

    if selection == 0:
        file_name1 = 'saved_img1.png'
        file1 = capture(file_name1)
        imageA = cv2.imread(file1)
        img1 = Image.open(file1)

        if img1 is None:
            easygui.msgbox("Please Try Again!")
        else:
            file1Ver = True
    elif selection == 1:
        file_name2 = 'saved_img2.png'
        file2 = capture(file_name2)
        imageB = cv2.imread(file2)
        img2 = Image.open(file2)
        if img2 is None:
            easygui.msgbox("Please Try Again!")
        else:
Ejemplo n.º 8
0
import cv2

import webcam
import face_detector

while True:
    frame = webcam.capture()

    face_detector.detect(frame)

    cv2.imshow('Video', frame)

    # Press Q to Exit
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

webcam.exit()