OpenCV - Python轨道栏不适用于macOS,但在Ubuntu中运行良好

时间:2017-06-02 16:33:29

标签: python macos python-3.x opencv ubuntu

我正在运行一个从网站上获得的代码,代码在Ubuntu上运行完全正常,但是跟踪条不能在macOS上运行:

https://accounts.spotify.com/api/token?grant_type=authorization_code&code=THE_CODE&redirect_uri=THE_REDIRECT_URI&client_id=THE_CLIENT_ID&client_secret=THE_CLIENT_SECRET

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

为什么会这样? 请帮忙。感谢。

1 个答案:

答案 0 :(得分:1)

if / else 语句应放在 while 循环内


import cv2
import numpy as np

def nothing(x):
   pass

img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('image')

cv2.createTrackbar('R','image',0,255,nothing)
cv2.createTrackbar('G','image',0,255,nothing)
cv2.createTrackbar('B','image',0,255,nothing)

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

    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()