//将第5和第9条单独取出来
Mat roi05
=
src(Rect(
6
*
VUpper[
4
],
0
,
6
*
(VDown[
4
]
-
VUpper[
4
]),src.rows));
Mat roi09
=
src(Rect(
6
*
VUpper[
8
],
0
,
6
*
(VDown[
8
]
-
VUpper[
8
]),src.rows));
cvtColor(roi05,roi05,CV_BGR2GRAY);
cvtColor(roi09,roi09,CV_BGR2GRAY);
threshold(roi05,roi05,
100
,
255
,THRESH_OTSU);
threshold(roi09,roi09,
100
,
255
,THRESH_OTSU);
threshold(roi05,roi05,
0
,
255
,THRESH_BINARY_INV);
threshold(roi09,roi09,
0
,
255
,THRESH_BINARY_INV);
std
:
:
vector
<
std
:
:
vector
<
cv
:
:
Point
>>
contours2;
findContours(roi05,contours2,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
int
imax2
=
0
;
int
imaxcontour2
=
-
1
;
for
(
int
i
=
0
;i
<
contours2.size();i
++
)
{
int
itmp
=
contourArea(contours2[i]);
if
(imaxcontour2
<
itmp )
{
imax2
=
i;
imaxcontour2
=
itmp;
}
}
Rect boundRect2;
//最小外接矩形
boundRect2
=
boundingRect(Mat(contours2[imax2]));
if
(boundRect2.y
+
boundRect2.height
>
750
)
{
//printf("第5个为打开的\n");
result[
4
]
=
0
;
}
else
{
//printf("第5个为关闭的\n");
result[
4
]
=
1
;
}
contours2.clear();
findContours(roi09,contours2,CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE);
imax2
=
0
;
imaxcontour2
=
-
1
;
for
(
int
i
=
0
;i
<
contours2.size();i
++
)
{
int
itmp
=
contourArea(contours2[i]);
if
(imaxcontour2
<
itmp )
{
imax2
=
i;
imaxcontour2
=
itmp;
}
}
boundRect2
=
boundingRect(Mat(contours2[imax2]));
if
(boundRect2.y
+
boundRect2.height
>
750
)
{
//printf("第9个为打开的\n");
result[
8
]
=
0
;
}
else
{
//printf("第9个为关闭的\n");
result[
8
]
=
1
;
}