From 9bc07d829bd2268129926c32773b177b75e32d95 Mon Sep 17 00:00:00 2001 From: zjn Date: Sun, 13 Aug 2023 10:33:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=91=84=E5=83=8F=E5=A4=B4?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/infer-onnx.py | 14 +++++++++----- deploy/utils/base_model_infer.py | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/deploy/infer-onnx.py b/deploy/infer-onnx.py index aea4a10..0e9dca1 100644 --- a/deploy/infer-onnx.py +++ b/deploy/infer-onnx.py @@ -37,11 +37,13 @@ class Args: def main(): model_infer = ONNXInfer(Args.weight_file) - camera_matrix = np.array([[309.90395107, 0.00000000e+00, 300.39021399], [0.00000000e+00, 302.16360458, 246.21441832], [0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]) - distortion_coefficients = np.array([-0.32984359, 0.11556734, -0.00545855, 0.00248696, -0.01897801]) + camera_matrix = np.array([[654.70620869, 0.00000000e+00, 620.18116133], [0.00000000e+00, 656.66098208, 433.29648979], [0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]) + distortion_coefficients = np.array([-0.32841624, 0.10118464, 0.00383333, 0.00071582, -0.01392005]) # cap = cv2.VideoCapture(Args.video) cap = cv2.VideoCapture(0) + cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280) + cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 960) skip_frame = 2 # 每隔 skip_frame 帧进行一次推理 i = 0 try: @@ -66,13 +68,15 @@ def main(): crop_h = int(img_w * 0.36) # 0.36 = 288 / 800 # crop_h = 0 # 如果不裁切,可以改成 0 - img = cv2.resize(frame, (img_w, img_h)) + img=img[200:, :] + # img = cv2.resize(frame, (img_w, img_h)) + add_h = img_h - 0 crop_img = img[add_h : img_h, :, :] # 裁切下半部分 - img = undistort_image(frame, camera_matrix, distortion_coefficients) - img = img[0: img_h, :600, :] # 裁切下半部分 + img = undistort_image(img, camera_matrix, distortion_coefficients) + img = img[:, :1200, :] # 裁切下半部分 # img = color_extraction(img) infer_result: InferResult = model_infer.infer(img) diff --git a/deploy/utils/base_model_infer.py b/deploy/utils/base_model_infer.py index d6e073e..a291506 100644 --- a/deploy/utils/base_model_infer.py +++ b/deploy/utils/base_model_infer.py @@ -195,9 +195,9 @@ def infer(self, img: np.ndarray, is_kalman=False): if (left_x0 == 0 and right_x0 == 0): y_offset = np.int32(0) elif (left_x0 != 0 and right_x0 == 0): - y_offset = np.int32(left_x0 - 20) + y_offset = np.int32(left_x0 - 40) elif (left_x0 == 0 and right_x0 != 0): - y_offset = np.int32(right_x0 - 580) + y_offset = np.int32(right_x0 - 1160) else: y_offset = np.int32(predict_direct[0][0] - forward_direct[0][0])