Example #1
0
    def initCam(self):
        self.env = 0
        self.brightness = 85

        #USB-Webcam
        '''
        pygame.camera.init()
        if not pygame.camera.list_cameras():
            self.main.TextOut.addText("[J.A.R.V.I.S.]: I couldn't find a camera!")
            self.env = 1
        else:
            #The first shall be it!
            self.camera = pygame.camera.Camera(pygame.camera.list_cameras()[0], self.camsize)
        '''
        #UNCOMMENT, IF A PICAMERA IS USED!
        try:
            camera = picamera.PiCamera()
            camera.close()
        except ImportError:
            self.env = 1
        except picamera.exc.PiCameraError:
            self.env = 1
        if self.env == 0:
            self.main.TextOut.addText("[J.A.R.V.I.S.]: Initializing!")
        else:
            self.main.TextOut.addText(
                "[J.A.R.V.I.S.]: I couldn't find a camera! You won't be able to take pictures."
            )
Example #2
0
 def camerapi(self,event):
     camera = picamera.PiCamera()
     camera.resolution = (2592, 1944)
     camera.drc_strength = 'high'
     time.sleep(2)
     filename = str(self.variable1) + ' Bottomview.jpg'
     filename2 =str(self.variable1)
     npath ="/home/pi/FootCam/" + str(filename2)
     if not os.path.isdir(npath):
         os.makedirs(npath)
     camera.capture(npath + "/" + filename)
     camera.close()
    def phototaking(self, event):
        camera = picamera.PiCamera()
        camera.resolution = (2592, 1944)
        camera.drc_strength = 'high'
        filename = 'Timelapse.jpg'

        npath = "/home/pi/" + str(filename)
        if not os.path.isdir(npath):
            os.makedirs(npath)
        time_of_lapse = 100
        while time_of_lapse > 0:
            camera.capture(npath + "/" + str(time_of_lapse) + filename)
            time_of_lapse = time_of_lapse - 1
        camera.close()
Example #4
0
def captureCSIImageAndSendOut():
    isOn = isLocalTakePhotoOn()
    if isOn:
        try:
            camera = picamera.PiCamera()
            #cameraConfigDict["latestLocalUploadTime"]
            camera.resolution = (1920, 1080)
            #camera.start_preview()
            # Camera warm-up time
            time.sleep(2)
            #Image name
            fileName = str(current_milli_time()) + ".jpg"
            camera.capture(fileName)
            camera.close()
            #camera.stop_preview()
            print "SHOOOOOTTTTTing CSI image"
            sendImageToLocalAndRemoteServer(cpu_serial, fileName)
        except Exception, e:
            print str(e)
Example #5
0
def quit_app(camera):  #quitte proprement la caméra
    camera.annotate_text = ""  #réinitialise le texte affiché
    Ymd = datetime.datetime.now().strftime(
        "%Y-%m-%d")  #récupération de la date
    #vérification et/ou création du dossier "Photos"
    os.makedirs("Photos", exist_ok=True)
    os.chdir("Photos")
    os.makedirs(Ymd, exist_ok=True)
    os.chdir(Ymd)
    camera.capture('last_image_saved.jpg',
                   resize=(299,
                           168))  #prise d'un cliché pour l'interface graphique
    os.chmod(
        '.', 0o777
    )  #changement des droits : tout le monde peut écrire dans le dossier et y supprimer des éléments
    #retour au dossier de travail
    os.chdir("..")
    os.chdir("..")
    #quitte et ferme la caméra
    camera.close()
    pygame.display.quit()
Example #6
0
def inspectCameraConfig():
    global cameraConfigDict
    #Add cpu serialNumber(onboard csi camera serialId)
    #boardCameraSerialNumber = getCpuSerial()
    #CSI camera
    cameraConfigDict = getCameraConfigInfo(cpu_serial)
    #if solution has been changed
    global localResolution
    global camera
    if localResolution != cameraConfigDict["localResolution"]:
        print 'not eauql haha---------------------' + cameraConfigDict[
            "localResolution"]
        localResolution = cameraConfigDict["localResolution"]
        #restart camera
        camera.close()
        #init picamera
        camera = picamera.PiCamera()
        camera.resolution = (
            int(cameraConfigDict["localResolution"].split("*")[0]),
            int(cameraConfigDict["localResolution"].split("*")[1]))
    else:
        print localResolution
    captureCSIImage()
