2016年3月16日 星期三

OpenCV3: AKAZE


一直對 Computer Vision 懷有興趣,每隔一段時間都有機會接觸到要使用影像分析的項目。當年開發的投影打雀遊戲、商標辨認、Weather Kids 的白紙偵測...等。這些都是自行研發的技術,沒有使用第三方的程序庫。最近想以 Raspberry Pi 開發一個影像分析項目,不想再自行開發,改而使用著名的 OpenCV。於是先在 Mac 上體驗及使用一下。好不容易才安裝好 OpenCV,立即試試效果:
##------------------------------------------------------------------------------
##  Detect keypoints and extract AKAZE features with OpenCV 3.1
##------------------------------------------------------------------------------
##  Language: Python 2.7
##  Platform: Mac OS X
##  Written by Pacess HO
##  Copyright 2016 Pacess Studio.  All rights reserved
##------------------------------------------------------------------------------

##  Import packages
from __future__ import print_function
import cv2

##  Load image
image = cv2.imread("sita_01.jpg")

##  Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

##  Display original image in a window
cv2.imshow("Original", image)

##  Initialize the AKAZE descriptor, then detect keypoints and extract local invariant descriptors from the image
detector = cv2.AKAZE_create()
(kps, descs) = detector.detectAndCompute(gray, None)
print("keypoints: {}, descriptors: {}".format(len(kps), descs.shape))

##  Draw the keypoints and show the output image in another window
cv2.drawKeypoints(image, kps, image, (0, 255, 0))
cv2.imshow("Output", image)

##  Wait any key pressed
cv2.waitKey(0)
cv2.destroyAllWindows()

沒有留言: