1
我嘗試了各種方法,但我仍然得到apx 2-3 fps。OpenCV蟒蛇線以下代碼低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()
它的工作謝謝 –