cv2 getTrackbarPos无效

时间:2016-09-07 15:38:50

标签: python-2.7 opencv trackbar opencv3.1

在python 2.7.12中使用opencv3.1作为cv2。我现在遇到的问题是,尽管我遵循多组指令,但似乎都使用与我自己相同的设置或至少非常类似的设置。我主要通过以下两个示例:openCV.orgCodeGenerater's Blogspot tutorial。我没有忘记创建回调函数或使用cv2.getTrackbarPos。我觉得我的具体顺序或图像显示循环一定有问题。这是我所拥有的,它使用初始轨迹栏阈值显示图像,但不会使用轨迹栏回调更新图像:

import cv2


#write simple callback function to pass trackbar position as *arg    
def callback(*arg): 
    pass

#create display window for image
cv2.namedWindow('frame') 

#read in image
img = cv2.imread(r'/home/Usr/Documents/Aerial-Images/images_with_targets/Flight_4/target_10.jpg',0)

#instantiate trackbar that goes in our named window and uses callback function
cv2.createTrackbar('thresh2','frame',5,15,callback)

#initialize thresholds
thresh1=11
thresh2=5

#loop really just runs until the escape key causes a break
while(True):

    #sets threshold 2 to trackbar position
    thresh2=cv2.getTrackbarPos('thresh2','frame')   
    #apply laplacian filter to ehance edge gradients
    th = cv2.Laplacian(img,cv2.CV_8UC1)
    #binarize image with adaptive threshold
    th = cv2.adaptiveThreshold(th,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,thresh1,thresh2) 

    #show filtered image
    cv2.imshow('frame',th)
    #waits for escape key then breaks out of loop
    if cv2.waitKey(0) & 0xFF == ord('q'):
        break


#close our display window     
cv2.destroyallwindows()

2 个答案:

答案 0 :(得分:0)

答案很简单。在查看我编写的一些旧代码后,我意识到我需要将等待键从0更改为1:

if cv2.waitKey(0) & 0xFF == ord('q'):
    break

成了

if cv2.waitKey(1) & 0xFF == ord('q'):
    break

我没有看到的是我忘记了Camel Case cv2.destroyAllWindows,这让我觉得显示循环仍在运行,但事实并非如此。

答案 1 :(得分:0)

computed: {
    newHeros(){
      return this.getAllHeros.filter(newHero => {
        console.log(newHero.id);
        return newHero.id === this.heroForTab
      })
    }
  },


return {
   heroForTab: ['76NQjrYTdfbWN8xZOAvI', 'uDsm0BValBa31guJs10h']
};

这应该属于while循环

相关问题