简体   繁体   English

类型错误:预期 Ptr<cv::umat> 在 python 中使用 mss 库作为参数“mat”</cv::umat>

[英]TypeError: Expected Ptr<cv::UMat> for argument 'mat' using mss library in python

I am trying to screenshot using mss library add display it using below code but getting same error every time.我正在尝试使用 mss 库添加屏幕截图并使用以下代码显示它,但每次都会出现相同的错误。 Is there a fix for this error是否有解决此错误的方法

TypeError: Expected Ptr<cv::UMat> for argument 'mat' TypeError:参数“mat”的预期 Ptr<cv::UMat>

** I am using this in Macos not windows ** 我在 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')

You have to convert "screenshot" to cv::UMat:您必须将“屏幕截图”转换为 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
        if cv2.waitKey(25) & 0xFF == ord("q"):
            cv2.destroyAllWindows()
            break

This is example from here这是这里的例子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 预期的 Ptr<cv::umat> 对于参数“垫子”</cv::umat> - Expected Ptr<cv::UMat> for argument 'mat' 类型错误:预期的 Ptr<cv::umat> 使用 opencv 在文件夹中显示多张图片后的参数 'mat'</cv::umat> - TypeError: Expected Ptr<cv::UMat> for argument 'mat' after display multiple pictures in a folder using opencv Python - tkinter; 类型错误:预期的 Ptr<cv::umat> 对于参数“src”</cv::umat> - Python - tkinter; TypeError: Expected Ptr<cv::UMat> for argument 'src' 类型错误:预期的 Ptr<cv::umat> 对于参数 'm'</cv::umat> - TypeError: Expected Ptr<cv::UMat> for argument 'm' 类型错误:预期的 Ptr<cv::umat> 对于参数'src'?</cv::umat> - TypeError: Expected Ptr<cv::UMat> for argument 'src'? 类型错误:预期的 Ptr<cv::umat> 对于参数“%s”</cv::umat> - TypeError: Expected Ptr<cv::UMat> for argument '%s' 类型错误:预期的 Ptr<cv::umat> 对于参数“img”</cv::umat> - TypeError: Expected Ptr<cv::UMat> for argument 'img' 类型错误:使用 OpenCV 在 Python 中旋转图像时,参数“mat”需要 cv::UMat - TypeError: Expected cv::UMat for argument 'mat' when rotating an image in Python using OpenCV 错误“TypeError:预期的 Ptr<cv::umat> 尝试显示数组中的图像时用于参数“垫子”</cv::umat> - Error “TypeError: Expected Ptr<cv::UMat> for argument 'mat'” when trying to display images from an Array 错误消息“预期的 Ptr<cv::umat> 对于参数“垫子””</cv::umat> - Error Message “Expected Ptr<cv::UMat> for argument 'mat'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM