def update(): global cap global frame global running global rawCapture global picamera while running: # Read that frame # print( "Read one camera frame" ) if rawCapture: rawCapture.truncate(0) picamera.capture(rawCapture, format="bgr") #, resize=(640, 360)) frame = rawCapture.array else: # Capture frame from regular USB webcam (grabbed, frame2) = cap.read() frame = cv2.resize(frame2, res, interpolation=cv2.INTER_CUBIC) print("Stopped camera.")
def saveImage(): print("Initializing camera...") with picamera.PiCamera() as camera: #camera.start_preview() print("Setting focus and light level on camera...") logging.basicConfig(filename=datetime.datetime.now().strftime("%Y-%m-%d")+'.txt',level=logging.DEBUG) print("Capture picture...") # Create the in-memory stream stream = io.BytesIO() camera.capture(stream, format='jpeg') # Construct a numpy array from the stream data = np.fromstring(stream.getvalue(), dtype=np.uint8) # "Decode" the image from the array, preserving colour image = cv2.imdecode(data, 1) tstmp = datetime.datetime.now().strftime("%Y-%m-%d-%H:%M:%S") image_file = "image_%s_%05d.jpg" % (tstmp, count) #get the date to save the directory with the actual day date = datetime.datetime.now().strftime("%Y-%m-%d") #get the actual directory of the aplication actual = os.getcwd() #test to see if the directory with the date already exist if os.path.exists(date): os.chdir(date) # go to the directory date if it exist #if the directory do not exist then, create the directory and access it else : os.mkdir(date) print('Directory created: ' + date) os.chdir(date) #save the image on the directory date cv2.imwrite(file_name, self.__image0) print(" - Image saved:", file_name) #return to the main directory of the aplication os.chdir(actual)
import picamera import datetime import os import ffmpeg now = datetime.datetime.now() dir_name = now.strftime('%Y%m%d') dir_path = '/home/pi/Pictures/' + dir_name file_name = now.strftime('%H%M%S') if not os.path.exists(dir_path): os.makedirs(dir_path) os.chmod(dir_path, 0755) picamera = picamera.PiCamera() picamera.capture(dir_path + '/' + file_name + '.jpg') #recording video print('recording video') picamera.start_recording(dir_path + '/' + file_name + '.h264') picamera.wait_recording(10) picamera.stop_recording() #encording with ffmpeg print('encording video') input_file_path = dir_path + '/' + file_name + '.h264' output_file_path = dir_path + '/' + file_name + '.mp4' #stream = ffmpeg.input(dir_path+'/'+file_name+'.h264') stream = ffmpeg.input(input_file_path) #print(dir_path+'/'+file_name+'.h264') #print(dir_path+'/'+file_name+'.mp4')
def capture_image(self): picamera.start_preview() time.sleep(5) picamera.capture('/home/pi/Desktop/Visitors/%s.jpg' % self.data) picamera.stop_preview()
dir_name = now.strftime('%Y%m%d') dir_path = '/home/pi/nas/' + dir_name print(dir_path) file_name = now.strftime('%H%M%S') if not os.path.exists(dir_path): os.makedirs(dir_path) #インデントを付けていなかったのでエラーが出ていた os.chmod(dir_path, 0777) picamera = picamera.PiCamera() picamera.resolution = (1024, 768) #picamera.start_preview() # Camera warm-up time、これがないと色が青白くて使い物にならない time.sleep(2) file_name = file_name + '.jpg' picamera.capture(dir_path + '/' + file_name) print "Now start Upload." _ftp = FTP('192.168.12.151') _ftp.set_debuglevel(1) # デバッグログをリアルタイムで確認 _ftp.login('ftpuser', 'password') _file = open(dir_path + '/' + file_name, 'rb') #target file _ftp.cwd('picture') try: _ftp.cwd(dir_name) #target_dir except Exception as e: if str(e) == '550 Failed to change directory.': _ftp.mkd(dir_name) _ftp.cwd(dir_name) _ftp.storbinary('STOR ' + file_name, _file)
def getFrame(): global rawCapture, picamera if rawCapture: rawCapture.truncate(0) picamera.capture(rawCapture, format="bgr") #, resize=(640, 360)) return rawCapture.array
def saveFrame(filepath): global picamera picamera.start_preview() picamera.capture(filepath)
import picamera import datetime import os now = datetime.datetime.now() dir_name = now.strftime('%Y%m%d') dir_path = '/home/pi/'+dir_name file_name = now.strftime('%H%M%S') if not os.path.exists(dir_path): os.makedirs(dir_path) os.chmod(dir_path, 0o777) picamera = picamera.PiCamera() picamera.capture(dir_path+'/'+file_name+'.jpg')
if not os.path.exists(dir_path): os.makedirs(dir_path) os.chmod(dir_path, 0777) try: picamera = picamera.PiCamera() dbx = dropbox.Dropbox('') dbx.users_get_current_account() i = 0 while i < 24: now = datetime.datetime.now() nowf = "{0:%H:%M:%S}.png".format(now) file_name = now.strftime("%H:%M:%S") base = os.path.basename(dir_path + '/' + nowf) picamera.capture(dir_path + '/' + base) dbx = dropbox.Dropbox('') dbx.users_get_current_account() with open(dir_path + '/' + base, 'rb') as f: dbx.files_upload(f.read(), "/saibaicam/" + dir_name + "/" + nowf) f.close() i = i + 1 if i == 1: #宛先 to_addr = "" #件名,本文 subject = "Cam" body = "SaibaiCam Go" #メッセージ作成
def process(): print("Initializing camera...") with picamera.PiCamera() as camera: #camera.start_preview() print("Setting focus and light level on camera...") print("Initializing the CameraDetection...") detection = MotionDetection() logging.basicConfig( filename=datetime.datetime.now().strftime("%Y-%m-%d") + '.txt', level=logging.DEBUG) count = 0 while True: print("Capture picture...") # Create the in-memory stream stream = io.BytesIO() camera.capture(stream, format='jpeg') # Construct a numpy array from the stream data = np.fromstring(stream.getvalue(), dtype=np.uint8) # "Decode" the image from the array, preserving colour image = cv2.imdecode(data, 1) ctrl = 1 alarm_on = True if detection.detectMotion(image): start_log = log_start(alarm_on) light_on_off = lights() while ctrl < 10: tstmp = datetime.datetime.now().strftime( "%Y-%m-%d-%H:%M:%S") image_file = "image_%s_%05d.jpg" % (tstmp, count) count += 1 detection.saveImage(image_file) print(ctrl) stream2 = io.BytesIO() camera.capture(stream2, format='jpeg') data2 = np.fromstring(stream2.getvalue(), dtype=np.uint8) image2 = cv2.imdecode(data2, 1) test = detection.detectMotion(image2) if test == False: ctrl = ctrl + 1 else: ctrl = 1 if light_on_off == True: light_on_off = False print("Turning of the lights") log_finish(start_log)
#-*- coding:utf-8 -*- import time import picamera import subprocess parae = [ "off", "auto", "night", "nightpreview", "backlight", "spotlight", "sports", "snow", "beach", "verylong", "fixedfps", "antishake", "fireworks" ] param = ["average", "spot", "backlit", "matrix"] paraa = [ "off", "auto", "sunlight", "cloudy", "shade", "tungsten", "fluorescent", "incandescent", "flash", "horizon" ] with picamera.PiCamera() as picamera: num = 0 file_name = str(num) for e in parae: print(e) for m in param: for a in paraa: file_name = a + "-" + m + "-" + e picamera.awb_mode = a picamera.meter_mode = m picamera.exposure_mode = e picamera.capture("/home/pi/Desktop/robocon/test1/" + file_name + '.jpg') print("\n") print("end")