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

本文详细描述了如何在遇到The function is not implemented报错时,通过安装opencv-contrib-python解决。提供了一段测试代码,以及关键步骤pip install --user opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错内容:

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

总结:遇到这个报错,请执行以上命令
在这里插入图片描述
附上测试代码

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的使用方式变了。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值