平面物體檢測

2021-06-21 05:07:27 字數 2109 閱讀 5962

這個教程的目標是學習如何使用 features2d 和 calib3d 模組來檢測場景中的已知平面物體。

測試資料: 資料影象檔案,比如 「box.png」或者「box_in_scene.png」等。

建立新的控制台(console)專案。讀入兩個輸入影象。

mat

img1

=imread

(argv[1

],cv_load_image_grayscale

);mat

img2

=imread

(argv[2

],cv_load_image_grayscale

);

檢測兩個影象的關鍵點(尺度旋轉都不發生變化的關鍵點)。

// 對第一幅影象進行關鍵點檢測

fastfeaturedetector

detector(15

);vector

<

keypoint

>

keypoints1

;detector

.detect

(img1

,keypoints1

);...

// 對第二幅影象進行關鍵點檢測

計算每個關鍵點的描述向量(descriptor)。

// 計算描述向量

surfdescriptorextractor

extractor

;mat

descriptors1

;extractor

.compute

(img1

,keypoints1

,descriptors1

);...

// 計算第二幅影象中的關鍵點對應的描述向量

計算兩幅影象中的關鍵點對應的描述向量距離,尋找兩影象中距離最近的描述向量對應的關鍵點,即為兩影象中匹配上的關鍵點:

// 關鍵點描述向量匹配

bruteforcematcher

<

l2<

float

>

>

matcher

;vector

<

dmatch

>

matches

;matcher

.match

(descriptors1

,descriptors2

,matches

);

視覺化結果:

// 繪製出結果

namedwindow

("matches",1

);mat

img_matches

;drawmatches

(img1

,keypoints1

,img2

,keypoints2

,matches

,img_matches

);imshow

("matches"

,img_matches

);waitkey(0

);

尋找兩個點集合中的單對映變換(homography transformation):

vector

<

point2f

>

points1

,points2

;// 用點填充形成矩陣(array)

....

math

=findhomography

(mat

(points1

),mat

(points2

),cv_ransac

,ransacreprojthreshold

);

建立內匹配點集合同時繪製出匹配上的點。用perspectivetransform函式來通過單對映來對映點:

mat points1projected; perspectivetransform(mat(points1), points1projected, h);

用 drawmatches

來繪製內匹配點.

平面物體檢測的主要演算法流程

主要用於使用 features2d 和 calib3d 模組來檢測場景中的已知平面物體。步驟 1 讀入兩幅影象 mat img1 imread argv 1 cv load image grayscale mat img2 imread argv 2 cv load image grayscale ...

DPM物體檢測相關

deformable parts model dpm 簡介 dpm deformable part model 模型結構初解 關於dpmv5 deformable part model 演算法中model結構的解釋 把訓練出來的模型檔案.mat格式轉為.txt格式的 hog 用於人體檢測的梯度方向直...

物體檢測網路概述

yolo 實時快速目標檢測 yolo詳解 傳統目標檢測系統採用deformable parts models dpm 方法,通過滑動框方法提出目標區域,然後採用分類器來實現識別。近期的r cnn類方法採用region proposal methods,首先生成潛在的bounding boxes,然後...