python如何将2个lidar点云图像对齐

import cv2
import numpy as np

# 读取图像并转为灰度
img1 = cv2.imread('output_image_rotate6.jpg', cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread('output_image_standard6.jpg', cv2.IMREAD_GRAYSCALE)

# 初始化SIFT检测器
sift = cv2.SIFT_create()

# 检测关键点并计算描述符
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)

# 使用暴力匹配器进行特征匹配
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)


# np.float64(-2.5418798426532048), np.float64(-0.7227428481105767)
result = 2.5418798426532048 / 0.7227428481105767
print(result)  # 输出: 3.3333333333333335
print("result=",result)


# 应用比率测试筛选优质匹配
good_matches = []
for m, n in matches:
    if m.distance < 0.75 * n.distance:
        good_matches.append(m)

# 至少需要2个匹配点来估计变换
if len(good_matches) > 4:
    src_pts = np.float32([kp1[m.queryIdx].pt for m in good_matches]).reshape(-1, 1, 2)
    dst_pts = np.float32([kp2[m.trainIdx].pt for m in good_matches]).reshape(-1, 1, 2)

    # 估计相似变换矩阵(旋转、平移、缩放)
    M, _ = cv2.estimateAffinePartial2D(src_pts, dst_pts)

    print(M)

    if M is not None:
        # 提取平移参数
        tx = M[0, 2]
        ty = M[1, 2]

        # 提取旋转角度(弧度转角度)
        angle_rad = np.arctan2(M[1, 0], M[0, 0])
        angle_deg = np.degrees(angle_rad)

        print(tx)
        print(ty)
        print(f"平移距离:Δx = {tx:.2f} 像素, Δy = {ty:.2f} 像素")
        print(f"旋转角度:{angle_deg:.2f} 度")
        print(ty/tx)
    else:
        print("无法估计变换矩阵")
else:
    print("匹配点不足,无法对齐")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qqqweiweiqq

你的鼓励将是我最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值