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
-
G
r
a
y
=
0.299
R
+
0.587
G
+
0.114
B
Gray=0.299R+0.587G+0.114B
Gray=0.299R+0.587G+0.114B.
»Ò¶ÈÖ±·½Í¼
»Ò¶ÈÖ±·½Í¼ÊǻҶȼ¶µÄº¯Êý,ÃèÊöͼÏñÖиûҶȼ¶µÄÏñËظöÊý(»ò¸Ã»Ò¶È¼¶ÏñËسöÏÖµÄƵÂÊ):Æäºá×ø±êÊǻҶȼ¶,×Ý×ø±ê±íʾͼÏñÖиûҶȼ¶³öÏֵĸöÊý(ƵÂÊ)¡£
һάֱ·½Í¼µÄ½á¹¹±íʾΪ:
N
(
P
)
=
[
n
1
,
n
2
,
¡
,
n
L
?
1
]
N
=
¡Æ
i
=
0
L
?
1
n
i
,
p
i
=
n
i
N
N(P)=[n_1,n_2,\dots,n_{L-1}] \\ N=\sum_{i=0}^{L-1}n_i,p_i=\frac{n_i}{N}
N(P)=[n1?,n2?,¡,nL?1?]N=i=0¡ÆL?1?ni?,pi?=Nni?? ÆäÖÐ,LΪ»Ò¶È¼¶µÄ¸öÊý,
n
i
n_i
ni?Ϊÿ¸ö»Ò¶ÈµÄÏñËظöÊý,ÆäƵÂÊΪ
p
i
p_i
pi?¡£
Ö±·½Í¼¾ùºâ»¯
Ö±·½Í¼¾ùºâ»¯Ö÷Òª´¦ÀíÆعⲻ¹»»òÆعâ¹ý¶ÈµÄͼÏñ,ÓÃÓÚÌá¸ßͼƬµÄ¶Ô±È¶È¡£
Ëã·¨²½Öè:
-
½¨Á¢Í¼Ïñ»Ò¶ÈÖ±·½Í¼¡£ -
¼ÆËãÀÛ»ý·Ö²¼º¯Êý
P
(
k
)
P(k)
P(k):
P
(
k
)
=
¡Æ
i
=
0
k
p
i
P(k)=\sum_{i=0}^k p_i
P(k)=i=0¡Æk?pi? -
Éú³ÉеĻҶȺ;ɵĻҶȵĶÔÓ¦¹ØϵÊý×é:
T
(
i
)
=
P
(
i
)
?
L
T(i)=P(i)*L
T(i)=P(i)?L ÆäÖÐ
T
(
i
)
T(i)
T(i)±íʾлҶÈÖµ¡£ -
ÓÃеĻҶÈÖµ´úÌæ¾ÉµÄ»Ò¶ÈÖµ¡£
ͼÏñ¼¸ºÎ±ä»»
-
ƽÒÆ ×ÔÓɶÈΪ2.
x
¡ä
=
[
I
t
]
x
o
r
x
¡ä
=
[
I
t
0
T
1
]
x
\bold{x}'= \begin{bmatrix}\bold{I} & \bold{t} \end{bmatrix} \bold{x} \quad or \quad \bold{x}'= \begin{bmatrix}\bold{I} & \bold{t} \\ \bold{0}^T & 1\end{bmatrix} \bold{x}
x¡ä=[I?t?]xorx¡ä=[I0T?t1?]x -
¸ÕÌåÔ˶¯(Ðýת+ƽÒÆ) ×ÔÓɶÈΪ3¡£
x
¡ä
=
[
R
t
]
x
\bold{x}'= \begin{bmatrix}\bold{R} & \bold{t} \end{bmatrix} \bold{x}
x¡ä=[R?t?]x ÆäÖÐ
R
=
[
cos
?
¦È
?
sin
?
¦È
sin
?
¦È
cos
?
¦È
]
\bold{R}=\begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}
R=[cos¦Èsin¦È??sin¦Ècos¦È?] -
ÏàËƱ任(Ëõ·ÅÐýת+ƽÒÆ) ×ÔÓɶÈΪ4.
x
¡ä
=
[
s
R
t
]
x
=
[
a
?
b
t
x
b
a
t
y
]
x
\bold{x}'= \begin{bmatrix}s\bold{R} & \bold{t} \end{bmatrix} \bold{x}= \begin{bmatrix}a & -b & t_x \\ b & a & t_y \end{bmatrix} \bold{x}
x¡ä=[sR?t?]x=[ab??ba?tx?ty??]x -
·ÂÉä±ä»» ×ÔÓɶÈΪ6,·ÂÉä±ä»»ºóµÄƽÐÐÏßÈÔÈ»±£³ÖƽÐС£
x
¡ä
=
A
x
=
[
a
00
a
01
a
02
a
10
a
11
a
12
]
x
\bold{x}'= \bold{A} \bold{x}= \begin{bmatrix}a_{00} & a_{01} & a_{02} \\ a_{10} & a_{11} & a_{12} \end{bmatrix} \bold{x}
x¡ä=Ax=[a00?a10??a01?a11??a02?a12??]x // ¸ù¾ÝPoint2f[] srcPtsºÍdstPts¼ÆËã·ÂÉä±ä»»¾ØÕó,warp_matΪ2x3µÄ¾ØÕó
Mat warp_mat = getAffineTransform(srcPts, dstPts);
// ½«Í¼Ïñ½øÐзÂÉä±ä»»
Mat warp_dst = Mat::zeros(src.rows, src.cols, src.type());
// ÊäÈëͼÏñ¡¢Êä³öͼÏñ¡¢·ÂÉä±ä»»¾ØÕó¡¢Êä³öͼÏñµÄ³ß´ç
warpAffine(src, warp_dst, warp_mat, warp_dst.size());
-
͸ÊÓ/µ¥Ó¦ÐԱ任 ×ÔÓɶÈΪ8.
x
3
¡Á
1
¡ä
=
H
3
¡Á
3
x
3
¡Á
1
\bold{x}'_{3\times1}= \bold{H}_{3\times3} \bold{x}_{3\times1}
x3¡Á1¡ä?=H3¡Á3?x3¡Á1? Æë´Î×ø±ê
x
3
¡Á
1
¡ä
\bold{x}'_{3\times1}
x3¡Á1¡ä?±ØÐë¾¹ý¹éÒ»»¯ÒԵõ½·ÇÆë´Î×ø±ê,¼´
x
¡ä
=
h
00
x
+
h
01
y
+
h
02
h
20
x
+
h
21
y
+
h
22
,
y
¡ä
=
h
10
x
+
h
11
y
+
h
12
h
20
x
+
h
21
y
+
h
22
x'=\frac{h_{00}x+h_{01}y+h_{02}}{h_{20}x+h_{21}y+h_{22}},\quad y'=\frac{h_{10}x+h_{11}y+h_{12}}{h_{20}x+h_{21}y+h_{22}}
x¡ä=h20?x+h21?y+h22?h00?x+h01?y+h02??,y¡ä=h20?x+h21?y+h22?h10?x+h11?y+h12?? µ¥Ó¦ÐԱ任±£ÁôÁËÖ±Ïß¡£
Ä£°åÆ¥Åä
Æ¥Åä·½·¨ÓÐƽ·½²îTM_SQDIFF¡¢¹éÒ»»¯Æ½·½²îTM_SQDIFF_NORMED¡¢Ïà¹ØÐÔTM_CCORR¡¢¹éÒ»»¯Ïà¹ØÐÔTM_CCORR_NORMED¡¢Ð·½²îTM_CCOEFF¡¢¹éÒ»»¯Ð·½²îTM_CCOEFF_NORMED¡£
// ÊäÈëͼÏñI¡¢Ä£°åT¡¢Æ¥Åä½á¹ûR¡¢Æ¥Åä·½·¨¡¢ÑÚÂëͼÏñM
matchTemplate(img, temp1, result, match_method=TM_SQDIFF, mask);
// ¶¨Î»½á¹ûRÖеÄ×î´óºÍ×îСֵ
double minVal; double maxVal; Point minLoc; Point maxLoc;
minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
// ¶ÔÓÚƽ·½²î·½·¨×î¼ÑÆ¥ÅäÊÇRµÄ×îСֵ,¶ÔÓÚÆäËû·½·¨×î¼ÑÆ¥ÅäÊÇRµÄ×î´óÖµ
Point matchLoc;
if (match_method == TM_SQDIFF || match_method == TM_SQDIFF_NORMED) {
matchLoc = minLoc;
} else {
matchLoc = maxLoc;
}
ͼÏñÂ˲¨ºÍ±ä»»
¸ßͨÂ˲¨
¸ßͨÂ˲¨Æ÷(HPF)ÊǼì²âͼÏñµÄij¸öÇøÓò,È»ºó¸ù¾ÝÏñËØÓëÖÜΧÏñËصÄÁÁ¶È²îÖµÀ´ÌáÉý¸ÃÏñËصÄÁÁ¶ÈµÄÂ˲¨Æ÷¡£Èç¹ûÁÁ¶È±ä»¯ºÜ´ó,ÖÐÑëÏñËصÄÁÁ¶È»áÔö¼Ó,·´Ö®Ôò²»»á¡£Ö÷ÒªÓÃÓÚ±ßÔµ¼ì²â¡£
kernel_3x3 = np.array([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]])
k3 = ndimage.convolve(img, kernel_3x3)
±ßÔµ¼ì²â
ÌݶÈËã×Ó
-
SobelËã×Ó
G
x
=
[
?
1
0
+
1
?
2
0
+
2
?
1
0
+
1
]
?
I
,
G
y
=
[
?
1
?
2
?
1
0
0
0
+
1
+
2
+
1
]
?
I
ÌÝ
¶È
Ïò
Á¿
µÄ
Ä£
G
=
G
x
2
+
G
y
2
ÌÝ
¶È
·½
Ïò
¦È
=
a
r
c
t
a
n
(
G
y
G
x
)
G_{x} = \begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \end{bmatrix} * I, G_{y} = \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ +1 & +2 & +1 \end{bmatrix} * I \\ ÌݶÈÏòÁ¿µÄÄ£G=\sqrt{G_x^2+G_y^2}\\ Ìݶȷ½Ïò\theta=arctan(\frac{G_y}{G_x})
Gx?=????1?2?1?000?+1+2+1?????I,Gy?=????10+1??20+2??10+1?????IÌݶÈÏòÁ¿µÄÄ£G=Gx2?+Gy2?
?Ìݶȷ½Ïò¦È=arctan(Gx?Gy??) Mat grad_x, grad_y;
int ddepth = CV_16S;
int ksize = 3;
double scale = 1;
double delta = 0;
// ÊäÈëͼÏñ¡¢Êä³öͼÏñ¡¢Êä³öͼÏñµÄÉî¶È¡¢x·½Ïòµ¼ÊýµÄ½×Êý¡¢y·½Ïòµ¼ÊýµÄ½×Êý¡¢ºË³ß´ç¡¢...
Sobel(src_gray, grad_x, ddepth, 1, 0, ksize, scale, delta, BORDER_DEFAULT); // x·½ÏòÌݶÈ
Sobel(src_gray, grad_y, ddepth, 0, 1, ksize, scale, delta, BORDER_DEFAULT); // y·½ÏòÌݶÈ
// ½«Êä³öת»»ÎªCV_8UͼÏñ
Mat abs_grad_x, abs_grad_y;
convertScaleAbs(grad_x, abs_grad_x);
convertScaleAbs(grad_y, abs_grad_y);
// ºÏ²¢ÌݶÈ:½«x¡¢y·½ÏòµÄÌݶȽøÐмÓȨ
Mat grad;
addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad);
imshow("sobel gradient", grad);
-
LaplaceËã×Ó ÀÆÕÀ˹Ëã×ÓÊÇÒ»ÖÖ¶þ½×΢·ÖËã×Ó,Òò´Ë,ËüÒ»°ãÓöþ½×΢·Ö·ûºÅ
?
2
f
?^2f
?2fÀ´±íʾ¡£Æä³£ÓõÄÏà¹ØºËÓÐ:
h
1
=
[
0
?
1
0
?
1
4
?
1
0
?
1
0
]
,
h
2
=
[
?
1
?
1
?
1
?
1
8
?
1
?
1
?
1
?
1
]
h_1=\left[\begin{array}{ccc} 0&-1&0\\ -1&4&-1 \\ 0&-1&0\end{array} \right],h_2=\left[\begin{array}{ccc} -1&-1&-1\\ -1&8&-1 \\ -1&-1&-1\end{array} \right]
h1?=???0?10??14?1?0?10????,h2?=????1?1?1??18?1??1?1?1???? Mat dst, abs_dst;
// ÊäÈë¡¢Êä³ö¡¢Êä³öͼÏñÉî¶È(ӦΪCV_16S·ÀÖ¹Òç³ö)¡¢ºË³ß´ç¡¢...
Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
// ½«Êä³öת»»ÎªCV_8U
convertScaleAbs(dst, abs_dst);
imshow("Laplace gradient", abs_dst);
Canny±ßÔµ
Canny±ßÔµ¼ì²âËã·¨·Ç³£¸´ÔÓ,µ«ÊÇÒ²ºÜÓÐȤ,ËüÓÐ5¸ö²½Öè,¼´Ê¹Óøß˹Â˲¨Æ÷¶ÔͼÏñ½øÐÐÈ¥Ôë,¼ÆËãÌݶÈ,ÔÚ±ßÔµÉÏʹÓ÷Ç×î´óÒÖÖÆ,ÔÚ¼ì²âµ½µÄ±ßÔµÉÏʹÓÃË«ãÐֵȥ³ý¼ÙÑôÐÔ,×îºó»¹»á·ÖÎöËùÓеıßÔµ¼°ÆäÖ®¼äµÄÁ¬½Ó,ÒÔ±£ÁôÕæÕýµÄ±ßÔµ²¢Ïû³ý²»Ã÷ÏԵıßÔµ¡£
Ëã·¨²½Öè
-
ʹÓøß˹Â˲¨È¥Ôë:
K
=
1
159
[
2
4
5
4
2
4
9
12
9
4
5
12
15
12
5
4
9
12
9
4
2
4
5
4
2
]
K = \dfrac{1}{159}\begin{bmatrix} 2 & 4 & 5 & 4 & 2 \\ 4 & 9 & 12 & 9 & 4 \\ 5 & 12 & 15 & 12 & 5 \\ 4 & 9 & 12 & 9 & 4 \\ 2 & 4 & 5 & 4 & 2 \end{bmatrix}
K=1591????????24542?491294?51215125?491294?24542???????? -
ʹÓÃSobelËã×Ó¼ÆËãÌݶÈ,Ìݶȷ½ÏòÀëÉ¢»¯Îª4¸ö·½Ïò¡£ -
·Ç×î´óÖµÒÖÖÆ,Ïû³ý±ßÎó¼ì¡£ -
Ë«ãÐÖµ:ÈôÏñËØÌݶȴóÓÚÉϽç,ÈÏΪ¸ÃÏñËØΪ±ßÔµ;ÈôÏñËØÌݶÈСÓÚϽç,ÔòÈ¥³ý;ÈôÏñËØÌݶÈλÓÚÖмä,Ôò½öµ±¸ÃÏñËغÍÒ»¸öÌݶȴóÓÚÉϽçµÄÏñËØÏàÁ¬Ê±,²ÅÈÏΪ¸ÃÏñËØΪ±ßÔµ¡£ÉÏϽç±Èͨ³£Îª2:1»ò3:1¡£
cv2.Cannyº¯Êý²¿·Ö²ÎÊýÈçÏÂ:
- µÚÒ»¸ö²ÎÊýÊÇÐèÒª´¦ÀíµÄÔͼÏñ,¸ÃͼÏñ±ØÐëÊǵ¥Í¨µÀµÄ»Ò¶Èͼ;
- µÚ¶þ¸ö²ÎÊýÊÇãÐÖµ1¡£
- µÚÈý¸ö²ÎÊýÊÇãÐÖµ2.
ÆäÖнϴóµÄãÐÖµ2ÓÃÓÚ¼ì²âͼÏñÖÐÃ÷ÏԵıßÔµ,µ«ÊÇÒ»°ãÇé¿öϼì²âµÄЧ¹û²»»áÄÇôÍêÃÀ,±ßÔµ¼ì²â³öÀ´ÊǶ϶ÏÐøÐøµÄ¡£ËùÒÔÕâʱºò½ÏСµÄµÚÒ»¸öãÐÖµÓÃÓÚ½«ÕâЩ¶ÏÐøµÄ±ßÔµÁ¬½ÓÆðÀ´¡£
Mat img_gray, canny_output;
// ÊäÈë¡¢Êä³ö(¶þÖµ»¯CannyͼÏñ)¡¢Ï½硢ÉϽ硢SobelËã×ӵĺ˳ߴç
Canny(img_gray, canny_output, lowThresh, highThresh, kernel_size);
ÂÖÀªÌáÈ¡
ÔÚÌáÈ¡ÁËCanny±ßÔµºó,¿ÉÒÔͨ¹ýfindContoursº¯Êý½øÒ»²½ÌáȡͼÏñµÄÂÖÀª,º¯ÊýÇ©ÃûÈçÏÂ:
/*
image: µ¥Í¨µÀÊäÈëͼÏñ,ͨ³£Óþ¹ýCanny¡¢LaplaceµÈ±ßÔµ¼ì²âËã×Ó´¦Àí¹ýµÄ¶þÖµ»¯Í¼Ïñ
contours: ÊÇÒ»¸ö¶þÖØÏòÁ¿,ÏòÁ¿µÄÿ¸öÔªËØ´ú±íÁËÒ»×éPointµã¼¯¹¹³ÉµÄÒ»¸öÂÖÀª
hierarchy: Ò²ÊÇÒ»¸öÏòÁ¿,ÆäÔªËغÍcontoursÄÚµÄÂÖÀªÒ»Ò»¶ÔÓ¦,ÆäÄÚ²¿µÄ4¸öintÖµ·Ö±ð±íʾÂÖÀªµÄºóÒ»¸öÂÖÀª¡¢Ç°Ò»¸öÂÖÀª¡¢¸¸ÂÖÀªºÍÄÚǶÂÖÀªµÄË÷Òý¡£
mode: ÂÖÀªµÄ¼ìË÷ģʽ,°üÀ¨:
CV_RETR_EXTERNAL Ö»¼ì²â×îÍâΧÂÖÀª
CV_RETR_LIST ¼ì²âËùÓÐÂÖÀª,µ«ÊǼì²âµÄÂÖÀª²»½¨Á¢µÈ¼¶¹Øϵ(ûÓи¸ºÍÄÚǶÂÖÀª),±Ë´Ë¶ÀÁ¢
CV_RETR_CCOMP ¼ì²âËùÓÐÂÖÀª,µ«ÊÇÂÖÀªÖ»½¨Á¢Á½¸öµÈ¼¶¹Øϵ,ÍâΧΪ¶¥²ã¡£
CV_RETR_TREE ¼ì²âËùÓÐÂÖÀª,½¨Á¢Ò»¸öµÈ¼¶Ê÷½á¹¹,Íâ²ãÂÖÀª°üº¬ÄÚ²ãÂÖÀª¡£
method: ÂÖÀª½üËÆ·½·¨,°üÀ¨:
CV_CHAIN_APPROX_NONE ±£´æÎïÌå±ß½çÉÏËùÓÐÁ¬ÐøµÄÂÖÀªµã
CV_CHAIN_APPROX_SIMPLW ½ö±£´æÂÖÀªµÄ¹ÕµãÐÅÏ¢
offset: ËùÓÐÂÖÀªÐÅÏ¢Ïà¶ÔÓÚÔͼ¶ÔÓ¦µãµÄÆ«ÒÆÁ¿,Ï൱ÓÚÔÚÂÖÀªµãÉϼÓÒ»¸öÆ«ÒÆ
*/
findContours(InputOutputArray image, vector<vector<Point>> contours, vector<Vec4i> hierarchy,
int mode, int method, Point offset=Point());
// ʵÀý³ÌÐò
Canny(img_gray, img_canny, 100, 250);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(img_canny, contours, hierarchy, RETR_TREE, CHAIN_APPORX_SIMPLE);
// »æÖÆÂÖÀª
Mat drawing = Mat::zeros(canny_output.size(), CV_8UC3);
for (size_t i = 0; i < contours.size(); i++) {
Scalar color = Scalar(rng.uniform(0, 256), rng.uniform(0, 256), rng.uniform(0, 256));
drawContours(drawing, contours, (int)i, color, 2, 8, hierarchy, 0);
}
µÍͨÂ˲¨
µÍͨÂ˲¨Æ÷(LPF)ÊÇÔÚÏñËØÓëÖÜΧÏñËصÄÁÁ¶È²îֵСÓÚÒ»¶¨ÌØÕ÷Öµ,ƽ»¬¸ÃÏñËصÄÁÁ¶È¡£ËüÖ÷ÒªÓÃÓÚÈ¥ÔëºÍÄ£ºý»¯,±ÈÈç˵,¸ß˹ģºýÊÇ×î³£ÓõÄÄ£ºýÂ˲¨Æ÷(ƽ»¬Â˲¨Æ÷)Ö®Ò»,ËüÊÇÏ÷Èõ¸ßƵÐźÅÇ¿¶ÈµÄµÍͨÂ˲¨Æ÷¡£
- ·½¿òÂ˲¨
g
=
f
?
h
,
h
=
¦Á
[
1
1
1
?
1
1
1
1
?
1
?
?
?
?
?
1
1
1
?
1
]
,
¦Á
=
{
1
S
U
M
(
h
)
,
normalize=true
1
,
normalize=false
g=f\otimes h,h=\alpha \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 \\ 1 & 1 & 1 & \cdots & 1 \\ \cdots & \cdots & \cdots & \cdots & \cdots \\ 1 & 1 & 1 & \cdots & 1 \end{bmatrix} ,\alpha = \begin{cases} \frac{1}{SUM(h)}, & \text{normalize=true} \\ 1, & \text{normalize=false} \\ \end{cases}
g=f?h,h=¦Á?????11?1?11?1?11?1??????11?1??????,¦Á={SUM(h)1?,1,?normalize=truenormalize=false? µ±normalize=trueʱ·½¿òÂ˲¨±äΪ¾ùÖµÂ˲¨¡£
// ÊäÈëͼÏñ¡¢Êä³öͼÏñ¡¢Â˲¨Æ÷³ß´ç¡¢anchorµãλÖÃ(ĬÈÏΪºËÖÐÐÄ)
blur(src, dst, Size(i, i), Point(-1, -1));
// ÊäÈë¡¢Êä³ö¡¢ºË³ß´ç
medianBlur(src, dst, i);
G
0
(
x
,
y
)
=
A
e
?
(
x
?
¦Ì
x
)
2
2
¦Ò
x
2
+
?
(
y
?
¦Ì
y
)
2
2
¦Ò
y
2
G_{0}(x, y) = A e^{ \dfrac{ -(x - \mu_{x})^{2} }{ 2\sigma^{2}_{x} } + \dfrac{ -(y - \mu_{y})^{2} }{ 2\sigma^{2}_{y} } }
G0?(x,y)=Ae2¦Òx2??(x?¦Ìx?)2?+2¦Òy2??(y?¦Ìy?)2?
×î³£ÓõÄ3x3¸ß˹Â˲¨Æ÷Ϊ:
[
0.0625
0.125
0.0625
0.125
0.25
0.125
0.0625
0.125
0.0625
]
\left[\begin{array}{ccc} 0.0625&0.125&0.0625\\ 0.125&0.25&0.125 \\ 0.0625&0.125&0.0625\end{array}\right]
???0.06250.1250.0625?0.1250.250.125?0.06250.1250.0625????
// ÊäÈë¡¢Êä³ö¡¢ºË³ß´ç¡¢X·½ÏòµÄ¸ß˹ºË±ê×¼²î¡¢Y·½ÏòµÄ±ê×¼²î
GaussianBlur(src, dst, Size(i, i), 0, 0);
-
ÅòÕÍ(×î´óÖµÂ˲¨)
g
(
i
,
j
)
=
m
a
x
k
,
l
f
(
i
,
j
)
g(i,j)=max_{k,l}f(i,j)
g(i,j)=maxk,l?f(i,j) // ¾ØÐνṹԪ¡¢½á¹¹Ôª³ß´ç¡¢anchorλÖÃ
Mat element = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
// ÊäÈë¡¢Êä³ö¡¢½á¹¹Ôª
dilate(src, dst, element);
-
¸¯Ê´(×îСֵÂ˲¨)
g
(
i
,
j
)
=
m
i
n
k
,
l
f
(
i
,
j
)
g(i,j)=min_{k,l}f(i,j)
g(i,j)=mink,l?f(i,j) // Ê®×ֽṹԪ¡¢½á¹¹Ôª³ß´ç¡¢anchorλÖÃ
Mat element = getStructuringElement(MORPH_CROSS, Size(3, 3), Point(-1, -1));
// ÊäÈë¡¢Êä³ö¡¢½á¹¹Ôª
erode(src, dst, element);
-
Ë«±ßÂ˲¨ ÓÃÓÚ±£±ßÈ¥Ôë,ÈçÃÀÑÕ¡£ÆäÊä³öÏñËØÒÀÀµÓÚÁÚÓòÏñËØÖµµÄ¼ÓȨ×éºÏ
g
(
i
,
j
)
=
¡Æ
k
,
l
f
(
k
,
l
)
w
(
i
,
j
,
k
,
l
)
¡Æ
k
,
l
w
(
i
,
j
,
k
,
l
)
g(i,j)=\frac{\sum_{k,l}f(k,l)w(i,j,k,l)}{\sum_{k,l}w(i,j,k,l)}
g(i,j)=¡Æk,l?w(i,j,k,l)¡Æk,l?f(k,l)w(i,j,k,l)? ÆäÖÐ,
w
(
i
,
j
,
k
,
l
)
=
d
(
i
,
j
,
k
,
l
)
?
r
(
i
,
j
,
k
,
l
)
=
exp
?
(
?
(
i
?
k
)
2
+
(
j
?
l
)
2
2
¦Ò
d
2
)
?
exp
?
(
?
¡Î
f
(
i
,
j
)
?
f
(
k
,
l
)
¡Î
2
2
¦Ò
r
2
)
w(i,j,k,l)=d(i,j,k,l)\cdot r(i,j,k,l)=\exp\left(-\frac{(i-k)^2+(j-l)^2}{2\sigma_d^2}\right)\cdot \exp\left(-\frac{\|f(i,j)-f(k,l)\|^2}{2\sigma_r^2}\right)
w(i,j,k,l)=d(i,j,k,l)?r(i,j,k,l)=exp(?2¦Òd2?(i?k)2+(j?l)2?)?exp(?2¦Òr2?¡Îf(i,j)?f(k,l)¡Î2?)
ÐÎ̬ѧ²Ù×÷
-
¿ª²Ù×÷ ÓÃÒÔÏû³ýСÎïÌå(Ôëµã)
o
p
e
n
(
s
r
c
)
=
d
i
l
a
t
e
(
e
r
o
d
e
(
s
r
c
)
)
open(src)=dilate(erode(src))
open(src)=dilate(erode(src)) -
±Õ²Ù×÷ ÓÃÓÚÏû³ýСµÄºÚ¶´
d
s
t
=
c
l
o
s
e
(
s
r
c
,
e
l
e
m
e
n
t
)
=
e
r
o
d
e
(
d
i
l
a
t
e
(
s
r
c
,
e
l
e
m
e
n
t
)
)
dst = close( src, element ) = erode( dilate( src, element ) )
dst=close(src,element)=erode(dilate(src,element)) -
ÐÎ̬ѧÌÝ¶È ¶Ô¶þֵͼÏñ½øÐÐÕâÒ»²Ù×÷¿ÉÒÔ½«ÍÅ¿é(blob)µÄ±ßԵͻ³ö³öÀ´¡£ÎÒÃÇ¿ÉÒÔÓÃÐÎ̬ѧÌݶÈÀ´±£ÁôÎïÌåµÄ±ßÔµÂÖÀª¡£
m
o
r
p
h
g
r
a
d
(
s
r
c
)
=
d
i
l
a
t
e
(
s
r
c
)
?
e
r
o
d
e
(
s
r
c
)
morphgrad(src)=dilate(src)-erode(src)
morphgrad(src)=dilate(src)?erode(src)
´úÂëʵÏÖ
// operationΪÐÎ̬ѧ²Ù×÷,°üÀ¨:
// ¿ª=MORPH_OPEN,±Õ=MORPH_CLOSE,ÌݶÈ=MORPH_GRADIENT
morphologyEx(src, dst, operation, element);
ͼÏñ½ð×ÖËþ
-
¸ß˹½ð×ÖËþ(ÓÃÓÚͼÏñϲÉÑù) ϲÉÑù:¸ß˹Â˲¨,È»ºóÒƳýͼÏñµÄżÊýÁкÍÐÐ(È¡1/4)¡£ ÉϲÉÑù:½«Í¼ÏñÔÚÿ¸ö·½ÏòÀ©´óΪÔÀ´µÄ2±¶,ÐÂÔöµÄÖµÒÔ0Ìî³ä;ʹÓÃÏÈǰͬÑùµÄºË(³ËÒÔ4)Óë·Å´óºóµÄͼÏñ¾í»ý,»ñµÃ¡°ÐÂÖµÏñËØ¡±µÄ½üËÆÖµ¡£ // ÊäÈë¡¢Êä³ö¡¢Êä³ö³ß´ç
pyrDown( src, src, Size( src.cols/2, src.rows/2 ) );
pyrUp(src, src, Size(src.cols*2, src.rows*2));
-
ÀÆÕÀ˹½ð×ÖËþ(ÓÃÓÚϲãͼÏñµÄÖؽ¨ÉϲÉÑù) ΪʹÉϲÉÑùºÍϲÉÑù¿ÉÄæ,ÀÆÕÀ˹½ð×ÖËþ¶¨ÒåΪ:
L
i
=
G
i
?
P
y
r
U
p
(
P
y
r
D
o
w
n
(
G
i
)
)
=
G
i
?
U
p
(
P
y
r
D
o
w
n
(
G
i
)
)
?
H
5
¡Á
5
L_i=G_i-PyrUp(PyrDown(G_i))=G_i-Up(PyrDown(G_i))\otimes H_{5\times 5}
Li?=Gi??PyrUp(PyrDown(Gi?))=Gi??Up(PyrDown(Gi?))?H5¡Á5? ÆäÖÐUp²Ù×÷Êǽ«Ô´Í¼ÏñÖÐλÖÃΪ(x,y)µÄÏñËØÓ³É䵽Ŀ±êͼÏñµÄ(2x+1,2y+1)λÖÃ,
H
5
¡Á
5
H_{5¡Á5}
H5¡Á5?±íʾ5x5µÄ¸ß˹ºË¡£
Mat src; // Ôͼ
Mat laplace_pyramid, temp; // ½ð×ÖËþͼÏñ¡¢ÔÝ´æÔͼ
pyrDown(src, src, Size(src.cols / 2, src.rows / 2));
pyrUp(src, src, Size(src.cols * 2, src.rows * 2));
laplace_pyr![ÇëÌí¼ÓͼƬÃèÊö](https://img-blog.csdnimg.cn/03511b9e32294adc9f4592d0d5c613be.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2JlcmV6ZQ==,size_16,color_FFFFFF,t_70)
amid = temp - src;
imshow("Laplace_pyramid", laplace_pyramid);
Hough񄯯
Hough±ä»»ÓÃÓÚ¼ì²âÖ±Ïß,ÔÚʹÓÃÇ°ÐèÒªÏȾ¹ý±ßÔµ¼ì²âµÄÔ¤´¦Àí¡£
¶ÔÓÚÒ»ÌõÖ±Ïß,¿ÉÒÔʹÓü«×ø±êÐÎʽÃèÊö:
y
=
(
?
cos
?
¦È
sin
?
¦È
)
x
+
(
r
sin
?
¦È
)
y = (-\frac{\cos \theta}{\sin \theta})x+(\frac{r}{\sin \theta})
y=(?sin¦Ècos¦È?)x+(sin¦Èr?)
-
¶ÔÓÚÿ¸öµã
(
x
0
,
y
0
)
(x_0,y_0)
(x0?,y0?),¿ÉÒÔ¶¨Òå´©¹ý¸ÃµãµÄÖ±Ïß´Ø:
r
¦È
=
x
0
cos
?
¦È
+
y
0
sin
?
¦È
r_{\theta}=x_0\cos\theta+y_0\sin\theta
r¦È?=x0?cos¦È+y0?sin¦È Ò»¶Ô
(
r
¦È
,
¦È
)
(r_{\theta},\theta)
(r¦È?,¦È)¾Í´ú±íÒ»Ìõ´©¹ý
(
x
0
,
y
0
)
(x_0,y_0)
(x0?,y0?)µÄÖ±Ïß¡£ -
¶ÔÓÚ¸ø¶¨µÄÒ»¸öµã
(
x
0
,
y
0
)
(x_0,y_0)
(x0?,y0?),¿ÉÒÔ»æÖÆ
(
r
,
¦È
)
(r,\theta)
(r,¦È)µÄÇúÏß,ÆäΪһÌõÕýÏÒÇúÏß:(Ö»¿¼ÂÇ
r
>
0
r>0
r>0ºÍ
0
<
¦È
<
2
¦Ð
0<\theta<2\pi
0<¦È<2¦Ð)
-
ÎÒÃǶÔͼÏñÖеÄËùÓе㶼»æÖÆÕâÑùµÄÇúÏß¡£Èç¹ûÁ½¸ö²»Í¬µãµÄÇúÏßÏཻÓÚÒ»µã
(
r
,
¦È
)
(r,\theta)
(r,¦È),Õâ±íÃ÷ÕâÁ½¸öµã¶¼ÔÚÕâÌõÖ±ÏßÉÏ¡£ -
ÓÉ´Ë,¿ÉÒÔ¶¨ÒåÒ»¸ö½»µããÐÖµÀ´¼ì²âÒ»ÌõÖ±Ïß,µ±½»µã¸öÊý³¬¹ý¸ÃãÐֵʱ,±íÃ÷¸Ã½»µã
(
r
,
¦È
)
(r,\theta)
(r,¦È)¿ÉÒÔÃèÊöÒ»ÌõÖ±Ïß¡£Õâ¾ÍÊÇHoughÏ߱任¡£
Mat src, img_canny, cdst, cdst_p;
Canny(src, img_canny, 50, 200, 3);
cvtColor(img_canny, cdst, COLOR_GRAY2BGR);
cdst_p = cdst.clone();
vector<Vec2f> lines;
HoughLines(img_canny, lines, 1, CV_PI/180, 150, 0, 0);
for (size_t i = 0; i < lines.size(); i++) {
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a * rho, y0 = b * rho;
pt1.x = cvRound(x0 + 1000 * (-b));
pt1.y = cvRound(y0 + 1000 * a);
pt2.x = cvRound(x0 + 1000 * b);
pt2.y = cvRound(y0 + 1000 * (-a));
line(cdst, pt1, pt2, Scalar(0, 0, 255), 3, LINE_AA);
}
vector<Vec4i> lines_p;
HoughLinesP(img_canny, lines_p, 1, CV_PI/180, 50, 50, 10);
for (size_t i = 0; i < lines_p.size(); i++) {
Vec4i l = lines_p[i];
line(cdst_p, Point(l[0], l[1]), Point(l[2],l[3]), Scalar(0, 0, 255), 3, LINE_AA);
}
imshow("Source", src);
imshow("Detected Lines (in red) - Standard", cdst);
imshow("Detected Lines (in red) - Probabilistic", cdst_p);
¾µäÊÖ¹¤ÌØÕ÷
Harris½Çµã
Harris½Çµã¾ßÓÐÐýת²»±äÐÔ,µ«²»¾ßÓг߶Ȳ»±äÐÔ¡£
»ù±¾Ë¼Ïë
ʹÓÃÒ»¸ö¹Ì¶¨´°¿ÚÔÚͼÏñÉϽøÐÐÈÎÒâ·½ÏòÉϵĻ¬¶¯,±È½Ï»¬¶¯Ç°ºó´°¿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
€
W
g
(
I
y
2
)
=
¡Æ
(
x
,
y
)
€
W
I
y
2
?
w
(
x
,
y
)
C
=
¡Æ
(
x
,
y
)
€
W
g
(
I
x
I
y
)
=
¡Æ
(
x
,
y
)
€
W
I
x
I
y
?
w
(
x
,
y
)
A=\sum\limits_{(x,y)€W}g(I_x^2)=\sum\limits_{(x,y)€W}I_x^2*w(x,y)\\ B=\sum\limits_{(x,y)€W}g(I_y^2)=\sum\limits_{(x,y)€W}I_y^2*w(x,y)\\ C=\sum\limits_{(x,y)€W}g(I_xI_y)=\sum\limits_{(x,y)€W}I_xI_y*w(x,y)\\
A=(x,y)€W¡Æ?g(Ix2?)=(x,y)€W¡Æ?Ix2??w(x,y)B=(x,y)€W¡Æ?g(Iy2?)=(x,y)€W¡Æ?Iy2??w(x,y)C=(x,y)€W¡Æ?g(Ix?Iy?)=(x,y)€W¡Æ?Ix?Iy??w(x,y) ÆäÖÐ
M
=
[
A
C
C
B
]
=
¡Æ
(
x
,
y
)
€
W
w
(
x
,
y
)
[
I
x
2
I
x
I
y
I
x
I
y
I
y
2
]
M=\begin{bmatrix} A & C \\C & B\end{bmatrix}=\sum\limits_{(x,y)€W}w(x,y)\begin{bmatrix} I_x^2 & I_xIy \\I_xI_y & I_y^2\end{bmatrix}
M=[AC?CB?]=(x,y)€W¡Æ?w(x,y)[Ix2?Ix?Iy??Ix?IyIy2??],
w
(
x
,
y
)
w(x,y)
w(x,y)±íʾ¸ß˹»¬¶¯´°¿Ú¡£ -
¼ÆËãÿ¸öÏñËصã
(
x
,
y
)
(x,y)
(x,y)´¦µÄHarrisÏìÓ¦Öµ
R
R
R:
R
=
d
e
t
(
M
)
?
k
(
t
r
a
c
e
(
M
)
)
2
d
e
t
(
M
)
=
¦Ë
1
¦Ë
2
t
r
a
c
e
(
M
)
=
¦Ë
1
+
¦Ë
2
R=det(M)-k(trace(M))^2 \\ det(M)=¦Ë_1¦Ë_2 \\ trace(M)=¦Ë_1+¦Ë_2
R=det(M)?k(trace(M))2det(M)=¦Ë1?¦Ë2?trace(M)=¦Ë1?+¦Ë2? ÕâÀï
¦Ë
1
,
¦Ë
2
¦Ë_1,¦Ë_2
¦Ë1?,¦Ë2?ÊǾØÕó
M
M
MµÄ2¸öÌØÕ÷Öµ,
k
k
kÊÇÒ»¸öÖ¸¶¨Öµ,ÕâÊÇÒ»¸ö¾Ñé²ÎÊý,ÐèҪʵÑéÈ·¶¨ËüµÄºÏÊÊ´óС,ͨ³£ËüµÄÖµÔÚ0.04ºÍ0.06Ö®¼ä,ËüµÄ´æÔÚÖ»Êǵ÷½Úº¯ÊýµÄÐÎ×´¶øÒÑ¡£
R
R
RÈ¡¾öÓÚ
M
M
MµÄÌØÕ÷Öµ,¶ÔÓڽǵã
¨O
R
¨O
|R|
¨OR¨OºÜ´ó,ƽ̹µÄÇøÓò
¨O
R
¨O
|R|
¨OR¨OºÜС,±ßÔµµÄ
R
R
RΪ¸ºÖµ¡£ -
Â˳ýСÓÚãÐÖµ
t
t
tµÄ
R
R
RÖµ:
R
=
{
R
:
d
e
t
(
M
)
?
k
(
t
r
a
c
e
(
M
)
)
2
>
t
}
R=\{R:det(M)-k(trace(M))^2 \gt t \}
R={R:det(M)?k(trace(M))2>t} Èç¹ûÔÚ3¡Á3»òÕß5¡Á5µÄÁÚÓò½øÐзÇ×î´óÖµÒÖÖÆ,Ôò¾Ö²¿×î´óÖµµã¼´ÎªÍ¼ÏñÖеĽǵ㡣
´úÂëʵÏÖ
Mat dst = Mat::zeros(src.size(), CV_32FC1);
int block_size = 2;
int aperture_size = 3;
double k = 0.04;
cornerHarris(src_gray, dst, block_size, aperture_size, k);
Mat dst_norm, dst_norm_scaled;
normalize(dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat());
converScaleAbs(dst_norm, dst_norm_scaled);
int thresh = 200;
for (int i = 0; i < dst_norm.rows; i++) {
for (int j = 0; j < dst_norm.cols; j++) {
if ((int) dst_norm.at<float>(i,j) > thresh) {
circle(dst_norm_scaled, Point(j, i), 5, Scalar(0), 2, 8, 0);
}
}
}
imshow("harris corner", dst_norm_scaled);
Shi-Tomasi½Çµã(GFFT)
Shi-Tomasi½Çµã¼ì²âÔÀíÓëHarris½Çµã¼ì²âÏàͬ,Ö»ÊÇÔÚ×îºóÅбðʽµÄÑ¡È¡Éϲ»Í¬,Shi-Tomasi½Çµã¼ì²âÑ¡È¡ÌØÕ÷ÖеÄ×îСµÄÄǸöÀ´Åб𡣼´½ÇµãÏìÓ¦±äΪ
R
=
min
?
(
¦Ë
1
,
¦Ë
2
)
R=\min(\lambda_1,\lambda_2)
R=min(¦Ë1?,¦Ë2?)
vector<Point2f> corners; // ½ÇµãÏòÁ¿,ÿ¸öÔªËØΪһ¸ö½Çµã
int max_corners = 23; // ¼ì²âµÄ½ÇµãÊýÄ¿×î´óÖµ,ÈôÓиü¶àµÄ½Çµã,Ôò·µ»ØÏìÓ¦Öµ´óµÄ
double quality_level = 0.01; // ¿É½ÓÊܵÄ×îСÏìÓ¦Öµ,ÈôÏìÓ¦×î´óֵΪ1500,quality_level=0.01,ÔòСÓÚ15µÄÏìÓ¦¶¼±»¾Ü¾ø
double min_distance = 10; // ½ÇµãÖ®¼äµÄ×îСŷʽ¾àÀë
int block_size = 3, gradient_size = 3; // ¼ÆËãM¾ØÕóµÄ´°¿Ú´óС¡¢ÌݶÈËã×ӵĺ˳ߴç
bool use_harris_detector = false; // ÊÇ·ñʹÓÃharris½Çµã¼ì²âÆ÷
double k = 0.04; // harris½Çµã¼ì²âµÄkÖµ
goodFeaturesToTrack(src_gray,
corners,
max_corners,
quality_level,
min_distance,
Mat(), // ROI mask
block_size,
gradient_size,
use_harris_detector,
k);
// »æÖƽǵã
for (size_t i = 0; i < corners.size(); i++) {
circle(src, corners[i], 3, Scalar(0,0,255), FILLED);
}
imshow("Image", src);
SIFTÌØÕ÷
SIFT¾ßÓÐÐýת¡¢³ß¶È¡¢ÁÁ¶È²»±äÐÔ¡£
»ù±¾Ë¼Ïë
³ß¶È²»±äÌØÕ÷±ä»»(Scale-Invariant Feature Transform),ʹÓÃDoG(²î·Ö¸ß˹)À´ÌáÈ¡ÌØÕ÷µã,DoGÊÇÓò»Í¬µÄ³ß¶È¿Õ¼äÒò×Ó(¸ß˹·Ö²¼µÄ±ê×¼²î
¦Ò
\sigma
¦Ò)¶ÔͼÏñ½øÐÐƽ»¬,È»ºó±È½Ïƽ»¬ºóͼÏñµÄÇø±ð,²î±ð´óµÄÏñËؾͿÉÄÜÊÇÌØÕ÷µã¡£¶ÔµÃµ½µÄËùÓÐÌØÕ÷µã,ÌÞ³ýһЩ²»ºÃµÄ,SIFTËã×Ó»á°ÑʣϵÄÿ¸öÌØÕ÷µãÓÃÒ»¸ö128άµÄÏòÁ¿½øÐÐÃèÊö¡£
Ëã·¨²½Öè
-
DoG³ß¶È¿Õ¼äµÄ¼«Öµ¼ì²â: Ê×Ïȹ¹ÔìDoG³ß¶È¿Õ¼ä,ÔÚSIFTÖÐʹÓò»Í¬²ÎÊýµÄ¸ß˹ģºýÀ´±íʾ²»Í¬µÄ³ß¶È¿Õ¼ä¡£¶ø¹¹Ôì³ß¶È¿Õ¼äÊÇΪÁ˼ì²âÔÚ²»Í¬³ß¶È϶¼´æÔÚµÄÌØÕ÷µã,ÌØÕ÷µãµÄ¼ì²âʹÓÃDoG(ÀûÓòî·Ö´úÌæ΢·Ö)À´½üËƼÆËãLoG(ͼÏñµÄ¶þ½×µ¼Êý)¡£ -
ɾ³ý²»Îȶ¨µÄ¼«Öµµã: Ö÷Ҫɾ³ýÁ½Àà:µÍ¶Ô±È¶ÈµÄ¼«ÖµµãºÍ²»Îȶ¨µÄ±ßÔµÏìÓ¦µã¡£ -
È·¶¨ÌØÕ÷µãµÄÖ÷·½Ïò: ÒÔÌØÕ÷µãµÄ×ø±êΪÖÐÐÄ¡¢ÒÔ
3
¡Á
1.5
¦Ò
3\times1.5\sigma
3¡Á1.5¦ÒΪ°ë¾¶µÄÁÚÓòÄÚ¼ÆËã¸÷¸öÏñËصãµÄÌݶȵķùÖµºÍ·ù½Ç,È»ºóʹÓÃÖ±·½Í¼¶ÔÌݶȵķø½Ç½øÐÐͳ¼Æ¡£Ö±·½Í¼µÄºáÖáΪÌݶȵķ½Ïò,×ÝÖáΪÌݶȷ½Ïò¶ÔÓ¦ÌݶȷùÖµµÄÀÛºÍ,Ö±·½Í¼ÖеÄ×î¸ß·åËù¶ÔÓ¦µÄ·½Ïò¼´ÎªÌØÕ÷µãµÄÖ÷·½Ïò¡£ -
Éú³ÉÌØÕ÷µãµÄÃèÊö×Ó Ê×ÏȽ«×ø±êÖáÐýתΪÌØÕ÷µãµÄ·½Ïò,ÒÔÌØÕ÷µãΪÖÐÐĵÄ
16
¡Á
16
16\times16
16¡Á16´°¿ÚµÄÏñËصÄÌݶȷùÖµºÍ·½Ïò,½«´°¿ÚÄÚµÄÏñËØ·Ö³É
4
¡Á
4
4\times4
4¡Á4µÄ¿é,ÿ¿éÊÇÆäÄÚ²¿16¸öÏñËصÄ8¸ö·½ÏòµÄÖ±·½Í¼Í³¼Æ,¶ÔÓÚÒ»¸öÌØÕ÷µã,¿ÉÐγÉ
4
¡Á
4
¡Á
8
=
128
4\times4\times8=128
4¡Á4¡Á8=128άµÄÌØÕ÷ÏòÁ¿¡£
´úÂëʵÏÖ
int numFeatures = 400; // ÌáÈ¡µÄÌØÕ÷µãÊýÄ¿
Ptr<SIFT> detector = SIFT::create(numFeatures);
// step 1 detect the keypoints
vector<KeyPoint> keypoints;
detector->detect(src_gray, keypoints);
// draw keypoints
Mat img_keypoints;
drawKeypoints(src, keypoints, img_keypoints);
// show detected keypoints
imshow("SIFT", img_keypoints);
waitKey(0);
// detect the keypoints and descriptors
vector<KeyPoint> kp1, kp2;
Mat desc1, desc2;
detector->detectAndCompute(img1, Mat(), kp1, desc1);
detector->detectAndCompute(img2, Mat(), kp2, desc2);
// match,ʹÓÃflann¼ÓËÙÆ¥Åä
vector<vector<DMatch>> nn_matches;
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::FLANNBASED);
matcher->knnMatch(desc1, desc2, nn_matches, 2);
// Ñ¡ÔñºÃµÄÆ¥Åä
const float match_ratio = 0.8f;
vector<DMatch> good_matches;
for (size_t i = 0; i < nn_matches.size(); i++) {
if (nn_matches[i][0].distance < match_ratio * nn_matches[i][1].distance) {
good_matches.push_back(nn_matches[i][0]);
}
}
ORBÌØÕ÷
»ù±¾ÔÀí
ORBËã·¨½«FASTÌØÕ÷µãµÄ¼ì²â·½·¨ºÍBRIEFÌØÕ÷ÃèÊö×Ó½áºÏÆðÀ´,²¢½øÐиĽøºÍÓÅ»¯¡£
Ëã·¨²½Öè
-
ÀûÓÃFAST¼ì²âÌØÕ÷µã,È»ºóÀûÓÃHarris½ÇµãµÄ¶ÈÁ¿·½·¨,´ÓFASTÌØÕ÷µãÖÐÌôÑ¡³ýHarris½ÇµãÏìÓ¦Öµ×î´óµÄN¸öÌØÕ÷µã¡£ÆäÖÐÏìÓ¦º¯ÊýΪ
R
=
d
e
t
(
M
)
?
k
(
t
r
a
c
e
(
M
)
)
2
R=det(M)-k(trace(M))^2
R=det(M)?k(trace(M))2 ORBÖÐÓÃNMSÀ´É¸Ñ¡¹Ø¼üµã,Ö»±£Áô·ÖÊý×î´óµÄÇ°n¸ö¹Ø¼üµã¡£ÓÉÓÚFAST¹Ø¼üµã²»¾ß±¸³ß¶È²»±äÐÔ,Òò´ËORB²ÉÓÃÁËͼÏñ½ð×ÖËþÀ´ÊµÏֳ߶Ȳ»±äÐÔ,ͨ¹ý¹¹½¨¸ß˹½ð×ÖËþ,È»ºóÔÚÿһ²ã½ð×ÖËþͼÏñÉϼì²â½Çµã¡£ -
ÀûÓûҶÈÖÊÐÄ·¨ÊµÏÖBRIEFÃèÊö×ÓµÄÐýת²»±äÐÔ¡£ »Ò¶ÈÖÊÐÄ·¨ÈÏΪ½ÇµãµÄ»Ò¶ÈºÍÖÊÐÄÖ®¼ä´æÔÚÒ»¸öÆ«ÒÆ,Õâ¸öÏòÁ¿¿ÉÒÔÓÃÓÚ±íʾ·½Ïò¡£¶ÔÓÚÈÎÒâÌØÕ÷µãp,pµÄÁìÓòÏñËصľض¨ÒåΪ:
m
i
j
=
¡Æ
x
=
?
r
r
¡Æ
y
=
?
r
r
x
i
y
j
I
(
x
,
y
)
m_{ij}=\sum\limits_{x=-r}^{r}\sum\limits_{y=-r}^{r}x^iy^jI(x,y)
mij?=x=?r¡Ær?y=?r¡Ær?xiyjI(x,y) ÆäÖÐ
I
(
x
,
y
)
I(x,y)
I(x,y)Ϊµã
(
x
,
y
)
(x,y)
(x,y)´¦µÄ»Ò¶ÈÖµ,
q
q
qΪÖÊÐÄ,
i
,
j
=
0
,
1
i,j=0,1
i,j=0,1¡£ÄÇôÎÒÃÇ¿ÉÒԵõ½Í¼ÏñµÄÖÊÐÄΪ:
C
=
(
m
10
m
00
,
m
01
m
00
)
C=(\frac{m_{10}}{m_{00}},\frac{m_{01}}{m_{00}})
C=(m00?m10??,m00?m01??) ÄÇôÌØÕ÷µãÓëÖÊÐĵļнǶ¨ÒåΪFASTÌØÕ÷µãµÄ·½Ïò:
¦È
=
a
r
c
t
a
n
(
m
01
,
m
10
)
\theta=arctan(m_{01},m_{10})
¦È=arctan(m01?,m10?) BRIEFÃèÊö×ÓÊÇͨ¹ý±È½ÏÖÐÐÄÏñËصãpµÄÈÎÒâÁÚÓòÄÚµÄ256¶ÔÏñËؼäµÄ²îÖµÀ´Éú³É¶þ½øÖÆÃèÊö×Ó,Æä½á¹ûÊÇÒ»¸ö³¤¶ÈΪ256µÄ¶þÖµÂë´®,ÓÉÌØÕ÷µãÁÚÓòÄÚµÄ256¸öµã¶Ô×é³É,Õâ
2
¡Á
256
2\times256
2¡Á256¸öµã
(
x
i
,
y
i
)
,
i
=
1
,
2
,
.
.
.
.
.
,
2
n
(x_i,y_i),i=1,2,.....,2n
(xi?,yi?),i=1,2,.....,2n×é³ÉÒ»¸ö¾ØÕó
S
S
S:
S
=
[
x
1
x
2
.
.
.
x
2
n
y
1
y
2
.
.
.
y
2
n
]
S=\begin{bmatrix} x_1 & x_2 & ... &x_{2n} \\ y_1 & y_2 & ... & y_{2n} \end{bmatrix}
S=[x1?y1??x2?y2??......?x2n?y2n??] ORBʹÓÃÁÚÓò·½Ïò
¦È
\theta
¦ÈºÍ¶ÔÓ¦µÄÐýת¾ØÕó
R
¦È
R_{\theta}
R¦È?,¹¹½¨
S
S
SµÄУÕý°æ±¾
S
¦È
S_{\theta}
S¦È?:
S
¦È
=
R
¦È
S
S_{\theta}=R_{\theta}S
S¦È?=R¦È?S ÆäÖÐ,
R
¦È
=
[
c
o
s
¦È
s
i
n
¦È
?
s
i
n
¦È
c
o
s
¦È
]
R_{\theta}=\begin{bmatrix} cos\theta & sin\theta \\ -sin\theta & cos\theta \end{bmatrix}
R¦È?=[cos¦È?sin¦È?sin¦Ècos¦È?]
¦È
\theta
¦È¾ÍÊÇÉÏÃæÇóµÃµÄFASTÌØÕ÷µãµÄ·½Ïò¡£ ¶ÔÓÚÈÎÒâÒ»¶ÔÏñËصã
x
i
,
y
i
x_i,y_i
xi?,yi?,Èô
x
i
<
y
i
x_i<y_i
xi?<yi?,Ôò¸ÃλÖõÄÃèÊö×ÓΪ1,·ñÔòΪ0¡£ -
rBRIEF½â¾öÃèÊö×ÓµÄÇø·ÖÐÔ¡£
´úÂëʵÏÖ
Ptr<ORB> detector = ORB::create();
vector<KeyPoint> keypoints1, keypoints2;
Mat descriptors1, descriptors2;
detector->detectAndCompute(img_gray1, Mat(), keypoints1, descriptors1);
detector->detectAndCompute(img_gray2, Mat(), keypoints2, descriptors2);
Ptr<DescriptorMatcher> matcher =
DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE_HAMMING);
vector<vector<DMatch>> knn_matches;
matcher->knnMatch(descriptors1, decriptors2, knn_matches, 2);
const float ratio_thresh = 0.7f;
vector<DMatch> good_matches;
for (size_t i = 0; i < knn_matches.size(); i++) {
if (knn_matches[i][0].distance < ratio_thresh * knn_matches[i][1].distance) {
good_matches.push_back(knn_matches[i][0]);
}
}
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, good_matches, img_matches,
Scalar::all(-1),
Scalar::all(-1),
vector<char>(),
DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
imshow("Good matches", img_matches);
waitKey(0);
¹âÁ÷Optical flow
¹âÁ÷ÊÇ¿Õ¼äÔ˶¯ÎïÌåÔÚ¹Û²ì³ÉÏñƽÃæÉϵÃÏñËØÔ˶¯µÄ˲ʱËÙ¶È,ÊÇÀûÓÃͼÏñÐòÁÐÖÐÏñËØÔÚʱ¼äÓòÉϵı仯ºÍÏàÁÚÖ¡Ö®¼äµÄÏà¹ØÐÔÀ´ÕÒµ½ÉÏÒ»Ö¡ºÍµ±Ç°Ö¡Ö®¼äµÄ¶ÔÓ¦¹Øϵ,´Ó¶ø¼ÆËã³öÏàÁÚÖ¡Ö®¼äµÄÔ˶¯ÐÅÏ¢µÄÒ»ÖÖ·½·¨¡£
¿ÉÒÔͨ¹ý²»Í¬Ä¿±êµÄ¹âÁ÷Ô˶¯ËÙ¶ÈÅжÏËüÃÇÀëÎÒÃǵľàÀ롣һЩ½ÏÔ¶µÄÄ¿±ê,ÈçÔÆ,Ô˶¯µÃºÜÂý;¶øһЩ½Ï½üµÄÄ¿±ê,ÈçÃÅ¡¢Ô˶¯µÃ½Ï¿ì¡£
¹âÁ÷Ô¼Êø·½³Ì
¹âÁ÷»ùÓÚÈçÏÂÁ½¸ö¼ÙÉè:
- Ôں̵ܶÄʱ¼äÄÚÄ¿±êµÄÏñËØÖµ²»»á±ä»¯;
- ÁÚ½üµÄÏñËؾßÓÐÏàËƵÄÔ˶¯¡£
Áî
I
(
x
,
y
,
t
)
I(x,y,t)
I(x,y,t)±íʾtʱ¿ÌµÄÏñËصã
(
x
,
y
)
(x,y)
(x,y)µÄ»Ò¶ÈÖµ,Ôò¸ù¾ÝÁÁ¶Èºã¶¨¼ÙÉè,ÎÒÃÇÓÐ:
I
(
x
,
y
,
t
)
=
I
(
x
+
¦¤
x
,
y
+
¦¤
y
,
t
+
¦¤
t
)
I(x,y,t) = I(x + \Delta x, y + \Delta y, t + \Delta t)
I(x,y,t)=I(x+¦¤x,y+¦¤y,t+¦¤t) ÎÒÃǶÔÉÏʽÓÒ²à½øÐÐÒ»½×TaylorÕ¹¿ª,¿ÉµÃ:
I
(
x
+
¦¤
x
,
y
+
¦¤
y
,
t
+
¦¤
t
)
¡Ö
I
(
x
,
y
,
t
)
+
?
I
?
x
¦¤
x
+
?
I
?
y
¦¤
y
+
?
I
?
t
¦¤
t
I(x + \Delta x, y + \Delta y, t + \Delta t) \approx I(x,y,t) + \frac{\partial I}{\partial x}\Delta x + \frac{\partial I}{\partial y}\Delta y + \frac{\partial I}{\partial t}\Delta t
I(x+¦¤x,y+¦¤y,t+¦¤t)¡ÖI(x,y,t)+?x?I?¦¤x+?y?I?¦¤y+?t?I?¦¤t ×îºóµÃµ½¹âÁ÷Ô¼Êø·½³Ì:
?
I
?
x
¦¤
x
+
?
I
?
y
¦¤
y
+
?
I
?
t
¦¤
t
=
0
\frac{\partial I}{\partial x}\Delta x + \frac{\partial I}{\partial y}\Delta y + \frac{\partial I}{\partial t}\Delta t = 0
?x?I?¦¤x+?y?I?¦¤y+?t?I?¦¤t=0 ÓÉÓÚÕâ¸ö·½³ÌÓÐÁ½¸öδ֪Êý
(
¦¤
x
,
¦¤
y
)
(\Delta x,\Delta y)
(¦¤x,¦¤y),ËùÒÔûÓÐΨһ½â¡£ÎªÁ˵õ½Î¨Ò»½â,¾Í±ØÐëÐÂÔöÔ¼Êø»ò¼ÙÉè,Òò´ËÒ²¾ÍÓÐÁ˲»Í¬µÄËã·¨¡£
Lucas-KanadeËã·¨
Lucas-KanadeËã·¨¼ÙÉè¾Ö²¿¹âÁ÷ºã¶¨,ËûʹÓÃÒ»¸ö3x3µÄpatch,patchÄÚµÄ9¸öÏñËض¼¾ßÓÐͬÑùµÄÔ˶¯¡£Òò´Ë,ÎÊÌâ±äΪÁË:9¸ö·½³Ì,Çó½â2¸öδ֪Êý¡£Ë㷨ʹÓÃ×îС¶þ³Ë·¨Çó½â:
[
¦¤
x
¦¤
y
]
=
[
¡Æ
i
f
x
i
2
¡Æ
i
f
x
i
f
y
i
¡Æ
i
f
x
i
f
y
i
¡Æ
i
f
y
i
2
]
?
1
[
?
¡Æ
i
f
x
i
f
t
i
?
¡Æ
i
f
y
i
f
t
i
]
\begin{bmatrix} \Delta x \\ \Delta y \end{bmatrix} = \begin{bmatrix} \sum_{i}{f_{x_i}}^2 & \sum_{i}{f_{x_i} f_{y_i} } \\ \sum_{i}{f_{x_i} f_{y_i}} & \sum_{i}{f_{y_i}}^2 \end{bmatrix}^{-1} \begin{bmatrix} - \sum_{i}{f_{x_i} f_{t_i}} \\ - \sum_{i}{f_{y_i} f_{t_i}} \end{bmatrix}
[¦¤x¦¤y?]=[¡Æi?fxi??2¡Æi?fxi??fyi???¡Æi?fxi??fyi??¡Æi?fyi??2?]?1[?¡Æi?fxi??fti???¡Æi?fyi??fti???] ÆäÖÐ
f
x
=
?
I
?
x
??
;
??
f
y
=
?
I
?
y
;
??
f
t
=
?
I
?
t
f_x = \frac{\partial I}{\partial x} \; ; \; f_y = \frac{\partial I}{\partial y}; \;f_t= \frac{\partial I}{\partial t}\\
fx?=?x?I?;fy?=?y?I?;ft?=?t?I? ×¢Òâ,ʽÖеÄÄæ¾ØÕóºÍHarris½Çµã¼ì²âÖеÄMºÜÏñ,Õâ±íÃ÷½Çµã¸üÊʺϸú×Ù¡£
ΪÁ˽â¾ö½Ï´óÔ˶¯Ê±ÎÞ·¨¸ú×ÙµÄÎÊÌâ,Ë㷨ʹÓÃͼÏñ½ð×ÖËþ,µ±Í¼Ïñ½øÐÐÉϲÉÑùʱ,´óÔ˶¯±ä³ÉÁËСÔ˶¯,СÔ˶¯±»È¥³ýÁË¡£
´úÂëʵÏÖ
vector<Point2f> prevPts, currPts;
goodFeaturesToTrack(prevImg, prevPts, 100, 0.3, 7, Mat(), 7, false, 0.04);
vector<uchar> status;
vector<float> err;
TermCriteria criteria = TermCriteria((TermCriteria::COUNT) + (TermCriteria::EPS), 10, 0.03);
calcOpticalFlowPyrLK(prevImg, currImg, prevPts, currPts, status, err, Size(15,15), 2, criteria);
vector<Point2f> good_new;
for (uint i = 0; i < prevPts.size(); i++) {
if (status[i] == 1) {
good_new.push_back(currPts[i]);
line(prevImg, currPts[i], prevPts[i], color, thickness);
}
}
ͼÏñ²åÖµ
×î½üÁÚ²åÖµ
ÔÚʵ¼ÊÓ¦ÓÃÖÐ,Ö±½ÓÏÈÖðÐи´ÖÆ,ÔÙÖðÁи´ÖÆ¡£
Ë«ÏßÐÔ²åÖµ
ÒÑÖª
Q
11
(
x
1
,
y
1
)
¡¢
Q
12
(
x
1
,
y
2
)
¡¢
Q
21
(
x
2
,
y
1
)
¡¢
Q
22
(
x
2
,
y
2
)
Q11(x1,y1)¡¢Q12(x1,y2)¡¢Q21(x2,y1)¡¢Q22(x2,y2)
Q11(x1,y1)¡¢Q12(x1,y2)¡¢Q21(x2,y1)¡¢Q22(x2,y2),ÇóÆäÖеãP(x,y)µÄÖµ¡£
Ë«ÏßÐÔ²åÖµÊÇ·Ö±ðÔÚÁ½¸ö·½Ïò¼ÆËãÁ˹²3´Îµ¥ÏßÐÔ²åÖµ,ÈçͼËùʾ,ÏÈÔÚx·½ÏòÇó2´Îµ¥ÏßÐÔ²åÖµ,»ñµÃR1(x, y1)¡¢R2(x, y2)Á½¸öÁÙʱµã,ÔÙÔÚy·½Ïò¼ÆËã1´Îµ¥ÏßÐÔ²åÖµµÃ³öP(x, y)(ʵ¼ÊÉϵ÷»»2´ÎÖáµÄ·½ÏòÏÈyºóxÒ²ÊÇÒ»ÑùµÄ½á¹û)¡£
-
¼¸ºÎÖÐÐĵãÖغ϶ÔÓ¦
s
r
c
x
=
(
d
s
t
x
+
0.5
)
?
s
r
c
w
/
d
s
t
w
?
0.5
s
r
c
y
=
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z),Æä¶ÔÓ¦Ïà»úͼÏñ×ø±êΪ
p
(
u
,
v
)
p(u,v)
p(u,v),¿ÉÒÔ½¨Á¢ÈçÏÂͶӰ¹Øϵ:
s
[
u
v
1
]
=
[
a
r
u
0
0
b
v
0
0
0
1
]
[
r
1
r
2
r
3
t
]
[
X
Y
Z
1
]
=
K
T
P
s\left[ \begin{matrix} u \\ v \\ 1 \end{matrix} \right] = \left[ \begin{matrix} a & r & u_0 \\ 0 & b & v_0 \\ 0 & 0 & 1 \end{matrix} \right] \begin{bmatrix} \bold{r}_1 & \bold{r}_2 & \bold{r}_3 & \bold{t} \end{bmatrix} \left[ \begin{matrix} X \\ Y \\ Z \\ 1\end{matrix} \right] = \bold{K} \bold{T} \bold{P}
s???uv1????=???a00?rb0?u0?v0?1????[r1??r2??r3??t?]?????XYZ1??????=KTP
ÆäÖÐKΪÏà»úÄڲξØÕó,[R, t]ΪÏà»úÍâ²Î¡£´ËÍ⻹ÓÐÏà»ú»û±ä²ÎÊý:
{
x
d
i
s
t
o
r
t
e
d
=
x
(
1
+
k
1
r
2
+
k
2
r
4
+
k
3
r
6
)
+
2
p
1
x
y
+
p
2
(
r
2
+
2
x
2
)
y
d
i
s
t
o
r
t
e
d
=
y
(
1
+
k
1
r
2
+
k
2
r
4
+
k
3
r
6
)
+
p
1
(
r
2
+
2
y
2
)
+
2
p
2
x
y
\left \{ \begin{aligned}x_{distorted}=x(1+k_1r^2+k_2r_4+k_3r^6)+2p_1xy+p_2(r^2+2x^2) \\y_{distorted}=y(1+k_1r^2+k_2r_4+k_3r^6)+p_1(r^2+2y^2)+2p_2xy\end{aligned}\right.
{xdistorted?=x(1+k1?r2+k2?r4?+k3?r6)+2p1?xy+p2?(r2+2x2)ydistorted?=y(1+k1?r2+k2?r4?+k3?r6)+p1?(r2+2y2)+2p2?xy? (x, y)ΪÏà»ú¹éÒ»»¯Æ½Ãæ×ø±ê¡£Ïà»ú±ê¶¨µÄÄ¿µÄ¾ÍÊÇÇó½âÉÏÊöÕâЩ²ÎÊý¡£
±Õʽ½â(²»¿¼ÂÇ»û±ä)
ÎÒÃÇʹÓñ궨°åÀ´½øÐб궨,ÆäËùÓÐÌØÕ÷µã¶¼¹²Ãæ,¿ÉÒÔ¼ÙÉè¸ÃƽÃæΪZ=0,´Ó¶øÈ¥µô
r
3
r_3
r3?,ÓÚÊÇͶӰ¹Øϵ¿ÉÒÔдΪ:
s
[
u
v
1
]
=
[
a
r
u
0
0
b
v
0
0
0
1
]
[
r
1
r
2
t
]
[
X
Y
1
]
s\left[ \begin{matrix} u \\ v \\ 1 \end{matrix} \right] = \left[ \begin{matrix} a & r & u_0 \\ 0 & b & v_0 \\ 0 & 0 & 1 \end{matrix} \right] \begin{bmatrix} \bold{r}_1 & \bold{r}_2 & \bold{t} \end{bmatrix} \left[ \begin{matrix} X \\ Y \\ 1\end{matrix} \right]
s???uv1????=???a00?rb0?u0?v0?1????[r1??r2??t?]???XY1????
ÖмäµÄÕâ¿é
K
[
r
1
,
r
2
,
t
]
\bold{K}[\bold{r}_1 , \bold{r}_2 , \bold{t}]
K[r1?,r2?,t]¾Í´ú±í3DµãºÍÆäͼÏñ×ø±ê¼äµÄµ¥Ó¦H,Òò´ËÓÐ:
H
=
[
h
1
h
2
h
3
]
=
¦Ë
K
[
r
1
r
2
t
]
\bold{H}= \begin{bmatrix} \bold{h}_1 & \bold{h}_2 & \bold{h}_3 \end{bmatrix} =\lambda \bold{K} \begin{bmatrix} \bold{r}_1 & \bold{r}_2 & \bold{t} \end{bmatrix}
H=[h1??h2??h3??]=¦ËK[r1??r2??t?]
¦Ë
\lambda
¦ËΪ±êÁ¿(¿ÉÒÔÀí½âΪ1/s),½«¾ØÕóÀïÃæµÄÔªËØÕ¹¿ªÓÐ
{
r
1
=
K
?
1
h
1
r
2
=
K
?
1
h
2
\left \{ \begin{aligned} \bold{r}_1=\bold{K}^{-1}\bold{h}_1 \\ \bold{r}_2=\bold{K}^{-1}\bold{h}_2 \end{aligned}\right.
{r1?=K?1h1?r2?=K?1h2?? ÓÖÓÉÓÚÐýת¾ØÕóÓÐÕý½»ÐԺ͵¥Î»ÐÔ,Òò´ËÎÒÃÇÓÐ
{
r
1
T
r
2
=
0
¡ú
h
1
T
K
?
T
K
?
1
h
2
=
0
¨O
¨O
r
1
¨O
¨O
=
¨O
¨O
r
2
¨O
¨O
¡ú
h
1
T
K
?
T
K
?
1
h
1
=
h
2
T
K
?
T
K
?
1
h
2
\left \{ \begin{aligned} \bold{r}_1^T\bold{r}_2 &= 0 \rightarrow \bold{h}_1^T\bold{K}^{-T}\bold{K}^{-1} \bold{h}_2 = 0 \\ ||\bold{r}_1||&=||\bold{r}_2|| \rightarrow \bold{h}_1^T\bold{K}^{-T}\bold{K}^{-1} \bold{h}_1= \bold{h}_2^T\bold{K}^{-T}\bold{K}^{-1} \bold{h}_2 \end{aligned}\right.
{r1T?r2?¨O¨Or1?¨O¨O?=0¡úh1T?K?TK?1h2?=0=¨O¨Or2?¨O¨O¡úh1T?K?TK?1h1?=h2T?K?TK?1h2?? ÎÒÃÇÁî
B
=
K
?
T
K
?
1
\bold{B}=\bold{K}^{-T}\bold{K}^{-1}
B=K?TK?1,ÔòÓÐ
B
=
K
?
T
K
?
1
=
[
B
11
B
12
B
13
B
21
B
22
B
23
B
31
B
32
B
33
]
=
[
1
a
2
?
r
a
2
b
v
0
r
?
u
0
b
a
2
b
?
r
a
2
b
r
a
2
b
+
1
b
2
?
r
(
v
0
r
?
u
0
b
)
a
2
b
2
?
v
0
b
2
v
0
r
?
u
0
b
a
2
b
?
r
(
v
0
r
?
u
0
b
)
a
2
b
2
?
v
0
b
2
(
v
0
r
?
u
0
b
)
2
a
2
b
2
+
v
0
2
b
2
+
1
]
\bold{B}=\bold{K}^{-T}\bold{K}^{-1}= \begin{bmatrix} B_{11} & B_{12} &B_{13}\\ B_{21} & B_{22} & B_{23} \\ B_{31} & B_{32} & B_{33} \end{bmatrix} = \\ \begin{bmatrix} \frac{1}{a^2} & -\frac{r}{a^2b} & \frac{v_0r-u_0b}{a^2b} \\ -\frac{r}{a^2b} & \frac{r}{a^2b}+\frac{1}{b^2} & -\frac{r(v_0r-u_0b)}{a^2b^2}-\frac{v_0}{b^2} \\ \frac{v_0r-u_0b}{a^2b} & -\frac{r(v_0r-u_0b)}{a^2b^2}-\frac{v_0}{b^2} & \frac{(v_0r-u_0b)^2}{a^2b^2}+\frac{v_0^2}{b^2}+1 \end{bmatrix}
B=K?TK?1=???B11?B21?B31??B12?B22?B32??B13?B23?B33?????=????a21??a2br?a2bv0?r?u0?b???a2br?a2br?+b21??a2b2r(v0?r?u0?b)??b2v0???a2bv0?r?u0?b??a2b2r(v0?r?u0?b)??b2v0??a2b2(v0?r?u0?b)2?+b2v02??+1????? ÒòΪBÊǶԳƾØÕó,Òò´Ë²»·ÁÉèÏòÁ¿
b
\bold{b}
bΪ:
b
=
[
B
11
,
B
12
,
B
22
,
B
13
,
B
23
,
B
33
]
T
\bold{b}=\begin{bmatrix} B_{11},B_{12},B_{22},B_{13},B_{23},B_{33} \end{bmatrix}^T
b=[B11?,B12?,B22?,B13?,B23?,B33??]T ¶ÔÓÚµ¥Ó¦¾ØÕóHµÄÁÐÏòÁ¿
h
i
\bold{h}_i
hi?,ÓÐ:
h
i
=
[
h
i
1
,
h
i
2
,
h
i
3
]
T
\bold{h}_i=[h_{i1},h_{i2},h_{i3}]^T
hi?=[hi1?,hi2?,hi3?]T ½«
b
b
bºÍ
h
i
h_i
hi?´úÈëµ½Ðýת¾ØÕóµÄÁ½¸öÔ¼ÊøÖÐÈ¥,µÃµ½:
h
i
T
B
h
j
=
m
i
j
T
b
=
0
\bold{h}_i^T\bold{B}\bold{h}_j=\bold{m}_{ij}^T\bold{b}=0
hiT?Bhj?=mijT?b=0 ÆäÖÐ,
m
i
j
=
[
h
i
1
h
j
1
,
h
i
1
h
j
2
+
h
i
2
h
j
1
,
h
i
2
h
j
2
,
h
i
3
h
j
1
+
h
i
1
h
j
3
,
h
i
3
h
j
2
+
h
i
2
h
j
3
,
h
i
3
h
j
3
]
T
\bold{m}_{ij}=[h_{i1}h_{j1},h_{i1}h_{j2}+h_{i2}h_{j1},h_{i2}h_{j2},h_{i3}h_{j1}+h_{i1}h_{j3},h_{i3}h_{j2}+h_{i2}h_{j3},h_{i3}h_{j3}]^T
mij?=[hi1?hj1?,hi1?hj2?+hi2?hj1?,hi2?hj2?,hi3?hj1?+hi1?hj3?,hi3?hj2?+hi2?hj3?,hi3?hj3?]T¡£
×îÖÕ,Á½¸öÔ¼Êø¿ÉÒÔдΪÆë´Î·½³Ì:
[
m
12
T
(
m
11
?
m
22
)
T
]
b
=
M
2
¡Á
6
b
=
0
\begin{bmatrix} \bold{m}_{12}^T \\ (\bold{m}_{11}-\bold{m}_{22})^T \end{bmatrix} \bold{b}=\bold{M}_{2\times6}\bold{b}= \bold{0}
[m12T?(m11??m22?)T?]b=M2¡Á6?b=0 MÊÇÓɵ¥Ó¦H¾ö¶¨µÄÒÑÖªÁ¿,Òò´ËÖ»ÒªÇó½âÉÏÊö·½³Ì¼´¿ÉµÃµ½b¡£ÓÉÓÚÒ»ÕÅͼÏñ¾Í¿ÉÒԵõ½2¸öÔ¼Êø,Òò´ËÇó½â¸Ã·½³ÌÖÁÉÙÐèÒª²É¼¯3ÕÅͼÏñ,ʵ¼ÊÖÐ,ͨ³£»á²É¼¯15-20ÕÅ×óÓÒ¡£
¸Ã·½³Ì¿ÉÒÔʹÓÃSVD½øÐÐÇó½â,¼´
M
=
U
D
V
6
¡Á
6
T
\bold{M}=\bold{U}\bold{D}\bold{V}_{6\times6}^T
M=UDV6¡Á6T?,½«V°´DÖÐÌØÕ÷ÖµµÄ½µÐòÅÅÐò,È¡VµÄ×îºóÒ»ÁеÄÁÐÏòÁ¿¼´ÎªËùÇób¡£
µ±Çó³öbºÍ¾ØÕóBºó,¼´¿É°´(55)ÃèÊöµÄ
B
=
K
?
T
K
?
1
\bold{B}=\bold{K}^{-T}\bold{K}^{-1}
B=K?TK?1Çó½âÄÚ²ÎK:
v
0
=
(
B
12
B
13
?
B
11
B
23
)
/
(
B
11
B
22
?
B
12
2
)
¦Ë
=
B
33
?
[
B
13
2
+
v
0
(
B
12
B
13
?
B
11
B
23
)
]
/
B
11
a
=
¦Ë
/
B
11
b
=
¦Ë
B
11
/
(
B
11
B
22
?
B
12
2
)
r
=
?
B
12
a
2
b
/
¦Ë
u
0
=
r
v
0
/
a
?
B
13
a
2
/
¦Ë
\begin{aligned} v_0&=(B_{12}B_{13}-B_{11}B_{23})/(B_{11}B_{22}-B_{12}^2) \\ \lambda&=B_{33}-[B_{13}^2+v_0(B_{12}B_{13}-B_{11}B_{23})]/B_{11} \\ a&=\sqrt{\lambda/B_{11}} \\ b&=\sqrt{\lambda B_{11}/(B_{11}B_{22}-B_{12}^2)} \\ r&=-B_{12}a^2b/\lambda \\ u_0&=rv_0/a-B_{13}a^2/\lambda \end{aligned}
v0?¦Ëabru0??=(B12?B13??B11?B23?)/(B11?B22??B122?)=B33??[B132?+v0?(B12?B13??B11?B23?)]/B11?=¦Ë/B11?
?=¦ËB11?/(B11?B22??B122?)
?=?B12?a2b/¦Ë=rv0?/a?B13?a2/¦Ë? Íâ²Î¿ÉÒÔÓÉÄڲκ͵¥Ó¦Çó³ö:
r
1
=
¦Ë
K
?
1
h
1
r
2
=
¦Ë
K
?
1
h
2
r
1
=
r
1
¡Á
r
2
t
=
¦Ë
K
?
1
h
3
\begin{aligned} \bold{r}_1=\lambda \bold{K}^{-1}\bold{h}_1 \\ \bold{r}_2=\lambda \bold{K}^{-1}\bold{h}_2 \\ \bold{r}_1=\bold{r}_{1}\times\bold{r}_2 \\ \bold{t}=\lambda \bold{K}^{-1}\bold{h}_3 \end{aligned}
r1?=¦ËK?1h1?r2?=¦ËK?1h2?r1?=r1?¡Ár2?t=¦ËK?1h3?? ÆäÖÐ,
¦Ë
=
1
/
¨O
¨O
K
?
1
h
1
¨O
¨O
=
1
/
¨O
¨O
K
?
1
h
2
¨O
¨O
\lambda=1/||\bold{K}^{-1}\bold{h}_1||=1/||\bold{K}^{-1}\bold{h}_2||
¦Ë=1/¨O¨OK?1h1?¨O¨O=1/¨O¨OK?1h2?¨O¨O,ÓÉÓÚÔëÉù´æÔÚ,¼ÆËã³öÀ´µÄÐýת¾ØÕóR²¢²»Ò»¶¨Âú×㵥λÕý½»µÄÐÔÖÊ,Òò´Ë¿ÉÒÔÓÃQR·Ö½â,»òÕß½«½á¹û´Ó¾ØÕó¿Õ¼äÖØͶӰµ½SE(3)Á÷ÐÎÉÏ:
R
=
(
R
R
T
)
?
1
/
2
R
\bold{R}=(\bold{R}\bold{R}^T)^{-1/2}\bold{R}
R=(RRT)?1/2R
ÓÅ»¯½â(¿¼ÂÇ»û±ä)
֮ǰµÄ±Õʽ½â¼ÆËãûÓп¼ÂÇ»û±ä,Òò´ËÎÒÃÇ»¹ÐèÒª¶Ô±Õʽ½â½øÒ»²½ÓÅ»¯¡£ÎÒÃǶ¨Ò忼ÂÇÁË»û±äµÄÖØͶӰÎó²îÄ¿±êº¯Êý:
¡Æ
i
=
1
n
¡Æ
j
=
1
m
¨O
¨O
p
i
j
?
p
^
(
K
,
k
1
,
k
2
,
k
3
,
p
1
,
p
2
,
R
i
,
t
i
,
P
j
)
¨O
¨O
\sum_{i=1}^n\sum_{j=1}^m ||\bold{p}_{ij}-\bold{\hat{p}}(\bold{K},k_1,k_2,k_3,p_1,p_2,\bold{R_i},\bold{t_i},\bold{P}_j)||
i=1¡Æn?j=1¡Æm?¨O¨Opij??p^?(K,k1?,k2?,k3?,p1?,p2?,Ri?,ti?,Pj?)¨O¨O ÆäÖÐ,ÓÐnÕÅͼÏñ,m¸ö3Dµã¡£Í¨¹ý×îС»¯¸ÃÄ¿±êº¯Êý,¼´¿ÉÇó½âÏà»úµÄÄڲΡ¢»û±ä¡¢Íâ²Î¡£
ÎÒÃÇÉ趨ÄÚÍâ²ÎµÄ³õʼֵ¼´ÎªÏÈÇ°ÇóµÃ±Õʽ½â,»û±ä²ÎÊý³õʼΪ0¡£²ÉÓÃLMËã·¨½øÐÐÓÅ»¯,×îºó¼´¿ÉÇóµÃÏà»úµÄ²ÎÊý,Íê³ÉÏà»úµÄ±ê¶¨¡£
|