我尝试了各种各样的方法,但我仍然得到apx 2-3 fps。
import cv2
将numpy导入为np
import cv2
import numpy as np
##cap = cv2.imread('C:\\Users\\efeongan\\Desktop\\PYTHOn_OPENCV\\linetest.mp4')
cap = cv2.VideoCapture('C:\\Users\\efeongan\\Desktop\\PYTHOn_OPENCV\\linetest.mp4')
while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
lowbg = np.array([0,0,0])
highbg = np.array([50, 50, 50])
kernel = np.ones([10, 10], np.uint8)
mask = cv2.inRange(frame, lowbg, highbg)
res = cv2.bitwise_and(gray, gray, mask = mask)
dilation = cv2.dilate(res, kernel, iterations = 1)
lines = cv2.HoughLinesP(dilation,rho=0.02,theta=np.pi/500, threshold=100,lines=np.array([]), minLineLength= 0)
a,b,c = lines.shape
if lines[1][0][0] > 240:
diff = lines[1][0][0] - 240
print(diff)
if lines[1][0][0] < 240:
diff = 220 - lines[1][0][0]
print(diff)
for i in range(a):
cv2.line(dilation, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (255, 255, 255), 3, cv2.LINE_AA)
cv2.line(frame, (240, 800), (240 + diff, 800), (255,0,0),10)
cv2.putText(frame,str(diff),(240 + diff,800), cv2.FONT_HERSHEY_SIMPLEX, 1, 255)
print("x", lines[1][0][0], cnts)
cv2.imshow('raw', frame)
k = cv2.waitKey(1)
if k == 27:
brak
cv2.desrtroyAllWindows()
&#13;
答案 0 :(得分:0)
尝试使用较低的帧分辨率。您可以尝试使用较小的分辨率,并查看准确度如何随着分辨率的降低而降低,并找到折衷方案。
另一种可能性是仅处理每个帧的选定区域。假设您在图像的一个区域中找到要遵循的线条。您可以假设线的位置在下一帧中没有太大变化,只处理该线周围的区域。