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以使圖像變爲紅色。我會怎麼做?
我的最終目標是編寫檢測靜態背景上運動的軟件。我理解爲了實現這一目標需要做的理論和實際的數據操作,我只是不知道如何訪問每個幀的像素數據並對其進行操作。我試圖改變'圖像'中的一些值,但它說數組是不可變的,不能被寫入,只能讀取。
謝謝你的時間。