示例#1
0
def camstream():
    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode((1280, 960), 0)
    camera = pygame.camera.Camera(DEVICE, SIZE)
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    capture = True
    time.sleep(1)
    initial = camera.get_image(screen).copy()
    height = initial.get_height()
    width = initial.get_width()
    print(height)
    print(width)
    print(initial.get_at([0,0]))
    print(averagepix(initial))
    while capture:
        initial = camera.get_image(screen).copy()
        screen = camera.get_image(screen)
        screen = surfdiff(screen,initial)
        derr = pygame.transform.scale2x(pygame.transform.flip(screen.copy(),True,False))
        display.blit(derr,(5,5))
        pygame.display.flip()
        #pygame.display.update()
        for event in pygame.event.get():
            if event.type == QUIT:
                capture = False
            elif event.type == KEYDOWN and event.key == K_s:
                pygame.image.save(screen, FILENAME)
    camera.stop()
    pygame.quit()
    return
示例#2
0
def captureImage():

    global captureSoundSeq

    if (captureSoundSeq == 1):
        sdInit.play()
    if (captureSoundSeq == 2):
        sdConf.play()
    if (captureSoundSeq == 3):
        sdBegin.play()

    captureSoundSeq = captureSoundSeq + 1
    if (captureSoundSeq > 3):
        captureSoundSeq = 1

    camera = pygame.camera.Camera(DEVICE, (800, 480), "RGB")
    camera.start()
    sleep(.25)
    camGrab = camera.get_image()

    #create a new animation canvas
    animFrame = pygame.Surface(lastScreen.get_size())
    animFrame = animFrame.convert()
    pygame.draw.rect(animFrame, (0, 0, 0), (0, 0, 800, 480))
    lastScreen.blit(animFrame, (0, 0))

    capture = True
    camGrab = pygame.transform.flip(camGrab, False, True)

    while capture:
        if camera.query_image():
            captureSurface = camera.get_image()
        # flipping image
        captureSurface = pygame.transform.flip(captureSurface, False, True)
        display.blit(captureSurface, (0, 0))
        pygame.display.flip()

        if shutterButton.is_pressed:
            pygame.image.save(display, ("CapturedImages/" + photoFileName))
            shutterSound.play()

            flashFrame = pygame.Surface(lastScreen.get_size())
            flashFrame = flashFrame.convert()
            pygame.draw.rect(display, (255, 255, 255), (0, 0, 800, 480))
            pygame.display.flip()
            sleep(.25)
            capture = False

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                appRunning = False
                break
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    appRunning = False
                    break
    camera.stop()
    return
def main():
    camera = Camera()

    while True:
        camera.get_image(0)
        for i in range(0, 30):
            pygame.time.wait(100/30)
            camera.cycle_images()
示例#4
0
def camstream():
    pygame.init()
    clock = pygame.time.Clock()
    pygame.camera.init()

    pprint.pprint(pygame.camera.list_cameras())

    display = pygame.display.set_mode(screen_size, pygame.FULLSCREEN)
    camera = pygame.camera.Camera(DEVICE, camera_size)
    camera.start()

    actual_camera_size = camera.get_size()
    pprint.pprint(actual_camera_size)

    screen = pygame.surface.Surface(screen_size, 0, display)
    frame = pygame.surface.Surface(camera_size, 0, display)
    detect = pygame.surface.Surface(detect_size, 0, display)
    capture = True
    while capture:

        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == K_s:
                    capture = False
                elif event.type == KEYDOWN:
                    if event.key == K_s:
                        pygame.image.save(screen, FILENAME)
                    elif event.key == K_q:
                        capture = False
        if camera.query_image():
            camera.get_image(frame)

            pygame.transform.scale(frame, screen_size, screen)
            pygame.transform.flip(screen, True, False)
            # make a rect in the middle of the screen
            capture_rect = pygame.draw.rect(screen, (255, 255, 255),
                                            (390, 230, 20, 20), 1)
            # get the average color of the area inside the rect
            capture_colour = pygame.transform.average_color(
                screen, capture_rect)

            pygame.transform.scale(screen, detect_size, detect)
            pygame.transform.laplacian(detect, detect)
            # pygame.transform.threshold(detect, capture_colour, (90, 170, 170), (0, 0, 0), 2)

            display.blit(screen, (0, 0))

            # fill the upper left corner with that color
            display.fill(capture_colour, (0, 0, 24, 24))

            display.blit(detect, detect_origin)

        pygame.display.flip()
        dt = clock.tick(10)

    camera.stop()
    pygame.quit()
    return
