问题描述
我正在尝试使用 Python 和 OpenCV 在 RaspBerry 上制作车道保持算法。我使用以下管道 Image(RGB)(resolution 320x240) -> Image (Gray) -> Region Growing algorithm -> Canny Edges -> Cropping the ROI -> houghlinesp -> 根据线的斜率计算转向角。
我最近刚刚在流水线中添加了区域增长算法,从那时起,单个图像的处理时间增加了 4 秒,汽车只是等待指令的时间,看起来对汽车来说真的很糟糕去懒惰。但是将算法添加到管道中使汽车做出正确的决定,所以我无法删除它。
如何使处理速度更快?
def get_gray_diff(self,img,currentPoint,tmpPoint):
aux1 = int(img[currentPoint.x,currentPoint.y])
aux2 = int(img[tmpPoint.x,tmpPoint.y])
aux3 = abs(aux1 - aux2)
return aux3
def select_connects(self,p):
if p != 0:
connects = [Point(-1,-1),Point(0,Point(1,0),1),Point(-1,0)]
else:
connects = [Point(0,0)]
return connects
def region_grow(self,frame):
seeds = [Point(230,160)]
thresh = 6
p = 1
height,weight = frame.shape
seedMark = np.zeros(frame.shape)
seedList = []
for seed in seeds:
seedList.append(seed)
label = 1
connects = self.select_connects(p)
while len(seedList)>0:
currentPoint = seedList.pop(0)
seedMark[currentPoint.x,currentPoint.y] = label
for i in range(8):
tmpX = currentPoint.x + connects[i].x
tmpY = currentPoint.y + connects[i].y
if tmpX < 0 or tmpY < 0 or tmpX >= height or tmpY >= weight:
continue
grayDiff = self.get_gray_diff(frame,Point(tmpX,tmpY))
if grayDiff < thresh and seedMark[tmpX,tmpY] == 0:
seedMark[tmpX,tmpY] = label
seedList.append(Point(tmpX,tmpY))
return seedMark
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)