Importerror:错误:在“ CV2”的加载过程中检测到递归。二进制扩展。检查OpenCV安装

发布于 2025-01-30 04:57:35 字数 2771 浏览 2 评论 0原文

我是与Python一起制作屏幕录音机,我正在使用Python的OpenCV,但它给出了我在任何地方都找不到工作答案的输出,我真的需要帮助。我只使用Python大约一年了。这是它给我的输出:

['C:\\Users\\Diana\\Desktop\\python\\RecScreen', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\DLLs', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pygooglevoice-0.5-py3.10.egg', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\win32', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\win32\\lib', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\Pythonwin']
Traceback (most recent call last):
  File "C:\Users\Diana\Desktop\python\RecScreen\RecScreen.py", line 3, in <module>
    import cv2
  File "C:\Users\Diana\AppData\Local\Programs\Python\Python310\lib\cv2\__init__.py", line 180, in <module>
    bootstrap()
  File "C:\Users\Diana\AppData\Local\Programs\Python\Python310\lib\cv2\__init__.py", line 75, in bootstrap
    raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

我的代码是:

# importing the required packages
import pyautogui
import cv2
import keyboard
import numpy as np

# Specify resolution
resolution = (1920, 1080)

# Specify video codec
codec = cv2.VideoWriter_fourcc(*"XVID")

# Specify name of Output file
filename = "Recording.avi"

# Specify frames rate. We can choose any
# value and experiment with it
fps = 60.0


# Creating a VideoWriter object
out = cv2.VideoWriter(filename, codec, fps, resolution)

cv2.namedWindow("Recording", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Recording", 480, 270)

while True:
    # Take screenshot using PyAutoGUI
    img = pyautogui.screenshot()

    # Convert the screenshot to a numpy array
    frame = np.array(img)

    # Convert it from BGR(Blue, Green, Red) to
    # RGB(Red, Green, Blue)
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    # Write it to the output file
    #out.write(frame)
    
    # Optional: Display the recording screen
    cv2.imshow('Live', frame)
    
    # Stop recording when we press 'ctrl+esc'
    if keyboard.is_pressed("Ctrl+esc"):
        break

# Release the Video writer
out.release()

# Destroy all windows
cv2.destroyAllWindows()

我不知道如何解决此错误。任何帮助都将受到赞赏。

I as making a screen recorder with python and I was using OpenCV with python but its giving this output that I can't find a working answer ANYWHERE and I really need help. I am have only been using python for about a year. Here is the output it gives me:

['C:\\Users\\Diana\\Desktop\\python\\RecScreen', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\DLLs', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pygooglevoice-0.5-py3.10.egg', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\win32', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\win32\\lib', 'C:\\Users\\Diana\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\Pythonwin']
Traceback (most recent call last):
  File "C:\Users\Diana\Desktop\python\RecScreen\RecScreen.py", line 3, in <module>
    import cv2
  File "C:\Users\Diana\AppData\Local\Programs\Python\Python310\lib\cv2\__init__.py", line 180, in <module>
    bootstrap()
  File "C:\Users\Diana\AppData\Local\Programs\Python\Python310\lib\cv2\__init__.py", line 75, in bootstrap
    raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

My code is:

# importing the required packages
import pyautogui
import cv2
import keyboard
import numpy as np

# Specify resolution
resolution = (1920, 1080)

# Specify video codec
codec = cv2.VideoWriter_fourcc(*"XVID")

# Specify name of Output file
filename = "Recording.avi"

# Specify frames rate. We can choose any
# value and experiment with it
fps = 60.0


# Creating a VideoWriter object
out = cv2.VideoWriter(filename, codec, fps, resolution)

cv2.namedWindow("Recording", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Recording", 480, 270)

while True:
    # Take screenshot using PyAutoGUI
    img = pyautogui.screenshot()

    # Convert the screenshot to a numpy array
    frame = np.array(img)

    # Convert it from BGR(Blue, Green, Red) to
    # RGB(Red, Green, Blue)
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    # Write it to the output file
    #out.write(frame)
    
    # Optional: Display the recording screen
    cv2.imshow('Live', frame)
    
    # Stop recording when we press 'ctrl+esc'
    if keyboard.is_pressed("Ctrl+esc"):
        break

# Release the Video writer
out.release()

# Destroy all windows
cv2.destroyAllWindows()

I can't figure out how to fix this error. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2025-02-06 04:57:35

错误:递归: “ CV2”二进制扩展。检查OpenCV安装

它对我有用
作为管理员运行时,将其放在CMD中

pip3 install opencv-python --upgrade --force-reinstall

ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation

it worked for me
put this in your cmd as you run as admin

pip3 install opencv-python --upgrade --force-reinstall
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文