示例#5
0
def ampilight():
    try:
        pixelArray = dotstar.DotStar(board.SCK,
                                     board.MOSI,
                                     X + 2 * Y,
                                     brightness=0.3,
                                     auto_write=False,
                                     baudrate=20000000)
        pixelArray.fill((0, 0, 0))

        pygame.init()
        pygame.camera.init()
        camera = pygame.camera.Camera(DEVICE, SIZE_CAPTURE)
        screen = pygame.surface.Surface(SIZE_CAPTURE)
        tiny = pygame.surface.Surface((10, 5))
        pixelMatrix = pygame.surface.Surface(SIZE_LED)

        camera.start()
        while True:
            camera.get_image(screen)
            pygame.transform.smoothscale(screen, (10, 5), tiny)
            pygame.transform.smoothscale(tiny, SIZE_LED, pixelMatrix)

            # right panel
            if True:
                idx = 0
                for y in range(Y - 1):
                    pixelArray[idx] = pixelMatrix.get_at(
                        (X - 1 - OFFSET, Y - 1 - y))[:3]
                    idx += 1

            # top panel
            if True:
                idx = 23
                for x in range(X):
                    pixelArray[idx] = pixelMatrix.get_at(
                        (X - 1 - x, OFFSET))[:3]
                    idx += 1

            # left panel
            if True:
                idx = 64
                for y in range(Y - 1):
                    pixelArray[idx] = pixelMatrix.get_at(
                        (0 + OFFSET, y + 1))[:3]
                    idx += 1

            pixelArray = blackLevelCorrection(pixelArray)
            pixelArray.show()

    finally:
        print('stopping ...')
        pixelArray.fill((0, 0, 0))
        camera.stop()
        pygame.quit()
    return
示例#6
0
def camstream():
    pygame.init()
    pygame.display.set_caption("อ่าน BARCODE & QRCODE จาก กล้องเว็บแคม USB")
    display = pygame.display.set_mode(SIZE0, 0, 24)

    f01 = pygame.font.Font("Garuda-Bold.ttf", 12)

    pygame.camera.init()
    camera = pygame.camera.Camera(DEVICE0, SIZECAM)
    camera.start()
    surfcam = pygame.surface.Surface(SIZECAM, depth=24)

    FPS = 25
    clock = pygame.time.Clock()
    running = True
    while running:
        camera.get_image(surfcam)
        display.blit(surfcam, (0, 0))

        xrect1 = pygame.Rect(0, CAMH, CAMW, 20)
        pygame.draw.rect(display, xcolor[0], xrect1)
        msgcam = "คลิกซ้าย..อ่าน BARCODE   คลิกขวา..อ่าน QRCODE"
        display.blit(f01.render(msgcam, True, xcolor[1]), (10, CAMH))

        pygame.display.flip()

        for event in pygame.event.get():
            #event quit
            if event.type == QUIT:
                running = False
            elif event.type == KEYDOWN and event.key == K_q:
                running = False

            elif event.type == pygame.MOUSEBUTTONDOWN:
                #[1=Lclick 3=Rclick  2=Mclick  4=ScrUp 5=ScrDN]
                if (event.button == 1):  #event zbar
                    ximgndarray = getimg_ndarray(surfcam)
                    xrtns = convzbar(ximgndarray)
                if (event.button == 3):  #event zbarlight
                    xfile = 'filecam.png'
                    pygame.image.save(surfcam, xfile)
                    xrtns = convzbarlight(xfile)

                display.blit(surfcam, (CAMW, 0))
                xrect2 = pygame.Rect(CAMW, CAMH, CAMW, 20)
                pygame.draw.rect(display, xcolor[2], xrect2)
                msgzbar = xrtns[0]
                display.blit(f01.render(msgzbar, True, xcolor[0]),
                             (CAMW + 10, CAMH))

        pygame.display.flip()
        clock.tick(FPS)

    camera.stop()
    pygame.quit()
    return
示例#7
0
def main():
    parser = ArgParser(SIZE[0], SIZE[1])
    X1, Y1, X2, Y2 = 0, 0, SIZE[0], SIZE[1]
    try:
        X1, Y1, X2, Y2 = parser.parse()
    except IncorrectArgumentsException as e:
        print("ERROR: ", e)
        end()

    camera = tryInitCamera()
    pygame.event.set_allowed([KEYDOWN])

    display = pygame.display.set_mode(SIZE, 0)

    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    capture = True

    prev2 = None
    prev2Part = None
    prev = camera.get_image().convert()
    prevPart = toGrayscale(prev, tl=(X1, Y1), br=(X2, Y2))
    curr = camera.get_image().convert()
    currPart = toGrayscale(curr, tl=(X1, Y1), br=(X2, Y2))

    file = open("../results/pg_times.csv", "a")
    size = (X2 - X1) * (Y2 - Y1)

    i = 0
    while i < frames:
        i += 1
        prev2 = prev
        prev2Part = prevPart
        prev = curr
        prevPart = currPart
        curr = camera.get_image().convert()

        start_time = time.clock_gettime(CPUTIME)
        currPart = toGrayscale(curr, tl=(X1, Y1), br=(X2, Y2))
        diff = diffImg(prev2Part, prevPart, currPart, tl=(X1, Y1), br=(X2, Y2))
        end_time = time.clock_gettime(CPUTIME)

        elapsed = end_time - start_time
        file.write(str(size) + ", " + str(round(elapsed * 1000000000)) + "\n")

        frame = copy(curr)
        frame.blit(diff, (X1, Y1))
        display.blit(frame, (0, 0))
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == KEYDOWN and event.key == K_q:
                capture = False
                break
    file.close()
    end(camera)
