2017年2月27日 星期一

FAST (Features from Accelerated Segment Test)

上一張經典的圖



















這張圖表示FAST取角點的方法
底下是python的範例

#!/usr/bin/env python3.4
import numpy as np
import cv2
from matplotlib import pyplot as plt

def main():
        """ Main behaviour """
        print("test")
        image = cv2.imread("lena.png")
        gray=cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        fast = cv2.FastFeatureDetector_create()
        keypoints = fast.detect(gray,None)
        image2 = cv2.drawKeypoints(gray, keypoints, image, color=(255,0,0))
        cv2.imshow("Image",image2)
        #取出keypoint的x,y用numpy版本
        np_pts = np.asarray([kp.pt for kp in keypoints])
        print(np_pts[0])
       #keypoint轉成List格式 
        index = []
        for point in keypoints:
          temp = (point.pt, point.size, point.angle, point.response, point.octave, point.class_id)
          index.append(temp)
        print(index[0])
        #---------------List轉keypoint----------------------------------
        #kps = []
        #for point in index:
        #  temp = cv2.KeyPoint(x=point[0][0],y=point[0][1],_size=point[1], _angle=point[2], _response=point[3], _octave=point[4], _class_id=point[5])
        #  kps.append(temp)
        #image3 = cv2.drawKeypoints(gray, kps, image, color=(0,0,255))
        #-------------------------------------------------
        #cv2.imwrite('fast_false.png',image2)
        cv2.waitKey(0)

if __name__ == "__main__":

        main()

沒有留言:

張貼留言