简体   繁体   English

代码低FPS的OpenCV Python Line

[英]OpenCV Python Line following Code Low FPS

I tried various ways but i am still getting apx 2-3 fps. 我尝试了各种各样的方法,但我仍然得到apx 2-3 fps。

import cv2

import numpy as np 导入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() 

Do try using a lower frame resolution. 尝试使用较低的帧分辨率。 You can experiment with smaller resolutions and see how the accuracy decreases with decreasing resolution, and find a trade-off. 您可以尝试使用较小的分辨率,并查看精度如何随着分辨率的降低而降低,并找到折衷方案。

Another possibility is to process only a selected region of each frame. 另一种可能性是仅处理每个帧的选定区域。 Suppose you find the line to follow in one region of the image. 假设您在图像的一个区域中找到要遵循的线条。 You can assume that the location of the line does not change much in the next frame, and process only the region around this line. 您可以假设线的位置在下一帧中没有太大变化,并且仅处理该线周围的区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM