美文网首页
ORB feature tracking 特征跟踪

ORB feature tracking 特征跟踪

作者: 缪斯muse | 来源:发表于2020-07-08 12:38 被阅读0次

    输入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 特征跟踪

          本文链接:https://www.haomeiwen.com/subject/ojlqcktx.html