OPENCV-计算给定Harris角功能的SIFT描述符

发布于 2025-01-26 05:55:57 字数 433 浏览 3 评论 0原文

我需要计算OpenCV中Harris角检测的给定功能的SIFT描述符。我该怎么做?您能为我提供一些代码示例来修改筛分计算方法吗?

到目前为止,我的代码:

import cv2 as cv

img = cv.imread('example_image.png')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
dst = cv.cornerHarris(gray, 2, 3, 0.05)
dst = cv.dilate(dst, None)

现在我想添加类似的内容:

sift = cv.SIFT_create()
sift.compute(#Pass Harris corner features here)

这可能吗?我搜索了一段时间,但找不到任何东西。谢谢你们。

I need to calculate the SIFT descriptors for given features from the Harris Corner detection in OpenCV. How would I do that? Could you provide me some code examples to modify the SIFT-compute method?

My code so far:

import cv2 as cv

img = cv.imread('example_image.png')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
dst = cv.cornerHarris(gray, 2, 3, 0.05)
dst = cv.dilate(dst, None)

And now I want to add something like this:

sift = cv.SIFT_create()
sift.compute(#Pass Harris corner features here)

Is this possible? I searched for a while, but I couldn't find anything. Thank you guys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨扶苏 2025-02-02 05:55:57

这里已经有一个答案:

我如何创建关键点计算筛子?

解决方案:

import numpy as np
import cv2 as cv

def harris(img):
    gray_img = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
    gray_img = np.float32(gray_img)
    dst = cv.cornerHarris(gray_img, 2, 3, 0.04)
    result_img = img.copy() # deep copy image
    # Threshold for an optimal value, it may vary depending on the image.
    # draws the Harris corner key-points on the image (RGB [0, 0, 255] -> blue)
    result_img[dst > 0.01 * dst.max()] = [0, 0, 255]
    # for each dst larger than threshold, make a keypoint out of it
    keypoints = np.argwhere(dst > 0.01 * dst.max())
    keypoints = [cv.KeyPoint(float(x[1]), float(x[0]), 13) for x in keypoints]
    return (keypoints, result_img)


if __name__ == '__main__':
    img = cv.imread('example_Image.png')
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

    # Calculate the Harris Corner features and transform them to  
    # keypoints (so they are not longer as a dst matrix) which can be 
    # used to feed them into the SIFT method to calculate the SIFT
    # descriptors:
    kp, img = harris(img)

    # compute the SIFT descriptors from the Harris Corner keypoints 
    sift = cv.SIFT_create()
    sift.compute(img, kp)
    img = cv.drawKeypoints(img, kp, img)

    cv.imshow('dst', img)
    if cv.waitKey(0) & 0xff == 27:
        cv.destroyAllWindows()

There was an answer to this topic already here:

How do I create KeyPoints to compute SIFT?

The solution:

import numpy as np
import cv2 as cv

def harris(img):
    gray_img = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
    gray_img = np.float32(gray_img)
    dst = cv.cornerHarris(gray_img, 2, 3, 0.04)
    result_img = img.copy() # deep copy image
    # Threshold for an optimal value, it may vary depending on the image.
    # draws the Harris corner key-points on the image (RGB [0, 0, 255] -> blue)
    result_img[dst > 0.01 * dst.max()] = [0, 0, 255]
    # for each dst larger than threshold, make a keypoint out of it
    keypoints = np.argwhere(dst > 0.01 * dst.max())
    keypoints = [cv.KeyPoint(float(x[1]), float(x[0]), 13) for x in keypoints]
    return (keypoints, result_img)


if __name__ == '__main__':
    img = cv.imread('example_Image.png')
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

    # Calculate the Harris Corner features and transform them to  
    # keypoints (so they are not longer as a dst matrix) which can be 
    # used to feed them into the SIFT method to calculate the SIFT
    # descriptors:
    kp, img = harris(img)

    # compute the SIFT descriptors from the Harris Corner keypoints 
    sift = cv.SIFT_create()
    sift.compute(img, kp)
    img = cv.drawKeypoints(img, kp, img)

    cv.imshow('dst', img)
    if cv.waitKey(0) & 0xff == 27:
        cv.destroyAllWindows()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文