Paul597 3 months ago
parent 9792ce7ecf
commit 82d3297472

@ -194,7 +194,7 @@ def fun(x,cameraModel,corners):
error_y = 0
error_x = 0
f = cameraModel.focal_length
H = x[3] - 9
H = x[3] -0
gamma = math.atan(1 / (math.tan(x[0]) * math.tan(x[1])))
seta = math.atan(1 / math.sqrt(pow(math.tan(x[1]), 2) + 1 / pow(math.tan(x[0]), 2)))
column = 0
@ -231,11 +231,11 @@ def fun(x,cameraModel,corners):
def get_result(cameraModel, corners):
params = cameraModel, corners
bounds = [(0.1, 1.7), (0.1, 1.7), [-0.5, 0.5],[1000,1020]]
bounds = [(0.1, 1.7), (0.1, 1.7), [-0.5, 0.5],[1000-9,1020-9]]
# bounds = [(0.1, 1.7), (0.1, 1.7)]
result = minimize(
fun,
x0=[cameraModel.rotation_alpha, cameraModel.rotation_beta, 0, cameraModel.height],
x0=[cameraModel.rotation_alpha, cameraModel.rotation_beta, 0, 998],
args=params,
# method='Nelder-Mead', # 或 'trust-constr'
method='L-BFGS-B', bounds=bounds,
@ -347,6 +347,7 @@ def check_Extrinsic_Parameters(image_path, output_path, config):
# image_path = r"C:\Users\Administrator\Desktop\BYD\Visual measurement_model\Visual measurement\img\calibration\origin_img\*.jpg"
# output_fold =r"C:\Users\Administrator\Desktop\BYD\Visual measurement_model\Visual measurement\img\calibration\undistor_img"
# config = r"updated_config.json"
# find_corners(r"C:\Users\Administrator\Desktop\BYD\7.15\)
# calibrate_and_undistort(image_path,output_fold,config,11,8,60)
# calibrate_Extrinsic_Parameters("corrected.jpg", config, 11, 8)
# check_Extrinsic_Parameters("corrected.jpg", "output.jpg", config)
@ -361,3 +362,9 @@ def check_Extrinsic_Parameters(image_path, output_path, config):
# img = cv2.imread(r"C:\Users\Administrator\Desktop\BYD\0718\new415.379489173224.jpg")
# cv2.line(img, (int(229.67793558711742), 960-int(151.71034206841367)), (result[3],result[4]), (0, 255, 255), 3)
# cv2.imwrite(r"test.jpg", img)
# image_path = r"C:\Users\Administrator\Desktop\BYD\8.5\*.jpg"
# output_fold = r"C:\Users\Administrator\Desktop\BYD\8.5\undistor_img"
# config = r"updated_config.json"
# # find_corners(image_path,7,6)
# calibrate_and_undistort(image_path,output_fold,config,9,8,100)

@ -52,7 +52,7 @@ def calc_distance(cameraModel, x: float, y: float) -> tuple[float, float]:
Xw = d * math.cos(gamma + epsilon)
Yw = -d * math.sin(gamma + epsilon)
return Xw, Yw
return Xw*cameraModel.zoom, Yw*cameraModel.zoom
def calc_distance2(cameraModel, Xw: float, Yw: float) -> tuple[int, int]:
@ -72,7 +72,7 @@ def calc_distance2(cameraModel, Xw: float, Yw: float) -> tuple[int, int]:
像素坐标 (x, y)类型为整数
"""
# 1. 计算距离 d 和角度 seta、gamma
d = math.hypot(Xw, Yw)
d = math.hypot(Xw/cameraModel.zoom, Yw/cameraModel.zoom)
tan_alpha = math.tan(cameraModel.rotation_alpha)
tan_beta = math.tan(cameraModel.rotation_beta)
seta = math.atan2(1, math.sqrt(tan_beta ** 2 + 1 / tan_alpha ** 2))

@ -33,6 +33,7 @@ class CameraModel:
"ransac_residual_threshold": 2.5,
"grid_downsample": True,
"cell_size": 10,
"zoom":1.1,
}
@ -62,6 +63,7 @@ class CameraModel:
self.ransac_residual_threshold = params["ransac_residual_threshold"]
self.grid_downsample = params["grid_downsample"]
self.cell_size = params["cell_size"]
self.zoom = params["zoom"]
# 计算派生属性
self.pixel_size_x = self.focal_length / self.undistor_K[0, 0]
self.pixel_size_y = self.focal_length / self.undistor_K[1, 1]
@ -93,7 +95,8 @@ class CameraModel:
"outlier_num": self.outlier_num,
"grid_downsample": self.grid_downsample,
"cell_size": self.cell_size,
"ransac_residual_threshold": self.ransac_residual_threshold
"ransac_residual_threshold": self.ransac_residual_threshold,
"zoom": self.zoom
}
with open(file_path, 'w') as f:
json.dump(params, f, indent=4)

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 KiB

@ -3,14 +3,14 @@
"camera_height": 960,
"origin_K": [
[
1086.5841123501,
1086.32711,
0.0,
656.379279306796
657.410789
],
[
0.0,
1086.65442545872,
470.898109737448
1086.44329,
483.660145
],
[
0.0,
@ -20,14 +20,14 @@
],
"undistor_K": [
[
838.19297892,
838.19297635,
0.0,
658.51580973
658.51581017
],
[
0.0,
836.93529706,
475.57774991
836.9352939,
476.42225023
],
[
0.0,
@ -43,16 +43,17 @@
-0.0447846385
],
"focal_length": 3.6,
"height": 1007.0633042608584,
"rotation_alpha": 0.8892272342384955,
"rotation_beta": 0.6786627929104145,
"position_offset_x": 507,
"position_offset_y": 32,
"rotation_camera": 0.03985022053087201,
"height": 1026.4662744946722,
"rotation_alpha": 0.8169354601554343,
"rotation_beta": 0.8367541143814101,
"position_offset_x": 456,
"position_offset_y": 33,
"rotation_camera": 0.3727577077788678,
"filter": true,
"filt_percent": 0.05,
"filt_percent": 0.1,
"outlier_num": 10,
"grid_downsample": true,
"cell_size": 10,
"ransac_residual_threshold": 2.5
"ransac_residual_threshold": 2.5,
"zoom": 1.0
}
Loading…
Cancel
Save