[英]OpenCV Python kernel crashes when clicking the trackbar
I am trying to create a simple trackbar to test some edge detection, and I've been following the official opencv tutorial fromhere in Python.我正在尝试创建一个简单的轨迹条来测试一些边缘检测,并且我一直在关注Python中的官方 opencv 教程。 When I run the code, the window is created and I can see the sliders, but when I click the sliders, the kernel crashes.
当我运行代码时,创建了 window 并且我可以看到滑块,但是当我单击滑块时,kernel 崩溃。
I tried this with some other code example from the internet and it crashed then as well.我用互联网上的其他代码示例尝试了这个,然后它也崩溃了。 Basically the moment I click in the region of the slider, the kernel crashes.
基本上,当我单击 slider 区域时,kernel 就会崩溃。 I know that one thing you seem to need to do in macs is increase the
waitKey
time and I did do that.我知道你似乎需要在 mac 中做的一件事是增加
waitKey
时间,我确实这样做了。
How can I make this work?我怎样才能使这项工作?
def canny_threshold(low_val, src, src_gray):
low_threshold = low_val
img_blur = cv.blur(src_gray, (3,3))
detected_edges = cv.Canny(img_blur, low_threshold, low_threshold * RATIO)
mask = detected_edges != 0
dst = src * (mask[:,:, None].astype(src.dtype))
return dst
src = cv.imread("magpie_house.jpeg")
src_gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
def nothing(x):
pass
cv.namedWindow(WINDOW_NAME)
cv.startWindowThread()
cv.createTrackbar(TITLE_TRACK_BAR, WINDOW_NAME, 0, MAX_LOW_THRESHOLD, nothing)
cv.setTrackbarPos(TITLE_TRACK_BAR, WINDOW_NAME, 50)
while True:
COUNTER += 1
if COUNTER >= 700:
break
low_val = cv.getTrackbarPos(TITLE_TRACK_BAR, WINDOW_NAME)
dst = canny_threshold(low_val, src, src_gray)
cv.imshow(WINDOW_NAME, dst)
if cv.waitKey(10) & 0xFF == ord("q"):
break
cv.waitKey(1)
cv.destroyAllWindows()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.