python监控桌面捕捉,用Python从屏幕上捕获视频数据
您將需要使用枕頭(PIL)庫中的ImageGrab并將捕獲轉(zhuǎn)換為numpy數(shù)組。當(dāng)你擁有這個數(shù)組時,你可以使用opencv做你想做的事情。我將捕獲轉(zhuǎn)換為灰色,并使用imshow()作為演示。
下面是一個快速啟動代碼:from PIL import ImageGrab
import numpy as np
import cv2
img = ImageGrab.grab(bbox=(100,10,400,780)) #bbox specifies specific region (bbox= x,y,width,height *starts top-left)
img_np = np.array(img) #this is the array obtained from conversion
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
cv2.imshow("test", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
你可以用你想要的頻率在那里插入一個陣列來繼續(xù)捕捉幀。在那之后你只需解碼幀。不要忘記在循環(huán)之前添加:fourcc = cv2.VideoWriter_fourcc(*'XVID')
vid = cv2.VideoWriter('output.avi', fourcc, 6, (640,480))
在循環(huán)中,您可以添加:vid.write(frame) #the edited frame or the original img_np as you please
更新
最終的結(jié)果是這樣的(如果你想實現(xiàn)一個幀流的話)。作為視頻存儲,只是在截取的屏幕上演示如何使用opencv):from PIL import ImageGrab
import numpy as np
import cv2
while(True):
img = ImageGrab.grab(bbox=(100,10,400,780)) #bbox specifies specific region (bbox= x,y,width,height)
img_np = np.array(img)
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
cv2.imshow("test", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
希望能幫上忙
總結(jié)
以上是生活随笔為你收集整理的python监控桌面捕捉,用Python从屏幕上捕获视频数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 删除 srvinstw安装的服务
- 下一篇: php 论坛下载,PHPWind论坛社区