如何使用pyserial获取图片名称数据以显示在腻子上

时间:2019-07-01 23:31:33

标签: python raspberry-pi putty pyserial

我正在运行代码以使用两个网络摄像头和树莓派来拍摄一系列照片,并以升序保存。我想要做的是获取越来越多的图片名称以显示在腻子上或与图片相关的任何东西,因为对于该项目,我们使用pyserial来证明程序正在运行,并且由于我们使用图片而需要图片标题或要显示在腻子上的文件大小。如果有帮助,我也会使用fswebcam

我已经尝试过直接使用示例代码直接获取数据以直接发送到腻子,我也尝试对数据进行编码和解码,但是最好的办法是它以thonny显示/ dev / ttyAMA0或程序正在运行

import os
import datetime
import serial
import time
from threading import Thread
def picFunc():
    os.system("fswebcam -d /dev/video0 -r 1920x1080 -S 25 
/home/pi/Documents/Pictures/%s.jpeg" 
%datetime.datetime.utcnow().strftime("%Y-%m-%d-%H:%M:%S"))
    os.system("fswebcam -d /dev/video1 -r 1920x1080 -S 25 
 /home/pi/Documents/Pictures2/%s.jpeg" 
 %datetime.datetime.utcnow().strftime("%Y-%m-%d-%H:%M:%S"))
 t=5      # initialise the pause between pictures in seconds           
 count=10 # initialise the number of pictures to be taken
 i=1       # initialise (reset) the counting sequence
 totalTime=(t*count) # Calculate the time in seconds
ser = serial.Serial(
    port='/dev/ttyAMA0',
    baudrate = 1200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
    )
ser.xonxoff =False
ser.rtscts= False
ser.dsrdtr = False
try:
    ser.isOpen()
except Exception:
        print('error open serial port: ' + str(Exception))
         exit()
print(ser.portstr)
serialcmd = ('')
print(serialcmd)

#ser.write(bytes(str(serialcmd).encode(encoding='utf-8', 
errors='ignore')))
#out = ser.read(125).decode(encoding='ascii', errors='ignore')
#print('recevied:' + out)
# Take a series of pictures one every t seconds
while (i<=count):
    # initialise variables
    leftTimeH=0
    leftTimeM=0
    leftTimeS=0

    # taking a picture by calling a command line prompt
x=Thread(target=picFunc)
x.start()
totalTime=(t*(count-i))     # Calculate the time in seconds
print (i)       # print the current count value to show progress
while (totalTime>=3600):
        leftTimeH=leftTimeH+1
        totalTime=totalTime-3600
while (totalTime>=60):
        leftTimeM=leftTimeM+1
        totalTime=totalTime-60
leftTimeS=totalTime
percentDone=((i/count)*100)
percentDone=round(percentDone,2)
message1=("Time left to finish " +repr(leftTimeH) +" Hours " + 
repr(leftTimeM) +" Minutes and " + repr(leftTimeS) +" Seconds")
message2=(""+repr(percentDone) + "% Completed!")
print (message1)
print (message2)
ser.write(bytes(str(message1).encode(encoding='utf-8', 
errors='ignore')))
out = ser.read(125).decode(encoding='ascii', errors='ignore')
print('recevied:' + out)
i=i+1
time.sleep(t)  
print ("Finished!") # print to show when finished

我从运行此代码得到的结果不是将其输出到腻子,而是显示

  
    
      

%运行webcam.py       / dev / ttyAMA0       就是这样

    
  

0 个答案:

没有答案