0
我有以下代码:编辑视频帧
# Import packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
X_RESOLUTION = 640
Y_RESOLUTION = 480
# Initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (X_RESOLUTION, Y_RESOLUTION)
camera.framerate = 10
rawCapture = PiRGBArray(camera, size = (X_RESOLUTION, Y_RESOLUTION))
# Allow camera to warmup
time.sleep(0.1)
#Capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# Grab the raw NumPy array representing the image
image = frame.array
# Show the frame
cv2.imshow("Frame", image)
key = cv2.waitKey(1) & 0xFF
# Clear the stream so it is ready to receive the next frame
rawCapture.truncate(0)
# If the 'q' key was pressed, break from the loop
if(key == ord('q')):
break
这是所有罚款和花花公子。它捕捉视频并将其显示在我的屏幕上,当按'q'时它会退出。但是,如果我想以某种方式操作这些帧,例如我想将每帧中的每个像素R值设置为255以使图像变为红色。我会怎么做?
我的最终目标是编写检测静态背景上运动的软件。我理解为了实现这一目标需要做的理论和实际的数据操作,我只是不知道如何访问每个帧的像素数据并对其进行操作。我试图改变'图像'中的一些值,但它说数组是不可变的,不能被写入,只能读取。
谢谢你的时间。