Python Opencv 提取图像特征

灰度特征

代码如下:

def img2cols(self, img):
    img = img.reshape(img.size, order="C")
    # convert the data type as np.float64
    img = img.astype(np.float64)
    return img

HOG特征

代码如下:

def HOG_features(self, im):
    hog = cv2.HOGDescriptor()
    winStride = (8, 8)
    padding = (8, 8)
    hist = hog.compute(im, winStride, padding)
    hist = hist.reshape((-1,))
    return hist

LBP特征

def LBP_features(self, im):
   im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)

    # settings for LBP
    radius = 3
    n_points = 8 * radius

    lbp_img = local_binary_pattern(im, n_points, radius)
    lbp = self.img2cols(lbp_img)

    # cv2.imshow("", lbp)
    # cv2.waitKey(0)

    return lbp
  • 1
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
以下是Python OpenCV中的特征提取代码示例: 使用SIFT算法提取特征: ```python import cv2 # 读取图片 img = cv2.imread('image.jpg') # 创建SIFT对象 sift = cv2.xfeatures2d.SIFT_create() # 检测关键点和计算描述符 keypoints, descriptors = sift.detectAndCompute(img, None) # 绘制关键点 img_with_keypoints = cv2.drawKeypoints(img, keypoints, None) # 显示结果 cv2.imshow('Image with Keypoints', img_with_keypoints) cv2.waitKey(0) cv2.destroyAllWindows() ``` 使用SURF算法提取特征: ```python import cv2 # 读取图片 img = cv2.imread('image.jpg') # 创建SURF对象 surf = cv2.xfeatures2d.SURF_create() # 检测关键点和计算描述符 keypoints, descriptors = surf.detectAndCompute(img, None) # 绘制关键点 img_with_keypoints = cv2.drawKeypoints(img, keypoints, None) # 显示结果 cv2.imshow('Image with Keypoints', img_with_keypoints) cv2.waitKey(0) cv2.destroyAllWindows() ``` 使用ORB算法提取特征: ```python import cv2 # 读取图片 img = cv2.imread('image.jpg') # 创建ORB对象 orb = cv2.ORB_create() # 检测关键点和计算描述符 keypoints, descriptors = orb.detectAndCompute(img, None) # 绘制关键点 img_with_keypoints = cv2.drawKeypoints(img, keypoints, None) # 显示结果 cv2.imshow('Image with Keypoints', img_with_keypoints) cv2.waitKey(0) cv2.destroyAllWindows() ``` 使用FAST算法提取关键点: ```python import cv2 # 读取图片 img = cv2.imread('image.jpg') # 创建FAST对象 fast = cv2.FastFeatureDetector_create() # 检测关键点 keypoints = fast.detect(img, None) # 绘制关键点 img_with_keypoints = cv2.drawKeypoints(img, keypoints, None) # 显示结果 cv2.imshow('Image with Keypoints', img_with_keypoints) cv2.waitKey(0) cv2.destroyAllWindows() ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值