示例#8
0
def camstream():
    '''
    The bulk of the camera code was not written by us, since it's just here for fun
    and does not contribute to the actual game in any meaningful way.
    We use this to make a avatar for the user on the fly
    modified from https://gist.github.com/snim2/255151
    works only in linux, or by installing some dependency in windows [not tested]
    '''
    try:
        DEVICE = '/dev/video0'
        SIZE = (640, 480)
        FILENAME = 'assets/avatar.png'
        import pygame.camera
        pygame.camera.init()
        display = pygame.display.set_mode((800, 60 * 8), 0)
        camera = pygame.camera.Camera(DEVICE, SIZE)
        camera.start()
        screen = pygame.surface.Surface(SIZE, 0, display)
        screen = camera.get_image(screen)
        pygame.image.save(screen, FILENAME)
        camera.stop()
        return
    except:
        # if camera fails to take a picture, use backup generic avatar
        from shutil import copyfile
        copyfile('assets/backupavatar.png', 'assets/avatar.png')
def camstream():
    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode(SIZE, 0)
    #try to go fullscreen
    #display = pygame.display.set_mode((1920,1080),pygame.FULLSCREEN)
    #does bot work due to resolution limit?

    #hide mouse
    pygame.mouse.set_visible(0)

    camera = pygame.camera.Camera(DEVICE, SIZE, "HSV")
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    capture = True
    while capture:
        screen = camera.get_image(screen)
        display.blit(screen, (0, 0))
        pygame.display.flip()
        #this is for capturing an image
        for event in pygame.event.get():
            if event.type == QUIT:
                capture = False
            elif event.type == KEYDOWN and event.key == K_s:
                pygame.image.save(screen, FILENAME)
    camera.stop()
    pygame.quit()
    return
示例#10
0
 def getimage(camera, screen):
     scrncap = camera.get_image(screen)
     l.acquire()
     pygame.image.save(scrncap, 'emotion.jpg')
     image = cv2.imread('emotion.jpg')
     l.release()
     return image
示例#11
0
def main():
    countdown = 10
    lastFaceCount = 0
    while True:
        clock.tick(60)

        for event in pygame.event.get():
            if event.type in (pygame.QUIT, pygame.KEYDOWN):
                return

        capture = camera.get_image()
        faces, capture_data = find_faces(capture)
        for bbox in faces:
            rect = pygame.Rect(bbox.left(), bbox.top(), bbox.width(),
                               bbox.height())
            pygame.draw.rect(capture, (255, 0, 0), rect, 2)

        capture = pygame.transform.flip(capture, True, False)
        screen.blit(pygame.transform.smoothscale(capture, screen.get_size()),
                    (0, 0))

        if len(faces) == 0 or len(faces) != lastFaceCount:
            countdown = 10
            lastFaceCount = len(faces)
        elif countdown == 0:
            recognize(capture_data, faces)
            countdown = 10
        else:
            screen.blit(write(countdown), (0, 0))
            countdown -= 1

        pygame.display.flip()

    pygame.quit()
示例#12
0
 def jalankanKamera(self):
     DEVICE = '/dev/video0'
     SIZE = (640,480)
     FILENAME = 'capture'+str(self.penghitung)+'.png'
     pygame.init()
     pygame.camera.init()
     display = pygame.display.set_mode(SIZE, 0)
     camera = pygame.camera.Camera(DEVICE, SIZE)
     camera.start()
     screen = pygame.surface.Surface(SIZE, 0, display)
     pygame.display.set_caption("Kamera Gabut qywok")
     capture = True
     while capture:
         screen = camera.get_image(screen)
         display.blit(screen, (0,0))
         pygame.display.flip()
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 capture = False
             elif event.type == pygame.KEYDOWN and event.key == K_SPACE:
                 pygame.image.save(screen, FILENAME)
                 camera.stop()
                 pygame.quit()
                 self.isi.set('Mulai Lagi')
                 self.ucapan.set("Selamat...!! gambar anda telah tersimpan...\n"
                                     "dengan nama 'capture"+str(self.penghitung)+".png' silahkan di cek di \n"
                                     "folder tempat anda menyimpan file python nya..\n"
                                     "Untuk memulai untuk memotret lagi, silahkan tekan\n"
                                     "tombol 'mulai lagi' dan ingat tekan tombol 'spasi'\n"
                                     "untuk mengambil gambar.")
                 self.penghitung+=1
                 return
     camera.stop()
     pygame.quit()
     return
