枕(PIL)ライブラリからImageGrabを使用し、キャプチャをnumpy配列に変換する必要があります。あなたが配列を持っているときは、opencvを使ってそれをどうすることもできます。キャプチャを灰色に変換し、デモンストレーションとして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()
あなたは、フレームをキャプチャ保つために喜ば周波数であり、配列を差し込むことができます。ここでは
はあなたが始めるために迅速なコードです。その後、フレームをデコードします。ループの前に追加することを忘れないでください:
fourcc = cv2.VideoWriter_fourcc(*'XVID')
vid = cv2.VideoWriter('output.avi', fourcc, 6, (640,480))
、あなたが追加することができ、ループ内:
vid.write(frame) #the edited frame or the original img_np as you please
あなたが達成したい場合はUPDATE
最終結果はこのようなものを(見てキャプチャされた画面に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()
役に立ったと思っています
http://stackoverflow.com/a/24213099/1832058 – furas