c语言版本和算法原理的可以查看本人的其他文档。《自动驾驶AVM环视算法–更新超广角视图算法和exe测试demo》本文档进用于展示部分代码的视线,获取方式网盘自行获取(非免费介意勿下载):链接: https://pan.baidu.com/s/1oYChfFYbWtrSvOgQzw7nYQ 提取码: 6a35 。
测试的环境:
以下是主运行函数的部分代码(仅供参考):
import cv2
from runAngle import *
# 导入 MyClass 类
from runAngle import avmobjData
flag =0#设置视角,0f 1b 2l 3r
# 创建类的实例
runAngle = avmobjData()
F_open=True
B_open=True
L_open=True
R_open=True
F_video=cv2.VideoCapture("video/Front.avi")
if F_video.isOpened():
F_ocpn,F_frame=F_video.read()
else:
F_open=False
B_video=cv2.VideoCapture("video/Back.avi")
if B_video.isOpened():
B_ocpn,B_frame=B_video.read()
else:
B_open=False
L_video=cv2.VideoCapture("video/Left.avi")
if L_video.isOpened():
L_ocpn,L_frame=L_video.read()
else:
L_open=False
R_video=cv2.VideoCapture("video/Right.avi")
if R_video.isOpened():
R_ocpn,R_frame=R_video.read()
else:
R_open=False
print(F_open,B_open,L_open,R_open)
if flag==0:
while F_open :
F_ret,F_frame=F_video.read()
srcH, srcW, _ = F_frame.shape
# 设置目标图像的宽度和高度
dstW = srcH * 3
dstH = srcH
# 调用 js_imgRect 函数
Dstimg = runAngle.js_imgRect(F_frame, srcW, srcH, dstW, dstH)
if F_frame is None:
break
if F_ret==True :
cv2.imshow("avmAngle",Dstimg)
if cv2.waitKey(25) & 0xFF==27:
break
F_video.release()
cv2.destroyAllWindows()
if flag==1:
while B_open:
B_ret,B_frame=B_video.read()
srcH, srcW, _ = B_frame.shape
# 设置目标图像的宽度和高度
dstW = srcH * 3
dstH = srcH
# 调用 js_imgRect 函数
Dstimg = runAngle.js_imgRect(B_frame, srcW, srcH, dstW, dstH)
if B_frame is None :
break
if B_ret==True:
cv2.imshow("avmAngle",Dstimg)
if cv2.waitKey(25) & 0xFF==27:
break
B_video.release()
cv2.destroyAllWindows()
if flag==2:
while L_open:
L_ret,L_frame=L_video.read()
srcH, srcW, _ = L_frame.shape
# 设置目标图像的宽度和高度
dstW = srcH * 3
dstH = srcH
# 调用 js_imgRect 函数
Dstimg = runAngle.js_imgRect(L_frame, srcW, srcH, dstW, dstH)
if L_frame is None:
break
if L_ret==True:
cv2.imshow("avmAngle",Dstimg)
if cv2.waitKey(25) & 0xFF==27:
break
L_video.release()
cv2.destroyAllWindows()
if flag==3:
while R_open:
R_ret,R_frame=R_video.read()
srcH, srcW, _ = R_frame.shape
# 设置目标图像的宽度和高度
dstW = srcH * 3
dstH = srcH
# 调用 js_imgRect 函数
Dstimg = runAngle.js_imgRect(R_frame, srcW, srcH, dstW, dstH)
if R_frame is None:
break
if R_ret==True:
cv2.imshow("avmAngle",Dstimg)
if cv2.waitKey(25) & 0xFF==27:
break
R_video.release()
cv2.destroyAllWindows()
注:当前python的版本效率比较低,需要加速的可以自行优化加速代码,实现的过程是从C代码直接转换过来的,没有进行任何的优化加速。
测试实现的效果: