OpenCV使用cv2.imshow()报错的解决办法

报错内容:

The function is not implemented. Rebuild the library with Windows,
GTK+ 2.x or Cocoa support.

版本出错应该是不太可能的,于是我试着安装一下OpenCV的拓展开发包也就是.

  • opencv-contrib
  • 没想到,折腾好久的问题,最后一行命令解决问题了

pip install --user opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn

总结:遇到这个报错,请执行以上命令
OpenCV使用cv2.imshow()报错的解决办法_第1张图片
附上测试代码

import cv2
import mediapipe as mp

mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(
    static_image_mode=False,
    max_num_hands=2,
    min_detection_confidence=0.75,
    min_tracking_confidence=0.75)

cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    frame = cv2.flip(frame, 1)
    results = hands.process(frame)
    frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
    if results.multi_handedness:
        for hand_label in results.multi_handedness:
            print(hand_label)
    if results.multi_hand_landmarks:
        for hand_landmarks in results.multi_hand_landmarks:
            print('hand_landmarks:', hand_landmarks)
            mp_drawing.draw_landmarks(
                frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
    cv2.imshow('MediaPipe Hands', frame)
    if cv2.waitKey(1) & 0xFF == 27:
        break
cap.release()

注意,直接copy官网的代码测试会报错,别问我是怎么知道的。报错是API的使用方式变了。

你可能感兴趣的:(深度学习,深度学习,opencv)