## 关于双目立体视觉的一些总结（二）

https://blog.csdn.net/u014629875/article/details/51340144

1.

/*Mat_<uchar>对应的是CV_8U，Mat_<uchar>对应的是CV_8U，Mat_<char>对应的是CV_8S，Mat_<int>对应的是CV_32S，Mat_<float>对应的是CV_32F，Mat_<double>对应的是CV_64F*/
#define CV_8U   0
#define CV_8S   1
#define CV_16U  2
#define CV_16S  3
#define CV_32S  4
#define CV_32F  5
#define CV_64F  6
1
2
3
4
5
6
7
8
9

2.

3.

（1）基于背景建模：

（2）基于统计学习的方法：

/*前后帧相减*/
VideoCapture video("../camera.avi");
Mat img1, img2, gray1, gray2, grayDiff;
int diff_threshold = 20;  //帧差阈值
while(1)
{
objectDetector(img1);
cvtColor(img1,gray1,CV_BGR2GRAY);
cvtColor(img2,gray2,CV_BGR2GRAY);
subtract(gray1,gray2,grayDiff);
for(int i = 0; i < grayDiff.rows; ++i)
{
for(int j = 0; j < grayDiff.cols; ++j)
{
if( abs(grayDiff.at<uchar>(i,j)) >= diff_threshold )
{
grayDiff.at<uchar>(i,j) = 255;
}
else
{
grayDiff.at<uchar>(i,j) = 0;
}
}
}
imshow("background",gray1);
imshow("zhencha",grayDiff);
char c = cvWaitKey(33);
if(c == 27)
break;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*三帧法*/
VideoCapture video("../camera.avi");
Mat img1, img2, gray1, gray2;
Mat img3, gray3, grayDiff1, grayDiff2;
int diff_threshold = 20;  //帧差阈值
while(1)
{
cvtColor(img1,gray1,CV_BGR2GRAY);
cvtColor(img2,gray2,CV_BGR2GRAY);
cvtColor(img3,gray3,CV_BGR2GRAY);
subtract(gray1,gray2,grayDiff1);
subtract(gray2,gray3,grayDiff2);
for(int i = 0; i < grayDiff1.rows; ++i)
{
for(int j = 0; j < grayDiff2.cols; ++j)
{
if( abs(grayDiff1.at<uchar>(i,j)) >= diff_threshold )
{
grayDiff1.at<uchar>(i,j) = 255;
}
else
{
grayDiff1.at<uchar>(i,j) = 0;
}
if( abs(grayDiff2.at<uchar>(i,j)) >= diff_threshold )
{
grayDiff2.at<uchar>(i,j) = 255;
}
else
{
grayDiff2.at<uchar>(i,j) = 0;
}
}
}
bitwise_and(grayDiff1,grayDiff2,grayDiff);//和运算
imshow("background",img2);
imshow("zhencha",grayDiff);
char c = cvWaitKey(33);
if(c == 27)
break;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

---------------------

posted on 2018-11-13 14:54 zmj 阅读(124) 评论(0)  编辑 收藏 引用