我有一个简单的脚本运行流式传输我的网络摄像头的图像,我想做一些像canny-filter和hough转换一样的操作来检测liveimage中的行:Python:输入文本框并行捕获userinput到OpenCV Live网络摄像头图像
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()
的问题是,我需要微调精明的过滤器和霍夫,函数的参数,因此我想做出一些输入框平行于liveimage窗口运行在那里我可以输入这些值。
我想到了最简单的解决方案,可以减少编码开销,从而选择tkinter。但是我很难同时运行tkinter-box(只能从这里找到这个解决方案:How do you run your own code alongside Tkinter's event loop?),这使得当我使用来自帖子#1的代码并将我的liveimage功能task。
你能告诉我一个简单的解决方案,显示输入框,用户可以在其中输入用作Canny/houghlines参数的数字吗?
谢谢
2014-01-06
tim
+2
你可以使用opencv附带的滑块吗?有限,因为它们工作得很好 –
+0
啊我想知道它们是否可用于cv2,因为我在文档中看不到它们:http://docs.opencv.org/modules/highgui/doc/ user_interface.html#createtrackbar为什么它们不可用?是要导入旧的opencv版本,如'import cv2.cv as cv',然后通过'cv.CreateTrackbar(..)'命令使用它? –
+0
噢,谢谢,它就像一个魅力!精彩。你还能向我解释为什么opencv中的一些命令只能通过* old *'cv'访问,而没有移植到cv2?我只是想知道.. –