9.7 Star检测器

# -*- coding:utf8 -*-
import cv2
import numpy as np

#加载图像
input_file = 'image/2.jpg'
img = cv2.imread(input_file)

#将图像转化为灰度图像
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# 显示图像
cv2.imshow('img',img)
cv2.imshow('img_gray',img_gray)

#定义一个类处理star特征检测相关的函数
class StarFeatureDetector(object):
    def __init__(self):
        self.detector = cv2.xfeatures2d.StarDetector_create()
    def detect(self, img):
        return self.detector.detect(img)

keypoints = StarFeatureDetector().detect(img)

cv2.drawKeypoints(img,keypoints,img,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

cv2.imshow('Star detect',img)
cv2.waitKey()

原图

原图

灰度图

灰度图

Start detect

Start detect

你可能感兴趣的:(9.7 Star检测器)