Example #7
0
#Initiate the camera

try:
    camera = picamera.PiCamera()
    camera.resolution = (1024, 768)
    #camera.start_preview()
    # Camera warm-up time
    print "first sleep started"
    time.sleep(2)
    print "first sleep ended"
    #Image name
    fileName = str(current_milli_time()) + ".jpg"
    camera.capture(fileName)
    print "first captured ended"
    #camera.stop_preview()
    camera.close()
    print "first closed"
    print "1  SHOOOOOTTTTTing CSI image"
    time.sleep(2)
    #Again
    #camera.start_preview()
    camera = picamera.PiCamera()
    camera.resolution = (1024, 768)
    fileName = str(current_milli_time()) + ".jpg"
    camera.capture(fileName)
    #camera.stop_preview()
    camera.close()
    print "2 SHOOOOOTTTTTing CSI image"
    time.sleep(2)
except Exception, e:
    print str(e)
Example #8
0
def startCamera(expTime):  #démarre la caméra et sa preview
    #initialise pygame et ecran
    pygame.init()

    screen = pygame.display.set_mode((640, 480), 0)

    #initialisation de la caméra
    camera = picamera.PiCamera()  #création de l'objet caméra
    camera.resolution = (1280, 720)  #paramétrage de la résolution
    camera.crop = (0.0, 0.0, 1.0, 1.0)
    camera.framerate = float(24)  #paramétrage des FPS
    camera.shutter_speed = expTime  #paramétrage du temps d'exposition
    x = (screen.get_width() - camera.resolution[0]) / 2
    y = (screen.get_height() - camera.resolution[1]) / 2

    # Init buffer
    rgb = bytearray(camera.resolution[0] * camera.resolution[1] * 3)
    #camera.start_preview(fullscreen=False, window = (0, 0, width, height))#démarre la preview
    global pad, target, already  #création de variables semi-locales
    target = Image.open('/home/pi/Desktop/Capsula/Icon/target.png'
                        )  #ouverture de l'image "target"
    already = False  #état : cible non affichée
    pad = Image.new('RGBA', (
        ((target.size[0] + 31) // 32) * 32,
        ((target.size[1] + 15) // 16) * 16,
    ))
    pad.paste(target, (0, 0))
    #ajout des raccourcis sous forme de texte sur la vidéo
    #camera.annotate_text_size = 25
    #camera.annotate_foreground = picamera.Color('white')
    #camera.annotate_text = "P : capture image\nV : Start recording video (v again to stop)\nC: Enable/Disable target\nBackspace : Exit"

    running = True  #état : caméra active
    while running:  #tant que la caméra est active
        stream = io.BytesIO()
        camera.capture(stream, use_video_port=True, format='rgb')
        stream.seek(0)
        stream.readinto(rgb)
        stream.close()
        img = pygame.image.frombuffer(
            rgb[0:(camera.resolution[0] * camera.resolution[1] * 3)],
            camera.resolution, 'RGB')

        screen.fill(0)
        if img:
            screen.blit(img, (x, y))

        pygame.display.update()

        for event in pygame.event.get(
        ):  #si il se produit une action sur le clavier
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_p:  #si la touche p est enfoncée
                    take_pic(camera)
                elif event.key == pygame.K_v:  #si la touche v est enfoncée
                    take_video(camera)
                elif event.key == pygame.K_c:  #si la touche c est enfoncée
                    print_target(camera)
                elif event.key == pygame.K_BACKSPACE:  #si la touche retour est enfoncée
                    running = False  #état : caméra inactive
                    quit_app(camera)
                    #quit_app(camera) #quitte la preview et la caméra
                elif event.key == pygame.K_UP:  #if  up key is pressed
                    startM()  #start motor
                elif event.key == pygame.K_DOWN:  #if down key is pressed
                    stopM()
                elif event.key == pygame.K_SPACE:  #if space key is pressed
                    changeDirectionM()
                elif event.key == pygame.K_TAB:  #if tab key is pressed
                    stepM()
                elif event.key == pygame.K_LSHIFT:  #if left shift is pressed
                    stepmM()
    camera.close()
    pygame.display.quit()