示例#13
0
文件: luke.py 项目: tobiascz/luke
def camstream():
    global capture
    global distance
    global distdelay
    global elwidth
    global elheight
    global formoverlay
    global area
    global distance_glob
    global pictureVar
    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode(SIZE, 0)
    camera = pygame.camera.Camera(DEVICE, SIZE)
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    pygame.mouse.set_visible(0)
    thread = Thread(target=rotaryThread)
    thread.start()
    while capture:
        if (not pictureVar):
            frame = camera.get_image(screen)
            frame = modFrame(frame)
            if (formoverlay == 1):
                pygame.draw.ellipse(frame, BLACK, [
                    80 - (elwidth / 2), 64 - (elheight / 2), elwidth, elheight
                ], 3)
            if (formoverlay == 2):
                pygame.draw.rect(frame, BLACK, [
                    80 - (elwidth / 2), 64 - (elheight / 2), elwidth, elheight
                ], 3)
            frame = pygame.transform.rotozoom(frame, 270, 0.8)
            display.fill((0, 0, 0))
            display.blit(frame, (0, 0))
            if (distdelay > 10):
                #distance = round(distanz(), 0)
                thread2 = Thread(target=distanz)
                thread2.start()
                distdelay = 0
                if (formoverlay == 2):
                    area = calc_area_rect(distance_glob, elwidth, elheight)
                elif (formoverlay == 1):
                    area = calc_area_ellipse(distance_glob, elwidth, elheight)
            distdelay = distdelay + 1

            displaytext("Dist: " + str(distance_glob), 18, 3, (250, 100, 100),
                        False, display)
            displaytext("Area: " + str(area), 25, 1, (250, 100, 100), False,
                        display)
            pygame.display.flip()
            for event in pygame.event.get():
                handle(event)
        else:
            displaytext("Saved", 18, 2, (0, 0, 0), False, display)
            pygame.display.flip()

    camera.stop()
    pygame.quit()
    GPIO.cleanup()
    return
示例#14
0
def camstream():
    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode(SIZE, 0)
    camera = pygame.camera.Camera(DEVICE, SIZE)
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    capture = True
    while capture:
        screen = camera.get_image(screen)
        display.blit(screen, (0, 0))
        pygame.display.flip()
        string = pygame.image.tostring(screen, "RGBA", False)
        image = Image.frombytes("RGBA", SIZE, string)
        codes = zbarlight.scan_codes('qrcode', image)
        if codes:
            print('QR codes: %s' % codes[0])
        for event in pygame.event.get():
            if event.type == QUIT:
                capture = False
            elif event.type == KEYDOWN and event.key == K_s:
                pygame.image.save(screen, FILENAME)
                print("saved")
    camera.stop()
    pygame.quit()
    return
示例#15
0
    def do_scan(self):
        display = pygame.display.set_mode(self.videosize, 0)
        pygame.display.iconify()
        camera = pygame.camera.Camera(self.camera, self.videosize)
        camera.start()
        screen = pygame.surface.Surface(self.videosize, 0, display)
        Locked = True

        while Locked:
            img = camera.get_image(screen)
            pygame.image.save(img, repertoire_script + 'data{}image.jpg'.format(os.sep))
            img = Image.open(repertoire_script + 'data{}image.jpg'.format(os.sep))
            codes = pyzbar.decode(img)
            if len(codes) > 0:
                Locked = False
            text = pytesseract.image_to_string(Image.open(repertoire_script + 'data{}image.jpg'.format(os.sep)))
            if len(text) > 0:
                Locked = False
            time.sleep(2)
        os.remove(repertoire_script + 'data{}image.jpg'.format(os.sep))
        camera.stop()

        for l in codes:
            donnees = l.data.decode('utf-8')
            print(_('Données du code: {}'.format(donnees)))
        donnees = '{}\n{}'.format(donnees, text)
        try:
            pyperclip.copy(donnees)
        except:
            if self.debug:
                print(_('Impossible de copier le texte.'))

        self.destroy()
示例#16
0
    def __init__(self, nombre):
        FILENAME = str(nombre)
        DEVICE = '/dev/video0'
        SIZE = (640, 480)
        pygame.init()
        pygame.camera.init()
        display = pygame.display.set_mode(SIZE, 0)
        camera = pygame.camera.Camera(DEVICE, SIZE)
        camera.start()
        screen = pygame.surface.Surface(SIZE, 0, display)
        capture = True
        while capture:
            screen = camera.get_image(screen)
            display.blit(screen, (0, 0))
            pygame.display.flip()
            for event in pygame.event.get():
                if event.type == KEYDOWN and event.key == K_s:
                    os.chdir("imagenes")
                    print("guardado")
                    pygame.image.save(screen, FILENAME)
                    os.chdir("..")
                    capture = False

        camera.stop()
        pygame.quit()
        return
示例#17
0
    def capture_image_pygame(self, camera_path: str, image_path: str) -> None:
        """Captures an image with pygame."""
        self.logger.debug("Capturing image from camera: {}".format(camera_path))

        # Capture image
        try:

            # Check if simulated
            # if self.simulate:
            #     message = "Simulating capture, saving image to: {}".format(image_path)
            #     self.logger.info(message)
            #     command = "cp {} {}".format(self.SIMULATION_IMAGE_PATH, image_path)
            #     os.system(command)
            #     return

            # Capture and save image
            if not self._simulate_capture(image_path):
                resolution_array = self.resolution.split("x")
                resolution = (int(resolution_array[0]), int(resolution_array[1]))
                camera = pygame.camera.Camera(camera_path, resolution)
                camera.start()
                image = camera.get_image()
                pygame.image.save(image, image_path)
                camera.stop()

        except Exception as e:
            raise exceptions.CaptureImageError(logger=self.logger) from e
