python - 在 PIL ImageGrab 模块 Python 上调整 RGB

标签 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()

最佳答案

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

这会起作用。

关于python - 在 PIL ImageGrab 模块 Python 上调整 RGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39960080/

相关文章:

Python:如何重置 turtle graphics 窗口

python - django 中的自定义用户引发 ValueError

qt - 如何在带有opencv-cv::Scalar的QT-QColor之间转换?

python - Selenium 显式等待 invisibility_of_element() 根本不等待

opencv - "Error: ' 尝试使用 OpenCV 和 CUDA 构建暗网时,IplImage' 没有命名类型?

image - 定向梯度旋转和变换的直方图

python - 在 Python 中调整图像大小

python - 如何更改图像的像素值?

python - PIL : How to write text images and automatically wrap?

python - 在 pdb(python 调试器)中,我可以在内置函数上设置断点吗?