我正在尝试学习MSS python库来流式传输/反映监视器中的内容。我的目的是将它与OpenCV一起使用来处理图像。我从youtube教程中获得了这个源代码,但是我得到了this错误:(我无法解决这个问题来运行代码)。任何提示和指导都是非常感谢的。
Traceback (most recent call last):
File "C:\Users\Ryan Webb\Documents\OpenCV-objectDetection\mss.py", line 4, in <module>
from mss.windows import MSS as mss
File "C:\Users\Ryan Webb\Documents\OpenCV-objectDetection\mss.py", line 4, in <module>
from mss.windows import MSS as mss
ModuleNotFoundError: No module named 'mss.windows'; 'mss' is not a package
以下是我从教程中复制粘贴的源代码:
from mss import mss
import cv2
from PIL import Image
import numpy as np
from time import time
mon = {'top': 100, 'left':200, 'width':1600, 'height':1024}
sct = mss()
while 1:
begin_time = time()
sct_img = sct.grab(mon)
img = Image.frombytes('RGB', (sct_img.size.width, sct_img.size.height), sct_img.rgb)
img_bgr = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
cv2.imshow('test', np.array(img_bgr))
print('This frame takes {} seconds.'.format(time()-begin_time))
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
我想我正确安装了MSS库,下面是我的pip列表结果:
C:\Users\Ryan Webb>pip list
Package Version
----------------- --------
astroid 2.6.5
colorama 0.4.4
isort 5.9.3
lazy-object-proxy 1.6.0
mccabe 0.6.1
MouseInfo 0.1.3
mss 6.1.0
numpy 1.21.1
opencv-python 4.5.3.56
Pillow 8.3.1
pip 21.1.3
PyAutoGUI 0.9.53
PyGetWindow 0.0.9
pylint 2.9.6
PyMsgBox 1.0.9
pyperclip 1.8.2
PyRect 0.1.4
PyScreeze 0.1.27
PyTweening 1.0.3
pywin32 301
setuptools 56.0.0
toml 0.10.2
wrapt 1.12.1
WARNING: You are using pip version 21.1.3; however, version 21.2.3 is available.
You should consider upgrading via the 'c:\program files\python39\python.exe -m pip install --upgrade pip' command.
发布于 2021-08-14 17:20:21
正如我的朋友Ghoti在评论中指出的那样,我的错误是将我的脚本命名为mss.py,导致运行时出现问题。我不知道如何将我的问题标记为已回答,所以我想在这里说出来。
https://stackoverflow.com/questions/68785352
复制相似问题