【发布时间】:2014-01-06 21:06:47
【问题描述】:
我有一个运行网络摄像头图像流式传输的简单脚本,我想做一些操作,如 canny-filter 和 hough 变换来检测实时图像中的线条:
import cv2
import math
# Init
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame1',frame)
cv2.imshow('frame2',gray)
cv2.moveWindow('frame1', 200, 10)
cv2.moveWindow('frame2', 200+660, 10)
# (3.)
edges = cv2.Canny(frame, 40, 100)
cv2.imshow('lines',edges)
cv2.moveWindow('lines', 200, 10+530)
# hough
lines = cv2.HoughLinesP(edges, 1, math.pi/2, 20, None, 100, 10)
edgeimg = gray
if not lines is None:
for line in lines[0]:
pt1 = (line[0],line[1])
pt2 = (line[2],line[3])
cv2.line(edgeimg, pt1, pt2, (255,0,0), 3)
cv2.imshow('hough',edgeimg)
cv2.moveWindow('hough', 200+660, 10+530)
# cv2.imshow('img',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
问题是我需要微调 canny-filter 和 hough-function 的参数,因此我想让一些输入框与我可以输入这些值的 liveimage-windows 并行运行。
我想到了最简单的解决方案来减少编码开销,因此选择了 tkinter。但是我很难并行运行 tkinter-boxes(仅从此处找到此解决方案:How do you run your own code alongside Tkinter's event loop?),当我使用帖子 #1 中的代码并将我的liveimage 到task 函数中。
你能告诉我一个简单的解决方案吗?显示输入框,用户可以在其中输入数字,用作我的代码中 canny/houghlines 的参数?
谢谢
【问题讨论】:
-
可以用opencv自带的滑块吗?尽管它们是有限的,但它们工作得很好
-
啊我想知道它们是否在 cv2 中可用,因为我在文档中看不到它们:docs.opencv.org/modules/highgui/doc/… 为什么它们不可用?像
import cv2.cv as cv这样导入旧的opencv版本然后通过cv.CreateTrackbar(..)命令使用它的方法是什么?? -
哦,是的,谢谢,它就像一个魅力!精彩的。您能否向我解释一下为什么 opencv 中的某些命令只能通过 old
cv访问而尚未移植到 cv2?我只是想知道它..
标签: python opencv input hough-transform inputbox