我正在使用覆盆子pi来检测我的猫何时在桌子上,并且我在几个图像捕获部件上遇到了一些麻烦。这是我正在运行的相关代码:
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import subprocess
#method 1
with PiCamera() as camera:
capImg = PiRGBArray(camera)
time.sleep(0.1)
camera.capture(capImg,format = 'bgr')
image = capImg.array
cv2.imwrite('image4.bmp',image)
#method 2
callString = 'raspistill -n -w %s -h %s -o /home/pi/python/catcam/image5.bmp --timeout 0' % (640,480)
subprocess.call(callString, shell = True)
有没有办法将raspistill图像保存在内存中,或者执行类似camera.capture_continuous的操作?比较picamera图像的质量:
使用raspistill,颜色会更好:
我想每隔几秒钟捕获一次图像,但是不想为每个图像都写到磁盘上,否则我将很快烧毁存储卡。此外,raspistill相当慢。
任何有关如何以恒定速率捕获更好质量的图像的指针将不胜感激!
编辑感谢下面的Mark,我已经编辑了当前问题的帖子。
参考方案
您可以根据需要使用Python调用raspistill。这是一个示例,该示例以第二个延迟重复运行raspistill命令:
from time import sleep
from datetime import datetime
import subprocess
dir = "/home/pi/Desktop/cam_images/"
while (True):
fileName= "img_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".jpg"
cmd = "raspistill -o " + dir + fileName
subprocess.call(cmd, shell=True)
sleep(1)
Python sqlite3数据库已锁定 - python我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…
Python:在不更改段落顺序的情况下在文件的每个段落中反向单词? - python我想通过反转text_in.txt文件中的单词来生成text_out.txt文件,如下所示:text_in.txt具有两段,如下所示:Hello world, I am Here. I am eighteen years old. text_out.txt应该是这样的:Here. am I world, Hello old. years eighteen a…
用大写字母拆分字符串,但忽略AAA Python Regex - python我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…
Python-Excel导出 - python我有以下代码:import pandas as pd import requests from bs4 import BeautifulSoup res = requests.get("https://www.bankier.pl/gielda/notowania/akcje") soup = BeautifulSoup(res.cont…
Python:传递记录器是个好主意吗? - python我的Web服务器的API日志如下:started started succeeded failed 那是同时收到的两个请求。很难说哪一个成功或失败。为了彼此分离请求,我为每个请求创建了一个随机数,并将其用作记录器的名称logger = logging.getLogger(random_number) 日志变成[111] started [222] start…