gpt4 book ai didi

python - Python:输入文本框与OpenCV Live网络摄像头图像并行捕获用户输入

转载 作者:行者123 更新时间:2023-12-02 17:13:46 24 4
gpt4 key购买 nike

我有一个简单的脚本正在运行流式网络摄像头的图像,并且我想执行一些操作,例如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过滤器和hough函数的参数,因此我想使一些输入框与liveimage窗口并行运行,在其中我可以输入这些值。

我想到了最简单的解决方案,可以减少编码开销,从而选择tkinter。但是我很难并行运行tkinter-box(仅从这里找到此解决方案: How do you run your own code alongside Tkinter's event loop?),这使我在使用#1中的代码并将liveimage放入其中时,实时图像的显示非常慢。 task函数。

您能建议我一个简单的解决方案,显示输入框,用户可以在其中输入用作我的代码中Canny / Houghlines参数的数字吗?

谢谢

最佳答案

我相信他们在cv2命名空间中。我认为我的版本是2.4.5

import cv2
import numpy as np

def onTrackbarChange(trackbarValue):
pass

cv2.namedWindow('ctrl')
cv2.createTrackbar( 'thresh', 'ctrl', 128, 255, onTrackbarChange )
c = cv2.VideoCapture(0)
while(1):
im = c.read()[1]
thresh=cv2.threshold(cv2.cvtColor(im,cv2.COLOR_BGR2GRAY),
cv2.getTrackbarPos('thresh','ctrl'),
255,cv2.THRESH_BINARY)[1]
cv2.imshow('thresh',thresh)
if cv2.waitKey(1)==27:
exit(0)

关于python - Python:输入文本框与OpenCV Live网络摄像头图像并行捕获用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20959278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com