python - OpenCV - Python 轨迹栏无法在 macOS 上运行,但在 Ubuntu 中运行良好

标签 python macos python-3.x opencv ubuntu

我正在运行从网站获得的代码,该代码在 Ubuntu 上运行完全正常,但轨迹栏在 macOS 上不移动:

import cv2
import numpy as np

def nothing(x):
   pass

# Create a black image, a window
img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('image')

# create trackbars for color change
cv2.createTrackbar('R','image',0,255,nothing)
cv2.createTrackbar('G','image',0,255,nothing)
cv2.createTrackbar('B','image',0,255,nothing)

# create switch for ON/OFF functionality
switch = '0 : OFF \n1 : ON'
cv2.createTrackbar(switch, 'image',0,1,nothing)

while(1):
    cv2.imshow('image',img)
    k = cv2.waitKey(1) & 0xFF
    if k == 27:
        break

    # get current positions of four trackbars
    r = cv2.getTrackbarPos('R','image')
    g = cv2.getTrackbarPos('G','image')
    b = cv2.getTrackbarPos('B','image')
    s = cv2.getTrackbarPos(switch,'image')

if s == 0:
     img[:] = 0
else:
     img[:] = [b,g,r]

cv2.destroyAllWindows()

这是我的 MacBook 上的图像,其中轨迹栏不移动:

This is the image from my macbook where the trackbars don't move

为什么会发生这种情况? 请帮忙。谢谢。

最佳答案

如果您使用以下内容更新您的 cv2,此问题已得到解决:

pip install opencv-python-rolling

关于python - OpenCV - Python 轨迹栏无法在 macOS 上运行,但在 Ubuntu 中运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44333631/

相关文章:

iphone - 更改 NSOperation 优先级的安全方法

python-3.x - 你能通过pygithub删除一个repo吗?

python - python的scikit如何测量k-means的 'best output'

python - 基于现有列向 Pandas DataFrame 添加多个列

python - 计算两个列表增量的快速算法

linux - 如何处理lua中的这种内存泄漏?

python pyplot : colorbar on contourf and scatter in same plot

macos - PostgreSQL 的问题

python - 如何在 python 中检查事件连接?

python-3.x - os.path.isfile 出现 "file path not defined"错误?