我卡住了。我的代码糟透了。我的银粉也不起作用,但是无限的图像窗口让我发疯了。当我关闭namedWindow时,它会打开一个新的显示窗口,显示图像(无限)。帮助?
import numpy as np
import cv2
from pylepton import Lepton
#setup the Lepton image buffer
def capture(device = "/dev/spidev0.0"):
with Lepton() as l:
a,_ = l.capture() #grab the buffer
cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX) # extend contrast
np.right_shift(a, 8, a) # fit data into 8 bits
return np.uint8(a)
#Create a window and give it features
def nothing(x):
pass
cv2.namedWindow('flir', cv2.WINDOW_NORMAL)
cv2.moveWindow('flir',1,1)
cv2.createTrackbar('thresh','flir',50,100,nothing)
cv2.createTrackbar('erode','flir',5,100,nothing)
cv2.createTrackbar('dilate','flir',7,100,nothing)
#process the buffer into an image on a continuous loop
while True:
#update the image processing variables
thresh = cv2.getTrackbarPos('thresh', 'flir')
erodeSize = cv2.getTrackbarPos('erode', 'flir')
dilateSize = cv2.getTrackbarPos('dilate', 'flir')
image = capture()
#apply some image processing
blurredBrightness = cv2.bilateralFilter(image,9,150,150)
thresh = 50
edges = cv2.Canny(blurredBrightness,thresh,thresh*2, L2gradient=True)
_,mask = cv2.threshold(blurredBrightness,200,1,cv2.THRESH_BINARY)
erodeSize = 5
dilateSize = 14
eroded = cv2.erode(mask, np.ones((erodeSize, erodeSize)))
mask = cv2.dilate(eroded, np.ones((dilateSize, dilateSize)))
adjusted_image = cv2.resize(cv2.cvtColor(mask*edges, cv2.COLOR_GRAY2RGB) | image, (640, 4$
final_image = cv2.applyColorMap(adjusted_image, cv2.COLORMAP_HOT)
#display the image
cv2.imshow('flir', final_image)
if cv2.waitKey(1) == ord('q'):
break
cv2.waitKey()
cv2.destroyWindow('flir')发布于 2016-12-04 08:04:26
首先,冷静。
其次,仔细查看代码。关上窗户对你没有任何好处,因为下面的字句:
cv2.imshow('flir', final_image)和
cv2.destroyWindow('flir')这两个步骤是在新窗口中显示一个框架,然后销毁它,然后在imshow中重新创建该窗口,然后显示下一个框架和销毁it...and等等。
这应该可以解释你闪烁的窗户。
为了停止程序的执行,您添加了以下代码:
if cv2.waitKey(1) == ord('q'):
break这意味着,当你按下'q‘在你的键盘上,而你的图像窗口在焦点,你的时间循环将中断,你的程序将终止。
因此,我建议您删除cv2.destroyWindow并使用'q‘键退出您的应用程序,而不是使用鼠标关闭它。
https://stackoverflow.com/questions/40956018
复制相似问题