成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

用 OpenCV 實(shí)現(xiàn) FAST 算法目標(biāo)跟蹤

開發(fā) 人工智能
FAST算法非常適合實(shí)時(shí)計(jì)算機(jī)視覺任務(wù)。在本文中,我將解釋FAST算法的工作原理,它的優(yōu)點(diǎn)和缺點(diǎn),并最終創(chuàng)建一個(gè)使用FAST算法的對(duì)象跟蹤器。

主要工作

提取特征(角點(diǎn))并使用FAST算法跟蹤對(duì)象:OpenCV,Python

OpenCV中有多種特征提取算法可供使用,但其中一種名為FAST算法的,對(duì)于實(shí)時(shí)計(jì)算機(jī)視覺應(yīng)用來(lái)說非常有用。大多數(shù)特征提取和角點(diǎn)檢測(cè)方法在提取特征方面表現(xiàn)良好,但它們大多數(shù)并不適合實(shí)時(shí)應(yīng)用。

FAST算法非常適合實(shí)時(shí)計(jì)算機(jī)視覺任務(wù)。在本文中,我將解釋FAST算法的工作原理,它的優(yōu)點(diǎn)和缺點(diǎn),并最終創(chuàng)建一個(gè)使用FAST算法的對(duì)象跟蹤器。

FAST算法的工作原理是什么?

FAST算法相對(duì)簡(jiǎn)單。

  • FAST算法選擇一個(gè)隨機(jī)像素,并在該像素周圍畫一個(gè)圓(半徑:3像素),其圓周為16像素。
  • 如果在16像素中有至少12個(gè)連續(xù)點(diǎn)的強(qiáng)度比中心像素亮或暗(加上閾值),那么這個(gè)中心像素就被視為興趣點(diǎn)(角點(diǎn))。
  • 為了加快這個(gè)過程,算法首先檢查圓周上的4個(gè)像素。至少有3個(gè)像素必須都比中心像素暗或亮,如果它們不是,該點(diǎn)就不能是興趣點(diǎn),因?yàn)檎缥抑八f,至少有12個(gè)連續(xù)像素必須更暗或更亮。

查看下面的圖片,它準(zhǔn)確地展示了我嘗試解釋的內(nèi)容。

FAST算法的優(yōu)點(diǎn)和缺點(diǎn)

優(yōu)點(diǎn):FAST算法非常快。如果你將它與其他特征提取和角點(diǎn)檢測(cè)算法進(jìn)行比較,你會(huì)看到差異。實(shí)際上,我在另一篇博客文章中比較了ORB、FAST和SIFT算法,結(jié)果顯示FAST算法比其他算法快(博客文章鏈接)

缺點(diǎn):FAST算法對(duì)噪聲敏感,因此在噪聲圖像中可能會(huì)檢測(cè)到錯(cuò)誤的角點(diǎn)。它不是尺度不變性的,這意味著如果圖像的大小改變,它可能不會(huì)很好地工作。

結(jié)論

選擇FAST算法為你的任務(wù)完全取決于你的目的。如果你需要更高的幀率,并且不太關(guān)心提取點(diǎn)的準(zhǔn)確性,你可以考慮使用FAST算法。

代碼/使用FAST算法跟蹤對(duì)象

有兩個(gè)主要步驟:

  • 首先,用戶通過使用鼠標(biāo)左鍵在目標(biāo)對(duì)象周圍畫矩形來(lái)定義目標(biāo)對(duì)象。然后使用FAST算法從這個(gè)目標(biāo)對(duì)象(而不是整幅圖像)中提取特征。
  • 接下來(lái),對(duì)于每一幀,使用FAST算法提取特征。將目標(biāo)圖像的特征與每一幀中的特征進(jìn)行比較。如果有匹配,就在特征位置畫一個(gè)圓圈,通過這樣做來(lái)跟蹤對(duì)象。

(1) 導(dǎo)入庫(kù):


