调整PIL ImageGrab模块Python上的RGB

时间:2016-10-10 14:00:23

标签: python opencv python-imaging-library

我正在尝试使用ImageGrab制作截屏剧本,但我正在使用有线蓝色图像

Image Sample


    import cv2
    import numpy as np
    from PIL import ImageGrab

    out = cv2.VideoWriter('record.avi', 2, 8.0, (1366, 768)) 
    while (True):
       img = ImageGrab.grab(bbox=(0, 0, 1366, 768)) # x, y, w, h
       img_np = np.array(img)
       frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
       out.write(img_np)
       cv2.imshow("Recorder", frame)
       key = cv2.waitKey(1)
       if key == 27:
          break
    cv2.waitKey(0)
    cv2.destroyAllWindows()

1 个答案:

答案 0 :(得分:4)

RGB_img = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
vid.write(RGB_img)

这样可行。