示例#18
0
def cam_run(threadName, delay):
    index = 0
    while True:
        #time.sleep(delay)
        global screen
        screen = camera.get_image(screen)
        display.blit(screen, (0, 0))
        pygame.display.flip()
        pygame.display.update()
        global state
        if int(state) == 0:
            pygame.image.save(screen, 'thanh' + str(index) + '.jpg')
            state = 1
            global graph
            with graph.as_default():
                path = 'thanh' + str(index) + '.jpg'
                print path
                img = cv2.imread(path, 0)
                ret, thresh = cv2.threshold(img, 100, 255, cv2.THRESH_TOZERO)
                median = cv2.medianBlur(thresh, 3)
                cv2.imwrite(path, median)
                out_1, out_2 = predict(model, path)
                print out_1
                if out_2[0] == 0:
                    print 'NG'
                elif out_2[0] == 1:
                    print 'OK'
                elif out_2[0] == 2:
                    print 'COLOR'
                else:
                    print 'BARI'

            index += 1
示例#19
0
def anaoshots(number, fid, rid, lid, eid, camera_frame_rate):
    # initialize
    pygame.init()
    pygame.camera.init()
    # capture a image
    camera = pygame.camera.Camera("/dev/video0", (640, 480))
    camera.start()
    print("open camera success")
    c = 1
    starttime = time.time()
    while c <= number:  # 循环读取视频帧
        image = camera.get_image()
        pygame.image.save(
            image,
            r'../../data/test_data/' + os.listdir('../../data/test_data/')[0] +
            '/' + fid + '_' + rid + '_' + lid + '_' + eid + '_' + eid + '1_' +
            str(time.time()) + '.jpg')
        print('save the image', c)
        print(time.time() - starttime)
        c += 1
        usetime = time.time() - starttime

        # sleeptime = separatedtime * c - usetime
        #if sleeptime > 0: time.sleep(sleeptime)
    print('采集结束')
    camera.stop()
示例#20
0
def camstream():
    DEVICE = '/dev/video0'
    SIZE = (640, 480)
    FILENAME = 'capture.png'
    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode(SIZE, 0)
    camera = pygame.camera.Camera(DEVICE, SIZE)
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    capture = True
    while capture:
        screen = camera.get_image(screen)
        pil_string_image = pygame.image.tostring(screen,"RGBA",False)
        im=Image.frombytes("RGBA",(640,480),pil_string_image)
        im.show()
        time.sleep(0.5)
        im.close()
        display.blit(screen, (0,0))
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == QUIT:
                capture = False
            elif event.type == KEYDOWN and event.key == K_s:
                pygame.image.save(screen, FILENAME)
    camera.stop()
    pygame.quit()
    return
示例#21
0
文件: av.py 项目: bbcrd/guild
    def gen_process(self):
        device = "/dev/video0"

        capturesize = vidsize
        camera = pygame.camera.Camera(device, capturesize)
        camera.start()
        count = 0
        ts = time.time()
        print("START")
        while True:
            time.sleep(0.02)
            yield 1
            count += 1
            snapshot = camera.get_image()
            now = time.time()
            try:
                self.produce(snapshot, now)
            except:
                pass
            if count > 30:
                print(ts, time.time(), "Count", count, end="")
                dur = time.time() - ts
                if dur > 0:
                    print("RATE: ", count / (time.time() - ts))
                count = 0
                ts = time.time()
示例#22
0
def get_current_image_fast( camera ):
    if picamera_available == True:
        camera.capture('/tmp/photobooth_curcam.jpg', format='jpeg', resize=(WIDTH,HEIGHT))
	return pygame.image.load('/tmp/photobooth_curcam.jpg')
    else:
        return camera.get_image()
    return
示例#23
0
    def process_cam(self, thread_name):
        DEVICE = 0
        SIZE = (640, 480)
        FILENAME = 'capture.png'
        finished_flag = False
        cam = pygame.camera.Camera(DEVICE, SIZE)
        cam.resolution = (self.conf.cam_res_x, self.conf.cam_res_y)
        cam.framerate = self.conf.cam_fps
        # raw_capture = PiRGBArray(cam, size=(self.conf.cam_res_x, self.conf.cam_res_y))
        screen = pygame.surface.Surface(SIZE, 0, display)
        raw_capture = camera.get_image(self.screen)

        def _resize(image):
            r = 320.0 / image.shape[1]
            dim = (100, int(image.shape[0] * r))
            resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
            cv2.imwrite(self.conf.saved_data_folder + "/currently_displayed_resized.jpg", resized)

        def _get_cam_img():
            global CAM_IMG, EXIT_FLAG
            cam.get_buffer()
            for frame in cam.get_buffer():
                # for frame in cam.capture_continuous(raw_capture, format="bgr", use_video_port=True):
                image_from_cam = frame.array
                cv2.imwrite(self.conf.saved_data_folder + "/currently_displayed.jpg", image_from_cam)
                # _resize(image_from_cam)
                # cv2.waitKey(0)
                raw_capture.truncate(0)
                CAM_IMG = pygame.image.load(self.conf.saved_data_folder + "/currently_displayed.jpg")
                break

        while not finished_flag:
            if EXIT_FLAG:
                self.name.exit()
            _get_cam_img()