import cv2
import numpy as np 
import matplotlib.pyplot as plt
import time

(2) 使用鼠標(biāo)通過在其周圍畫矩形來(lái)選擇目標(biāo)對(duì)象:


# Path to video  
video_path=r"videos/fish-video.mp4"
video = cv2.VideoCapture(video_path)

# read only the first frame for drawing a rectangle for the desired object
ret,frame = video.read()

# I am giving  big random numbers for x_min and y_min because if you initialize them as zeros whatever coordinate you go minimum will be zero 
x_min,y_min,x_max,y_max=36000,36000,0,0


def coordinat_chooser(event,x,y,flags,param):
    global go , x_min , y_min, x_max , y_max

    # when you click the right button, it will provide coordinates for variables
    if event==cv2.EVENT_RBUTTONDOWN:
        
        # if current coordinate of x lower than the x_min it will be new x_min , same rules apply for y_min 
        x_min=min(x,x_min) 
        y_min=min(y,y_min)

         # if current coordinate of x higher than the x_max it will be new x_max , same rules apply for y_max
        x_max=max(x,x_max)
        y_max=max(y,y_max)

        # draw rectangle
        cv2.rectangle(frame,(x_min,y_min),(x_max,y_max),(0,255,0),1)


    """
        if you didn't like your rectangle (maybe if you made some misscliks),  reset the coordinates with the middle button of your mouse
        if you press the middle button of your mouse coordinates will reset and you can give a new 2-point pair for your rectangle
    """
    if event==cv2.EVENT_MBUTTONDOWN:
        print("reset coordinate  data")
        x_min,y_min,x_max,y_max=36000,36000,0,0

cv2.namedWindow('coordinate_screen')
# Set mouse handler for the specified window, in this case, "coordinate_screen" window
cv2.setMouseCallback('coordinate_screen',coordinat_chooser)


while True:
    cv2.imshow("coordinate_screen",frame) # show only first frame 
    
    k = cv2.waitKey(5) & 0xFF # after drawing rectangle press ESC   
    if k == 27:
        cv2.destroyAllWindows()
        break

(3) 從目標(biāo)對(duì)象中提取特征(不是從整幅圖像中):


# take region of interest ( take inside of rectangle )
roi_image=frame[y_min:y_max,x_min:x_max]

# convert roi to grayscale, SIFT Algorithm works with grayscale images
roi_gray=cv2.cvtColor(roi_image,cv2.COLOR_BGR2GRAY) 

# Initialize the FAST detector and BRIEF descriptor extractor
fast = cv2.FastFeatureDetector_create(threshold=20)
brief = cv2.xfeatures2d.BriefDescriptorExtractor_create()

# detect keypoints
keypoints_1 = fast.detect(roi_gray, None)
# descriptors
keypoints_1, descriptors_1 = brief.compute(roi_gray, keypoints_1)

# draw keypoints for visualizing
keypoints_image = cv2.drawKeypoints(roi_image, keypoints_1, outImage=None, color=(0, 255, 0))
# display keypoints
plt.imshow(keypoints_image,cmap="gray")

(4) 使用FAST算法跟蹤對(duì)象


# matcher object
bf = cv2.BFMatcher()

# Variables for FPS calculation
frame_count = 0
start_time = time.time()
     
