添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
知识渊博的铁链  ·  Data Transfer Disk ...·  1 月前    · 
英俊的蚂蚁  ·  Binary malware image ...·  1 年前    · 
买醉的蟠桃  ·  arraybuffer转string ...·  1 年前    · 
迷茫的皮带  ·  jQuery 2.0.3 ...·  1 年前    · 

TypeError。在Python中使用mss库时,参数'mat'预期为Ptr<cv::UMat>。

1 人关注

我试图用mss库截图,用下面的代码来显示,但每次都得到同样的错误。 有什么方法可以解决这个错误吗?

TypeError: Expected Ptr<cv::UMat> for argument 'mat'

** 我是在Macos中使用的,不是在windows中。

import cv2 as cv
import numpy as np
import os
from time import time
from mss import mss
os.chdir(os.path.dirname(os.path.abspath(__file__)))
loop_time = time()
with mss() as sct:
    while (True):
        monitor_1 = sct.monitors[1]  # Identify the display to capture
        screenshot = sct.grab(monitor_1)
        cv.imshow('result', screenshot)
        print('FPS {}',format(1 / (time() - loop_time)))
        loop_time = time()
        if cv.waitKey(1) == ord('q'):
            cv.destroyAllWindows()
            break
print('done')
    
python
opencv
python-mss
Zac
Zac
发布于 2020-12-27
1 个回答
Hihikomori
Hihikomori
发布于 2020-12-27
已采纳
0 人赞同

你必须将 "屏幕截图 "转换为cv::UMat。

import time
import cv2
import mss
import numpy
with mss.mss() as sct:
    # Part of the screen to capture
    monitor = {"top": 40, "left": 0, "width": 800, "height": 640}
    while "Screen capturing":
        last_time = time.time()
        # Get raw pixels from the screen, save it to a Numpy array
        img = numpy.array(sct.grab(monitor))
        # Display the picture
        cv2.imshow("OpenCV/Numpy normal", img)
        # Display the picture in grayscale
        # cv2.imshow('OpenCV/Numpy grayscale',
        #            cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
        print("fps: {}".format(1 / (time.time() - last_time)))
        # Press "q" to quit