ORB feature tracking 特征跟踪

输入100张连续帧图像,提取并标记ORB 特征,保存视频。

import cv2
import numpy as np
import os
from os.path import isfile, join
import time

# input and output address
pathIn= './HighFrameRateTest2Sample100/Images/'
pathOut = 'tracking_gray.avi'

# preset output fps
fps = 5

# allocate list of images with ORB features
frame_array = []

files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
#for sorting the file names properly
# files.sort(key = lambda x: x[5:-4])
files.sort()

for i in range(len(files)):
    if files[i] != '.DS_Store':
        filename=pathIn + files[i]
        #reading each files
        start = time.time()
        img = cv2.imread(filename, 0)
        height, width= img.shape
        size = (width,height)

        # Initiate STAR detector
        orb = cv2.ORB_create()
        # compute keypoints and descriptors with ORB
        kp, des = orb.detectAndCompute(img, None)
        # draw keypoints
        kpimg = cv2.drawKeypoints(img,kp,img,color=(0,255,0), flags=0)
        end = time.time()
        frame_array.append(kpimg)

    print('processing the ' + str(i) + ' image, processing time: ' + str(end - start))

out = cv2.VideoWriter(pathOut,cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
for i in range(len(frame_array)):
    # writing to a image array
    out.write(frame_array[i])
out.release()

你可能感兴趣的:(ORB feature tracking 特征跟踪)