while True :
    # reading video 
    ret,frame=video.read()

    if ret:
          # convert frame to gray scale 
        frame_gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    
        
        # Detect keypoints using FAST
        keypoints_2 = fast.detect(frame_gray, None)

        # Compute descriptors using BRIEF
        keypoints_2, descriptors_2 = brief.compute(frame_gray, keypoints_2)
        
        """
        Compare the keypoints/descriptors extracted from the 
        first frame(from target object) with those extracted from the current frame.
        """
        if descriptors_2 is  not None:
            matches =bf.match(descriptors_1, descriptors_2)
    
    
            for match in matches:
            
                # queryIdx gives keypoint index from target image
                query_idx = match.queryIdx
                
                # .trainIdx gives keypoint index from current frame 
                train_idx = match.trainIdx
                
                # take coordinates that matches
                pt1 = keypoints_1[query_idx].pt
                
                # current frame keypoints coordinates
                pt2 = keypoints_2[train_idx].pt
                
                # draw circle to pt2 coordinates , because pt2 gives current frame coordinates
                cv2.circle(frame,(int(pt2[0]),int(pt2[1])),5,(255,0,0),-1)
    
        # Calculate and display FPS
        frame_count += 1
        elapsed_time = time.time() - start_time
        fps = frame_count / elapsed_time
        cv2.putText(frame, f"FPS: {fps:.2f}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 3)
        
    
        cv2.imshow("coordinate_screen",frame) 
    
    
        k = cv2.waitKey(5) & 0xFF # after drawing rectangle press esc   
        if k == 27:
            cv2.destroyAllWindows()
            break
    else:
        break

video.release()
cv2.destroyAllWindows()

責(zé)任編輯:趙寧寧 來(lái)源: 小白玩轉(zhuǎn)Python
相關(guān)推薦

2024-10-28 17:17:32

2010-08-05 08:49:19

2011-10-11 09:15:58

移動(dòng)應(yīng)用PhoneGapGoodDay

2025-02-17 07:00:00

ORB對(duì)象跟蹤器計(jì)算機(jī)視覺

2023-09-25 10:13:59

Java識(shí)別

2019-05-22 14:28:08

AI人工智能深度學(xué)習(xí)

2025-03-25 08:30:00

OpenCV計(jì)算機(jī)視覺圖像識(shí)別

2024-06-21 10:40:00

計(jì)算機(jī)視覺

2017-09-22 11:45:10

深度學(xué)習(xí)OpenCVPython

2023-01-11 08:59:33

Linuxtraceroute命令

2019-05-14 09:53:31

代碼開發(fā)工具

2019-02-18 09:00:00

TextRank算法自然語(yǔ)言處理Python

2021-10-20 11:47:26

威脅情報(bào)網(wǎng)絡(luò)威脅網(wǎng)絡(luò)安全

2020-07-25 19:40:33

Java開發(fā)代碼

2024-11-12 10:20:00

模型數(shù)據(jù)

2024-09-12 17:19:43

YOLO目標(biāo)檢測(cè)深度學(xué)習(xí)

2023-10-12 09:21:41

Java圖像

2024-09-24 17:12:47

2024-07-18 10:37:34

2024-04-25 11:45:09

在線地圖SOTA
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 亚洲性网 | 97超碰站| 天天爽夜夜操 | 日本一区不卡 | 亚洲一区二区在线视频 | 一区二区三区在线免费看 | 污污的网站在线观看 | 黄色精品 | 国产精品美女一区二区 | 国产成人99久久亚洲综合精品 | 91天堂网| 正在播放国产精品 | 欧美激情综合网 | 国产日韩欧美精品一区二区三区 | 亚洲视频在线看 | 人人性人人性碰国产 | 成人一区二区三区在线观看 | 国产一区二区三区在线看 | 欧美在线观看网站 | 美国一级黄色片 | 亚洲一级毛片 | 黄视频免费在线 | 日韩一级欧美一级 | 欧美中国少妇xxx性高请视频 | 亚洲va欧美va天堂v国产综合 | 玖玖视频网 | 久久一 | 午夜在线影院 | 一区二区视频在线 | 久久精品国产亚洲一区二区三区 | 色吧久久| 岛国av一区二区 | 欧美午夜精品久久久久免费视 | 亚洲精品中文在线观看 | 亚洲欧美视频一区 | www.啪啪.com| 色综合99 | 国产精品美女久久久久aⅴ国产馆 | 福利视频一区二区三区 | 秋霞在线一区 | 这里只有精品999 |