示例#24
0
def camstream():
    count = 0
    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode(SIZE, 0)
    camera = pygame.camera.Camera(DEVICE, SIZE)
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)

    capture = True
    while capture:
        screen = camera.get_image(screen)
        display.blit(screen, (0,0))
        pygame.display.flip()
        pygame.time.wait(100)
        pygame.image.save(screen, "frame%d.jpg" % count)
        count += 1
        if count > 20:
            break


        # for event in pygame.event.get():
        #     if event.type == QUIT:
        #         capture = False
        #     elif event.type == KEYDOWN and event.key == K_x:
        #         pygame.image.save(screen, "frame%d.jpg" % count)
        #         count += 1
    camera.stop()
    pygame.quit()
    return
示例#25
0
def read_QR(camera):
    # Take input from camera
    img = camera.get_image()
    # Save camera input to file
    pygame.image.save(img, CAMERA_VIEW_FILE)

    return decode_QR(CAMERA_VIEW_FILE)
示例#26
0
def get_current_image_fast( camera ):
    if picamera_available == True:
        camera.capture('/tmp/photobooth_curcam.jpg', format='jpeg', resize=(WIDTH,HEIGHT))
	return pygame.image.load('/tmp/photobooth_curcam.jpg')
    else:
        return camera.get_image()
    return
示例#27
0
文件: kural.py 项目: abisekrk/Kural
def capture_images():

    DEVICE = '/dev/video0'
    SIZE = (640, 480)
    FILENAME = '/media/abisek/Important Files/R.K/++/Machine Learning/Projects/K/captures/capturetest'

    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode(SIZE, 0)
    camera = pygame.camera.Camera(DEVICE, SIZE)
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    capture = True
    count = 0
    while capture:
        screen = camera.get_image(screen)
        display.blit(screen, (0, 0))
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == KEYDOWN and event.key == 113:
                capture = False
            elif event.type == KEYDOWN and event.key == 97:
                pygame.image.save(screen, FILENAME + str(count) + '.jpg')
                count += 1
    camera.stop()
    pygame.quit()
def camstream():
    bluetoothSerial = serial.Serial("/dev/rfcomm0", baudrate=9600)
    pygame.init()
    pygame.camera.init()

    DEVICE = pygame.camera.list_cameras()
    SIZE = (640, 480)
    FILENAME = 'capture.png'

    display = pygame.display.set_mode(SIZE, 0)
    camera = pygame.camera.Camera(DEVICE[0], SIZE)
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    capture = True
    while capture:
        screen = camera.get_image(screen)
        display.blit(screen, (0, 0))
        pygame.display.flip()
        isStealed = bluetoothSerial.readline().decode("utf-8")
        #for event in pygame.event.get():
        #    if event.type == QUIT:
        #        capture = False
        #    elif event.type == KEYDOWN and event.key == K_s:
        #        pygame.image.save(screen, FILENAME)
        if isStealed == "1111" or "2222" or "3333" or "4444" or "5555" or "6666" or "7777":
            pygame.image.save(screen, FILENAME)
    camera.stop()
    pygame.quit()
    return
示例#29
0
def camstream():
    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode(SIZE, 0)
    camera = pygame.camera.Camera(DEVICE, SIZE)
    camera.start()
    screen = pygame.surface.Surface(SIZE, 0, display)
    capture = True
    while capture:
        screen = camera.get_image(screen)
        display.blit(screen, (0,0))
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == QUIT:
                capture = False
            elif event.type == KEYDOWN:
                im = pygame.image.save(screen, FILENAME)
                camera.stop()
                pygame.quit()
                capture = False
                Button_Example()

    camera.stop()
    pygame.quit()
    return
示例#30
0
def scan_code(device, size):
    pygame.init()
    pygame.camera.init()
    display = pygame.display.set_mode(size, 0)
    pygame.display.set_caption("Scan QR-code here")
    camera = pygame.camera.Camera(device, size)
    camera.start()
    screen = pygame.surface.Surface(size, 0, display)
    capture = True
    while capture:
        screen = camera.get_image(screen)
        display.blit(screen, (0, 0))
        pygame.display.flip()
        string = pygame.image.tostring(screen, "RGBA", False)
        image = Image.frombytes("RGBA", size, string)
        codes = zbarlight.scan_codes('qrcode', image)
        if codes:
            code = codes[0]
            capture = False
        for event in pygame.event.get():
            if event.type == QUIT:
                capture = False
    camera.stop()
    pygame.quit()
    code = str(code)
    code = code[2:len(code) - 1]
    return code
