コード例 #1
0
    def _thread(cls):
        pygame.init()
        pygame.camera.init()
        with picamera.PiCamera() as camera:
            # camera setup
            camera.resolution = (320, 240)
            camera.hflip = True
            camera.vflip = True

            # let camera warm up
            camera.start_preview()
            time.sleep(2)

            stream = io.BytesIO()
            for foo in camera.capture_continuous(stream,
                                                 'jpeg',
                                                 use_video_port=True):
                # store frame
                stream.seek(0)
                cls.frame = stream.read()

                # reset stream for next frame
                stream.seek(0)
                stream.truncate()

                # if there hasn't been any clients asking for frames in
                # the last 10 seconds stop the thread
                if time.time() - cls.last_access > 10:
                    break
        cls.thread = None
コード例 #2
0
def main():
    # 1. Take picture
    camera = picamera.PiCamera()
    camera.start_preview()
    sleep(5)
    camera.capture('/home/pi/Desktop/image.jpg')
    camera.stop_preview()

    # 2. Display saved picture using pygame.
    pygame.init()
    fpsClock = pygame.time.Clock()
    surface = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
    black = (0, 0, 0)
    image = pygame.image.load('/home/pi/Desktop/image.jpg')

    while True:
        surface.fill(black)
        surface.blit(image, (0, 0))

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

        pygame.display.update()
        fpsClock.tick(30)
コード例 #3
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
コード例 #4
0
#setup sht
pygame.init()
pygame.camera.init()

#set up for main video
display = pygame.display.set_mode((width, height), 0, 32)
pygame.display.set_caption("Blob Tracker")

#set up for picamerai
camera = picamera.PiCamera()
stream = picamera.array.PiRGBArray(camera)
camera.resolution = resolution
camera.vflip = True

#preview so we can see whats beeing seen.
camera.start_preview(fullscreen=False, window=(100, 20, 640, 480))


def close():
    pygame.quit()
    sys.exit()


while True:
    x_pix = 0
    y_pix = 0
    l = 0

    display.fill((255, 255, 255))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
コード例 #5
0
ファイル: pygamecam.py プロジェクト: CWRatliff/Rover
pygame.display.set_caption('RaspiRobot')
#cam = pygame.camera.Camera("/dev/video0", (640, 480))
#cam.start()
#image = cam.get_image()

#camlist = pygame.camera.list_cameras()
#if camlist:
#    cam = pygame.camera.Camera(camlist[0], (640,480))
#pygame.mouse.set_visible(0)

from picamera import PiCamera

camera = PiCamera()
camera.preview_fullscreen = False
camera.preview_window = (0, 0, 640, 480)
camera.start_preview()
time.sleep(10)
camera.stop_preview()

steer = 90
speed = 0
left_limit = 60
right_limit = 120
GREEN = (0, 255, 0)

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_UP:
コード例 #6
0
def set_up():
    #Width and height of screen
    width = 700
    height = 500

    #resolution of camera
    resolution = (700, 500)

    #calculate the scale of pixels on canvas
    w, h = resolution
    scaleW = width / w
    scaleH = height / h

    #setup sht
    pygame.init()
    pygame.camera.init()

    #set up for main video
    display = pygame.display.set_mode((width, height), 0, 32)
    pygame.display.set_caption("Blob Tracker")

    #set up for picamerai
    camera = picamera.PiCamera()
    stream = picamera.array.PiRGBArray(camera)
    camera.resolution = resolution
    camera.vflip = True

    #preview so we can see whats beeing seen.
    camera.start_preview(fullscreen=False, window=(100, 20, 640, 480))

    while True:
        x_pix = 0
        y_pix = 0
        l = 0

        display.fill((255, 255, 255))
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                close()
                break

        #caspture a rbg picture to the stream
        camera.capture(stream, 'rgb', use_video_port=True)

        #somehow makes us process. lack luster docs....
        stream.seek(0)

        #iterate over all pix
        for y in range(h):
            for x in range(w):

                #get pixs
                r_vals = stream.array[y, x, 0]
                g_vals = stream.array[y, x, 1]
                b_vals = stream.array[y, x, 2]

                if b_vals > g_vals and b_vals > r_vals and b_vals > 175:
                    x_pix += x
                    y_pix += y

                    l += 1

        if l > 0:
            #calc the mean
            x_pix /= l
            y_pix /= l
            print('x', x_pix)
            print('y', y_pix)

            pygame.draw.circle(display, (255, 0, 0), (int(x_pix), int(y_pix)),
                               5, 0)

        else:
            print("nothing to report sir")

        stream.seek(0)
        stream.truncate()

        pygame.display.update()
コード例 #7
0
 def take_picture():
     camera = picamera.PiCamera()
     camera.start_preview()
     sleep(5)
     camera.capture('/home/pi/Desktop/image.jpg')
     camera.stop_preview()