py实现surf特征提取

py 复制代码
import cv2

def main():
    # 加载图像
    image1 = cv2.imread('image1.jpg', cv2.IMREAD_GRAYSCALE)
    image2 = cv2.imread('image2.jpg', cv2.IMREAD_GRAYSCALE)

    # 创建SURF对象
    surf = cv2.xfeatures2d.SURF_create()

    # 检测特征点和描述符
    keypoints1, descriptors1 = surf.detectAndCompute(image1, None)
    keypoints2, descriptors2 = surf.detectAndCompute(image2, None)

    # 绘制特征点
    result_image1 = cv2.drawKeypoints(image1, keypoints1, None, (0, 255, 0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    result_image2 = cv2.drawKeypoints(image2, keypoints2, None, (0, 255, 0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

    # 显示图像
    cv2.imshow("Image 1", result_image1)
    cv2.imshow("Image 2", result_image2)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()
py 复制代码
import cv2
import numpy as np

def main():
    # 加载图像
    image1 = cv2.imread('image1.jpg', cv2.IMREAD_GRAYSCALE)
    image2 = cv2.imread('image2.jpg', cv2.IMREAD_GRAYSCALE)

    # 创建SURF对象
    surf = cv2.xfeatures2d.SURF_create()

    # 检测特征点和描述符
    keypoints1, descriptors1 = surf.detectAndCompute(image1, None)
    keypoints2, descriptors2 = surf.detectAndCompute(image2, None)

    # 创建匹配器
    matcher = cv2.DescriptorMatcher_create(cv2.DescriptorMatcher_FLANNBASED)
    matches = matcher.match(descriptors1, descriptors2)

    # 根据距离排序匹配项
    matches = sorted(matches, key=lambda x: x.distance)

    # 提取前10个最佳匹配项
    good_matches = matches[:10]

    # 绘制匹配点和线条
    result_image = cv2.drawMatches(image1, keypoints1, image2, keypoints2, good_matches, None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)

    # 显示图像
    cv2.imshow("Matches", result_image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()
相关推荐
lpfasd1234 小时前
2026年第30周科技社区趋势周报:开放权重之争与AI Agent的破局
人工智能·科技
佛光芳林6 小时前
AI 情报局:用 PowerMem + SeekDB 做一个多 Agent 记忆小游戏
人工智能
通问AI6 小时前
2026年AI短剧技术现状:全链路AIGC生产已达95%,但用户完播率不足15%
人工智能·aigc
_Jimmy_6 小时前
Agent引用数据库知识过时的增量同步方案
人工智能·python·langchain
qq_454245036 小时前
Systemprompt 体系全览:形式化公理驱动的分层系统设计
人工智能
大龄码农有梦想6 小时前
传统的 BPMN 工作流审批和 AI 工作流有什么区别?
人工智能·流程引擎·工作流·ai agent·ai工作流·审批流·智能体平台
DO_Community6 小时前
Claude Opus 5 现已上线 DigitalOcean AI 推理云
人工智能·llm·agent·claude
幸福指北6 小时前
🚀 开源了,一个人 + AI 肝出一个 AI 终端 | AShell 技术分享
运维·人工智能·ai·终端
可以飞的话6 小时前
一、机器学习概述
人工智能·机器学习
sunneo7 小时前
磐石2.0发布,科学建模新突破
人工智能