示例#31
0
文件: av.py 项目: ucontent/guild
    def gen_process(self):
        device = "/dev/video0"

        capturesize = vidsize
        camera = pygame.camera.Camera(device, capturesize)
        camera.start()
        count = 0
        ts = time.time()
        print("START")
        while True:
            time.sleep(0.02)
            yield 1
            count += 1
            snapshot = camera.get_image()
            now = time.time()
            try:
                self.produce(snapshot, now)
            except:
                pass
            if count > 30:
                print(ts, time.time(), "Count", count, end="")
                dur = time.time() - ts
                if dur > 0:
                    print("RATE: ", count / (time.time() - ts))
                count = 0
                ts = time.time()
示例#32
0
 def gen_process(self):
     camera = pygame.camera.Camera(pygame.camera.list_cameras()[0])
     camera.start()
     while True:
         yield 1
         frame = camera.get_image()
         self.output(frame)
         time.sleep(1.0 / 50)
def capture_image(): 
    camera.start()
    pygame_surface = camera.get_image()
    camera.stop()

    pil_string_image = pygame.image.tostring(pygame_surface, 'RGB', False)
    image = Image.frombytes('RGB', (CANVAS_WIDTH, CANVAS_HEIGHT), pil_string_image)
    return image
示例#34
0
 def gen_process(self):
     camera = pygame.camera.Camera(pygame.camera.list_cameras()[0])
     camera.start()
     while True:
         yield 1
         frame = camera.get_image()
         self.output(frame)
         time.sleep(1.0 / 50)
示例#35
0
def get_current_image_as_jpg( camera, filename ):
    if picamera_available == True:
        #camera.start_preview()
        camera.capture(filename, format='jpeg', resize=(WIDTH,HEIGHT))
        #camera.stop_preview()
    else:
        img = camera.get_image()
        pygame.image.save(img,filename)
    return
示例#36
0
def get_current_image_as_jpg( camera, filename ):
    if picamera_available == True:
        camera.start_preview()
        camera.capture(filename, format='jpeg', resize=(WIDTH,HEIGHT))
        camera.stop_preview()
    else:
        img = camera.get_image()
        pygame.image.save(img,filename)
    return
示例#37
0
def rangeMeasure():
    pic = camera.get_image(screen)
    #truncate
    #pic=pic[0:10,0:10]
    #may need to save/open/and turn gray
    text = pytesseract.image_to_string(pic)
    #text = sevenSeg.measure(pic)

    print text
    standoff = text
示例#38
0
	def image_post(self):
		print "Capturing photo."
		client = dropbox.client.DropboxClient(access_token)
		filename = 'led_str-' + str(uuid.uuid4()) + '.jpg'
		for x in range(0,4):
			img = camera.get_image()
		pygame.image.save(img, directory + filename)
		f = open(directory + filename, 'rb')
		db_file_name = '/' + filename
		response = client.put_file(db_file_name, f)
		share_url = client.media(db_file_name)
		return share_url['url']
def show_camera_until(button):
    global screen
    font = pygame.font.Font(None, 36)
    text = font.render(u"Zum Loslegen: Roten Knopf drücken.", True, (128, 128, 128))
    #screen = init_pygame()
    pixel_width = 1024
    pixel_height = 768
    camera = pygame.camera.Camera("/dev/video0",(pixel_width,pixel_height))
    camera.start()
    while GPIO.input(button) == GPIO.HIGH:
      image = camera.get_image()
      screen.blit(image,(offset_x,offset_y))
      screen.blit(text,(512 - text.get_width() // 2, 384 - text.get_height() // 2))
      pygame.display.flip()
      sleep(0.0001)
    camera.stop()
def main():
	#init game, camera, display
	pygame.init()
	leckerli_font = pygame.font.Font("fonts/LeckerliOne-Regular.ttf", 35)
	anon_font	  = pygame.font.Font('fonts/slkscr.ttf', 15)
	anon_font_bold= pygame.font.Font('fonts/slkscrb.ttf', 15)
	pygame.camera.init()
	infoObject = pygame.display.Info()
	#SIZE = (infoObject.current_w, infoObject.current_h)
	screen = pygame.display.set_mode(SIZE, 0)#FULLsurface)
	camera = pygame.camera.Camera(DEVICE, CAMERA_SIZE)
	camera.start()
	#initialize surfaces
	camera_surface = pygame.surface.Surface(CAMERA_SIZE, 0, screen)
	chat_surface = ChatSurface((400, SIZE[1]), leckerli_font, anon_font, anon_font_bold)
	print chat_surface.lines
	capture = True
	while capture:
		#get camera image
		camera_surface = camera.get_image(camera_surface)
		#draw the screen elements
		pygame.draw.rect(screen, DARK, [0, 0, SIZE[0], SIZE[1]])				#background color
		screen.blit(pygame.transform.scale(camera_surface, SIZE), (0,0))										#camera screen
		chat_surface.draw(screen)
		#flip the display buffers thus updating the surface
		pygame.display.flip()
		#handle events
		for event in pygame.event.get():
			if event.type == QUIT or (event.type == KEYDOWN and event.key == K_q):
				capture = False
			elif event.type == KEYDOWN and event.key == K_s:
				pygame.image.save(camera_surface, FILENAME)
	#die
	chat_surface.stop()
	camera.stop()
	pygame.quit()
            draw_target = pointillism.draw_and_compare
        self.request.sendall(json.dumps({'return':'ok'}))

server = JsonConfigServer(('127.0.0.1', 8000), JsonConfigHandler)
th = Thread(target=server.serve_forever)
th.daemon = True
th.start()

pygame.init()
pygame.camera.init()

cameras = pygame.camera.list_cameras()
camera = pygame.camera.Camera(cameras[0])

camera.start()
img = camera.get_image()

cam_width = img.get_width()
cam_height = img.get_height()

cam_im_array = pygame.surfarray.array3d(img)#pygame.image.load('sometest.png'))

average = map(int,map(round, cam_im_array.mean(1).mean(0)))
temp = numpy.array([[[0,0,0]]*cam_height]*cam_width,dtype=numpy.uint8)
#temp = numpy.array([[[0,0,0]]*cam_width]*cam_height, dtype=numpy.uint8)                            
whistler.save_im = Image.fromarray(temp)
whistler.im = Image.fromarray(cam_im_array)

whistler.width, whistler.height = cam_height, cam_width#, cam_height

#some defaults
示例#42
0
import pygame
import pygame.camera
from pygame.locals import *

SCREEN_SIZE = (int(640*.9), int(480*.9))

pygame.init()
pygame.camera.init()

camera_list = pygame.camera.list_cameras()
if not camera_list:
    print 'Tidak ada kamera terdeteksi!.'
    sys.exit(0)

screen = pygame.display.set_mode(SCREEN_SIZE)
pygame.display.set_caption(os.path.basename(__file__))


camera = pygame.camera.Camera(camera_list[0], SCREEN_SIZE)
camera.start()

while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit(0)

    image = camera.get_image()
    screen.blit(image, (0,0))
    pygame.display.update()
示例#43
0
size = (640, 480)
flowers = scipy.zeros(size, int)

pygame.init()
pygame.camera.init()

camera = pygame.camera.Camera("/dev/video0", size, "RGB") # hsv, yuv
camera.start()

display = pygame.display.set_mode(size, 0)

cvimages = [ cv.CreateImageHeader(size, cv.IPL_DEPTH_8U, 3)
             for n in range(3) ]

for cvimage in cvimages:
    pyg_image = camera.get_image()
    cv.SetData(cvimage, pyg_image.get_buffer())

for i in infinite_01():
    for e in pygame.event.get():
        if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
            exit(0)

    pyg_image = camera.get_image()
    cv.SetData(cvimages[i], pyg_image.get_buffer())

    if not i:
        cv.AbsDiff(*cvimages)
    else:
        cv.AbsDiff(cvimages[1],
                   cvimages[0],
示例#44
0
文件: cross.py 项目: Foued70/pycam
from cvEyeTrack import Draw_Cross

print("Imported pygame, numpy, opencv and cvEyeTracking lib")
raw_input("Press Enter to capture an image (in pygame)")

pygame.init()
pygame.camera.init()
size = width,height = 640,480
display = pygame.display.set_mode(size,0)
camList = pygame.camera.list_cameras()                  # TODO: err if none found
camera = pygame.camera.Camera(camList[0],size,"RGB")
camera.start()
for i in range(100):
    if camera.query_image(): # ready to take an image?
        break
snapshot = camera.get_image()
camera.stop()


display.blit(snapshot,(0,0,))
pygame.display.flip()
pygame.display.flip()

print("Captured an image")
raw_input("Press Enter to convert into opencv format")

npy = surfarray.pixels3d(snapshot)
ipl = adaptors.NumPy2Ipl(npy)

print("Captured an image")
raw_input("Press Enter to pass to cvEyeTrack to add a cross")
示例#45
0
			# Display message
			print "Camera not detected"
			
			# Exit
			exit()
	
		# Start camera
		camera = pygame.camera.Camera(cameraPort, (cameraWidth, cameraHeight))
		camera.start()

		# Initialize variables
		cameraImage = pygame.Surface((cameraWidth, cameraHeight))
	
		# Stabilize lighting
		for i in xrange(30) :
			camera.get_image()

		# Loop forever
		while True :

			try :
	
				# Get image from camera
				camera.get_image(cameraImage)
	
				# Convert image to a JPEG
				rawImage = Image.frombytes("RGB", (cameraWidth, cameraHeight), pygame.image.tostring(cameraImage, "RGB", False))
				buffer = StringIO.StringIO()
				rawImage.save(buffer, "JPEG")
	
				# Update current frame