gpt4 book ai didi

python - 如何手动设置关键点和提取特征

转载 作者:行者123 更新时间:2023-12-02 16:19:15 26 4
gpt4 key购买 nike

我正在使用 ORB 检测一组图像上的关键点,如本例所示:

enter image description here

我想做的是:我想在图像的特定坐标处手动设置22个点,并将从这些点提取的特征存储到特征向量中。例如:

enter image description here

之后,将这些特征分别存储到一个22维向量中。

我目前用来加载图像和设置关键点的代码是这样的:

import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
from sklearn.utils import Bunch
from skimage.io import imread
import skimage
import cv2

DATADIR = "C:/Dataset"
CATEGORIES = ["class 1", "class 2", "class 3", "class 4", "class 5"]


def load_image_files(fullpath):
descr = "A image classification dataset"
for category in CATEGORIES:
path = os.path.join(DATADIR, category)
for person in os.listdir(path):
personfolder = os.path.join(path, person)
for imgname in os.listdir(personfolder):
class_num = CATEGORIES.index(category)
fullpath = os.path.join(personfolder, imgname)
imageList = skimage.io.imread(fullpath)
orb = cv2.ORB_create(22)
kp, des = orb.detectAndCompute(imageList, None)'''
orb = cv2.ORB_create()
key_points = [cv2.KeyPoint(64, 9, 1), cv2.KeyPoint(107, 6, 10), cv2.KeyPoint(171, 10, 10)]
kp, des = orb.compute(imageList, key_points)
drawnImages = cv2.drawKeypoints(imageList, kp, None, flags= cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imshow("Image", drawnImages)
cv2.waitKey(0)

return Bunch(target_names=CATEGORIES,
images=images,
DESCR=descr)

这些是我希望从中提取特征的坐标

p1 = 60, 10
p2 = 110, 10
p3 = 170, 10
p4 = 25, 60
p5 = 60, 40
p6 = 110, 35
p7 = 170, 35
p8 = 190, 60
p9 = 30, 95
p10 = 60, 80
p11 = 100, 105
p12 = 120, 105
p13 = 160, 180
p14 = 185, 95
p15 = 25, 160
p16 = 55, 160
p17 = 155, 160
p18 = 185, 160
p19 = 65, 200
p20 = 83, 186
p21 = 128, 186
p22 = 157, 197

最佳答案

使用 orb API 中的计算方法。标准的东西是

kp = orb.detect(img,None)
kp, des = orb.compute(img, kp)

但对于您的情况,关键点来自用户输入,因此请使用类似

input_kp = # comes from user
kp, des = orb.compute(img, input_kp)

确保输入关键点与计算方法期望的格式相匹配。您可以像这样从 x、y 值创建关键点。

key_points = [cv2.KeyPoint(x1, y1, 1), cv2.KeyPoint(x2, y2, 1) ...]

关于python - 如何手动设置关键点和提取特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61946202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com