Paul597 4 months ago
parent 793fb1dde9
commit 023fd7db4f

8
.idea/.gitignore vendored

@ -1,8 +0,0 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -1,10 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="95" name="Python" />
</Languages>
</inspection_tool>
</profile>
</component>

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
</project>

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/measure_lib.iml" filepath="$PROJECT_DIR$/.idea/measure_lib.iml" />
</modules>
</component>
</project>

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -54,6 +54,8 @@ def get_data(txt_name):
with open(txt_name, 'r', encoding='utf-8') as f: with open(txt_name, 'r', encoding='utf-8') as f:
lines = f.readlines() lines = f.readlines()
data = [] data = []
if not data:
return None, None, None, None
for i, line in enumerate(lines, 1): for i, line in enumerate(lines, 1):
data.append(line.split()) data.append(line.split())
x = [] x = []
@ -65,7 +67,7 @@ def get_data(txt_name):
x = np.array(x) x = np.array(x)
y = np.array(y) y = np.array(y)
slope, intercept, r_2 = calc_slope_line.linear_regression(x, y) slope, intercept, r_2 = calc_slope_line.linear_regression(x, y)
print(r_2) # print(r_2)
x_bot = [] x_bot = []
y_bot = [] y_bot = []
x_top = [] x_top = []
@ -83,7 +85,7 @@ def get_data(txt_name):
y_top = np.array(y_top) y_top = np.array(y_top)
slope_bot, intercept_bot, r2_bot = calc_slope_line.linear_regression(x_bot, y_bot) slope_bot, intercept_bot, r2_bot = calc_slope_line.linear_regression(x_bot, y_bot)
slope_top, intercept_top, r2_top = calc_slope_line.linear_regression(x_top, y_top) slope_top, intercept_top, r2_top = calc_slope_line.linear_regression(x_top, y_top)
print(f"r2_bot = {r2_bot},r2_top = {r2_top}") # print(f"r2_bot = {r2_bot},r2_top = {r2_top}")
if ((1-r2_bot) > 1e-2) or ((1-r2_bot) > 1e-2): if ((1-r2_bot) > 1e-2) or ((1-r2_bot) > 1e-2):
return None, None, None, None return None, None, None, None
@ -91,7 +93,7 @@ def get_data(txt_name):
for i in range(len(x_bot)): for i in range(len(x_bot)):
if abs(y_bot[i] - slope_bot * x_bot[i] - intercept_bot) > 10: if abs(y_bot[i] - slope_bot * x_bot[i] - intercept_bot) > 10:
delet.append(i) delet.append(i)
print(f"len(x_bot): {len(x_bot)},delet: {delet})") # print(f"len(x_bot): {len(x_bot)},delet: {delet})")
x_bot = np.delete(x_bot, delet) x_bot = np.delete(x_bot, delet)
y_bot = np.delete(y_bot, delet) y_bot = np.delete(y_bot, delet)
# y_pred = slope_bot * x_bot + intercept_bot # y_pred = slope_bot * x_bot + intercept_bot

@ -173,13 +173,13 @@ output_folder = 'C:\\Users\\Administrator\\Desktop\\BYD\\Visual measurement\\pic
# Y = Y + Yw # Y = Y + Yw
# return Z/len(x_bot),-max_Yw # return Z/len(x_bot),-max_Yw
def vs_measurement(txt_name,position): def vs_measurement(txt_name, position = 900):
if not os.path.exists(txt_name): if not os.path.exists(txt_name):
return 0, None,None,None,None return 0, None,None
# 获取数据 # 获取数据
x_bot, y_bot, x_top, y_top = get_data.get_data(txt_name) x_bot, y_bot, x_top, y_top = get_data.get_data(txt_name)
if x_bot.any() == None: if x_bot.any() == None:
return 0, None, None, None, None return -1, None, None
# x_bot = np.array(x_bot) # x_bot = np.array(x_bot)
# y_bot = np.array(y_bot) # y_bot = np.array(y_bot)
# x_top = np.array(x_top) # x_top = np.array(x_top)
@ -236,7 +236,7 @@ def vs_measurement(txt_name,position):
x, y = calc_slope_line.find_intersection((k, -1, b), (slope_top, -1, intercept_top)) x, y = calc_slope_line.find_intersection((k, -1, b), (slope_top, -1, intercept_top))
Zw_intersection = calc_way.calc_height(x_intersection, y_intersection, x, y, alpha, beta) Zw_intersection = calc_way.calc_height(x_intersection, y_intersection, x, y, alpha, beta)
Xw_intersection, Yw_intersection = calc_way.calc_distance(x_intersection, y_intersection, alpha, beta) Xw_intersection, Yw_intersection = calc_way.calc_distance(x_intersection, y_intersection, alpha, beta)
print(Xw_intersection, Yw_intersection)
# #位置修正 # #位置修正
# Yw_intersection = Yw_intersection + model.y # Yw_intersection = Yw_intersection + model.y
Xw_bot = [] Xw_bot = []
@ -265,7 +265,7 @@ def vs_measurement(txt_name,position):
distance = - Yw_intersection * math.cos(angle) distance = - Yw_intersection * math.cos(angle)
distance_pos = -(Yw_pos + model.y) * math.cos(angle) distance_pos = -(Yw_pos + model.y) * math.cos(angle)
# distance_pos = ((-intercept_Xw / slope_Xw) - position) / ((-intercept_Xw / slope_Xw) - Xw_intersection) * distance # distance_pos = ((-intercept_Xw / slope_Xw) - position) / ((-intercept_Xw / slope_Xw) - Xw_intersection) * distance
return 1, Zw_intersection, distance, Zw_pos, distance_pos return 1, Zw_pos, distance_pos
if __name__ == '__main__': if __name__ == '__main__':

@ -1,11 +0,0 @@
函数说明vs_measurement(txt_name,position)
txt_name : 路沿数据文件路径
position 车身某点P距离摄像头在X轴车行进方向的偏移车头为正车尾为负。
如不输入该参数默认为900指向前车轮中心位置。
返回值stateZw_pos, distance_pos
state : -1 , Zw_pos, distance_pos都为None表示txt_name 所传输的数据为空或无法使用
state : 0 , Zw_pos, distance_pos都为None表示txt_name路径不存在
state : 1
Zw_pos返回P点对应路沿的高度distance_pos返回P点距离路沿的距离

@ -221,5 +221,4 @@ def vs_measurement(txt_name,position):
return Zw_intersection, distance, Zw_pos , distance_pos return Zw_intersection, distance, Zw_pos , distance_pos
#
vs_measurement(txt_name,877)

Loading…
Cancel
Save