Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
D
datang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhaoyunfei
datang
Commits
0ef776fc
Commit
0ef776fc
authored
Jan 27, 2021
by
wanghailong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改参数,增加策略减少误检
parent
72b18292
Pipeline
#611
failed with stages
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
60 deletions
+98
-60
CBM_model.cpp
CBM_model.cpp
+20
-20
DetectAnomaly.cpp
DetectAnomaly.cpp
+18
-16
ObjLeftDetect.cpp
ObjLeftDetect.cpp
+36
-9
ObjLeftDetect.h
ObjLeftDetect.h
+4
-0
main.cpp
main.cpp
+18
-13
myDIP.cpp
myDIP.cpp
+2
-2
No files found.
CBM_model.cpp
View file @
0ef776fc
...
...
@@ -51,10 +51,10 @@ CBM_model::~CBM_model()
}
void
CBM_model
::
Initialize
()
{
//_writer6.open("long.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),0);
//_writer7.open("short.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),0);
//_writer8.open("static.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),1);
//_writer10.open("DPM.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),1);
//
_writer6.open("long.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),0);
//
_writer7.open("short.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),0);
//
_writer8.open("static.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),1);
//
_writer10.open("DPM.avi",cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),1);
mog_fg
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC1
);
...
...
@@ -106,10 +106,10 @@ void CBM_model::Initialize()
void
CBM_model
::
Uninitialize
()
{
#ifdef DEBUG
//_writer6.release();
//_writer7.release();
//_writer8.release();
//_writer10.release();
//
_writer6.release();
//
_writer7.release();
//
_writer8.release();
//
_writer10.release();
#endif
// cvReleaseImage(&mog_fg);
...
...
@@ -166,9 +166,9 @@ bool CBM_model::Motion_Detection(myImage *img)
frame_count
++
;
//_writer6.write(mog_fg);
//_writer7.write(mog_fg2);
//_writer8.write(imgStatic);
//
_writer6.write(mog_fg);
//
_writer7.write(mog_fg2);
//
_writer8.write(imgStatic);
return
false
;
}
else
{
...
...
@@ -180,8 +180,8 @@ bool CBM_model::Motion_Detection(myImage *img)
_myGMM2
->
process
(
_Previous_Img
[
FG_count
],
input_temp
);
myImageAND
(
input_temp
,
maskROI
,
my_mog_fg2
);
myDiladeitself
(
my_mog_fg
,
5
);
myDiladeitself
(
my_mog_fg2
,
5
);
myDiladeitself
(
my_mog_fg
,
3
);
myDiladeitself
(
my_mog_fg2
,
3
);
if
(
check_foreground2
(
my_mog_fg
)
>
(
my_mog_fg
->
width
*
my_mog_fg
->
height
*
0.30
)){
//if motion detection cannot work well
_myGMM
->
ChangeLearningRate
(
0.02
);
//speed up long-term model's learning rate to adapt the lighting changes.
...
...
@@ -214,9 +214,9 @@ bool CBM_model::Motion_Detection(myImage *img)
}
//_writer6.write(mog_fg);
//_writer7.write(mog_fg2);
//_writer8.write(imgStatic);
//
_writer6.write(mog_fg);
//
_writer7.write(mog_fg2);
//
_writer8.write(imgStatic);
FG_count
=
FG_count
+
1
;
FG_count
=
FG_count
%
TEMPORAL_RULE
;
...
...
@@ -297,10 +297,10 @@ int CBM_model::GetLabeling2( myImage *pImg1, int areaThreshold, int option)
vector
<
int
>
color_labels
;
color_labels
.
clear
();
for
(
int
i
=
0
;
i
<
pImg1
->
width
*
pImg1
->
height
;
i
++
){
//
if(out[i] > 2473){
//
std::cout << "error number : " << out[i] <<std::endl;
//
continue;
//
}
if
(
out
[
i
]
>
2473
){
//
std::cout << "error number : " << out[i] <<std::endl;
continue
;
}
constant_template
[
out
[
i
]]
=
true
;
}
for
(
int
i
=
0
;
i
<
2474
;
i
++
){
...
...
DetectAnomaly.cpp
View file @
0ef776fc
...
...
@@ -29,7 +29,9 @@ double INPUT_RESIZE;
bool
DetectAnomaly
::
detectAnomaly
(
cv
::
Mat
img
,
vector
<
vector
<
int
>>*
resultLocation
)
{
yolo_test
=
img
.
clone
();
cv
::
resize
(
img
,
img
,
cv
::
Size
(
2688
*
0.25
,
1520
*
0.25
),
cv
::
INTER_CUBIC
);
cv
::
Rect
rect
(
0
,
750
,
2400
,
770
);
img
=
img
(
rect
);
cv
::
resize
(
img
,
img
,
cv
::
Size
(
2400
*
0.25
,
770
*
0.25
),
cv
::
INTER_CUBIC
);
img
.
copyTo
(
myimg
);
medianBlur
(
mat_myimg
,
mat_myimg
,
3
);
opencv_2_myImage
(
myimg
,
myimg1
);
//transfer opencv data to myimage data
...
...
@@ -83,14 +85,14 @@ DetectAnomaly::DetectAnomaly()
// // INPUT_RESIZE = 0.25;
cfgAnomaly
.
input_resize
=
0.25
;
cfgAnomaly
.
owner_search_roi
=
10
;
cfgAnomaly
.
gmm_learn_frame
=
10
00
;
cfgAnomaly
.
gmm_learn_frame
=
3
00
;
cfgAnomaly
.
max_sfg
=
15625
;
cfgAnomaly
.
min_sfg
=
50
;
cfgAnomaly
.
min_sfg
=
15
;
cfgAnomaly
.
max_fg
=
75000
;
cfgAnomaly
.
min_fg
=
10
0
;
cfgAnomaly
.
buffer_length
=
3
00
;
cfgAnomaly
.
image_height
=
152
0
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
image_width
=
2
688
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
min_fg
=
5
0
;
cfgAnomaly
.
buffer_length
=
1
00
;
cfgAnomaly
.
image_height
=
77
0
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
image_width
=
2
400
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
gmm_long_learn_rate
=
0.0001
;
cfgAnomaly
.
gmm_short_learn_rate
=
0.002
;
...
...
@@ -99,24 +101,24 @@ DetectAnomaly::DetectAnomaly()
// set gloabl var
INPUT_RESIZE
=
1.0
;
OWNER_SEARCH_ROI
=
10
;
GMM_LEARN_FRAME
=
10
00
;
//frame number for GMM initialization
GMM_LEARN_FRAME
=
3
00
;
//frame number for GMM initialization
MAX_SFG
=
15625
;
MIN_SFG
=
50
;
MIN_SFG
=
15
;
MAX_FG
=
75000
;
MIN_FG
=
10
0
;
BUFFER_LENGTH
=
3
00
;
MIN_FG
=
5
0
;
BUFFER_LENGTH
=
1
00
;
GMM_LONG_LEARN_RATE
=
0.0001
;
GMM_SHORT_LEARN_RATE
=
0.002
;
// INPUT_RESIZE = 0.25;
cfgAnomaly
.
top_left_x
=
759
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
top_left_y
=
78
5
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
top_left_y
=
3
5
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
top_right_x
=
1581
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
top_right_y
=
77
1
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
top_right_y
=
2
1
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
bottom_left_x
=
73
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
bottom_left_y
=
148
9
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
bottom_left_y
=
73
9
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
bottom_right_x
=
2376
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
bottom_right_y
=
141
1
*
cfgAnomaly
.
input_resize
;
cfgAnomaly
.
bottom_right_y
=
66
1
*
cfgAnomaly
.
input_resize
;
obj_left
=
false
;
arr
[
0
]
=
4
;
...
...
@@ -148,7 +150,7 @@ DetectAnomaly::DetectAnomaly()
opencv_2_myImage
(
mask
,
mymask
);
#ifdef DEBUG
cv
::
imwrite
(
"mask.jpg"
,
Image1
);
//
cv::imwrite("mask.jpg", Image1);
cv
::
waitKey
(
1
);
//cvReleaseImage(&Image1);
#endif
...
...
ObjLeftDetect.cpp
View file @
0ef776fc
...
...
@@ -13,8 +13,7 @@ ObjLeftDetect::ObjLeftDetect(myImage * input, int set_MOG_LearnFrame, int set_mi
_CBM_model
=
new
CBM_model
(
input
,
set_MOG_LearnFrame
,
set_min_area
,
set_buffer_len
,
INPUT_RESIZE
,
mask
);
new_width
=
(
int
)(
input
->
width
*
INPUT_RESIZE
);
new_height
=
(
int
)(
input
->
height
*
INPUT_RESIZE
);
// new_width = (int)(input->width);
// new_height = (int)(input->height);
initialize
();
alarmList
.
clear
();
}
...
...
@@ -28,6 +27,17 @@ void ObjLeftDetect::ObjLeftSet(myImage *input, int set_MOG_LearnFrame, int set_m
_CBM_model
=
new
CBM_model
(
input
,
set_MOG_LearnFrame
,
set_min_area
,
set_buffer_len
,
INPUT_RESIZE
,
mask
);
new_width
=
(
int
)(
input
->
width
*
INPUT_RESIZE
);
new_height
=
(
int
)(
input
->
height
*
INPUT_RESIZE
);
objmask
=
cv
::
Mat
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC1
);
myImage_2_opencv
(
mask
,
objmask
);
cv
::
findContours
(
objmask
,
contours
,
cv
::
noArray
(),
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_SIMPLE
);
cv
::
Mat
showpic
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC1
);
drawContours
(
showpic
,
contours
,
0
,
Scalar
::
all
(
255
));
// cv::imwrite("show.jpg",showpic);
// new_width = (int)(input->width);
// new_height = (int)(input->height);
// std::cout << "contours size : " << contours.size() << " "<< contours[0].size() <<std::endl;
// new_width = (int)(input->width);
// new_height = (int)(input->height);
initialize
();
...
...
@@ -61,6 +71,7 @@ void ObjLeftDetect::initialize()
A
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC3
);
B
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC3
);
// _writer1.open("static_to_track.avi", cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),1);
// _writer2.open("summary.avi", cv::VideoWriter::fourcc('X','V','I','D'),30,cv::Size(new_width,new_height),1);
...
...
@@ -72,8 +83,8 @@ bool ObjLeftDetect::process(myImage * input, cv::Mat show_pic, vector<vector<int
cv
::
Mat
test
;
test
=
cv
::
Mat
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC3
);
set_alarm
=
false
;
myResize
(
input
,
myimg2
);
object_detected
=
_CBM_model
->
Motion_Detection
(
myimg2
);
//
myResize(input,myimg2);
object_detected
=
_CBM_model
->
Motion_Detection
(
input
);
if
(
object_detected
==
true
)
{
...
...
@@ -100,16 +111,32 @@ bool ObjLeftDetect::process(myImage * input, cv::Mat show_pic, vector<vector<int
auto
result
=
results_map
.
at
(
0
);
auto
obj
=
LeftLocation
[
i
];
int
objx0
=
(
obj
->
x
-
obj
->
width
/
2
)
*
4
;
int
objy0
=
(
obj
->
y
-
obj
->
height
/
2
)
*
4
;
int
objx1
=
(
obj
->
x
+
obj
->
width
/
2
)
*
4
;
int
objy1
=
(
obj
->
y
+
obj
->
height
/
2
)
*
4
;
int
objx0
=
(
obj
->
x
-
obj
->
width
)
;
int
objy0
=
(
obj
->
y
-
obj
->
height
)
;
int
objx1
=
(
obj
->
x
+
obj
->
width
)
;
int
objy1
=
(
obj
->
y
+
obj
->
height
)
;
vector
<
int
>
ojblocation
=
{
objx0
,
objy0
,
objx1
,
objy1
};
if
(
((
objx1
-
objx0
)
>
200
)
||
((
objy1
-
objy0
)
>
200
)
){
//check points location
cv
::
Point2f
point1
(
objx0
,
objy0
);
cv
::
Point2f
point2
(
objx1
,
objy1
);
auto
check1
=
cv
::
pointPolygonTest
(
contours
[
0
],
point1
,
false
);
auto
check2
=
cv
::
pointPolygonTest
(
contours
[
0
],
point2
,
false
);
std
::
cout
<<
check1
<<
" "
<<
check2
<<
std
::
endl
;
if
(
(
check1
==
-
1
)
||
(
check2
==-
1
)
){
continue
;
}
if
(
((
objx1
-
objx0
)
>
50
)
||
((
objy1
-
objy0
)
>
50
)
){
continue
;
}
bool
iscar
=
false
;
for
(
int
j
=
0
;
j
<
result
->
facility
.
size
();
j
++
)
{
...
...
ObjLeftDetect.h
View file @
0ef776fc
...
...
@@ -69,6 +69,10 @@ private:
bool
set_alarm
;
int
pic_num
=
0
;
//get mask points
cv
::
Mat
objmask
;
std
::
vector
<
std
::
vector
<
cv
::
Point
>>
contours
;
};
#endif
main.cpp
View file @
0ef776fc
...
...
@@ -42,7 +42,7 @@ int main()
int
count
=
0
;
// char test_video[200] = "zhao.mp4";
char
test_video
[
200
]
=
"
../test_video/out
.avi"
;
char
test_video
[
200
]
=
"
/media/6542bc52-3d7a-4bea-b9b6-f9343ca8560f/AB/test_video/test-6
.avi"
;
VideoDetails
*
_video
;
_video
=
new
VideoDetails
(
test_video
);
//VideoCapture capture;
...
...
@@ -52,6 +52,7 @@ int main()
cv
::
Mat
qImg
;
// config opt;
DetectAnomaly
detect
;
int
pic_num
=
0
;
#ifdef DEBUG
//cv::VideoWriter _writer;
//_writer.open("alarm.avi", cv::VideoWriter::fourcc('X', 'V', 'I', 'D'), 30, cv::Size(2448*0.25, 2048*0.25), 1);
...
...
@@ -60,22 +61,22 @@ int main()
/* main loop */
/************************************************************************/
bool
obj_left
=
false
;
//calculate time
struct
timeval
start
,
end
;
float
time
=
0
;
gettimeofday
(
&
start
,
NULL
);
while
(
_video
->
_file
.
read
(
qImg
))
{
// cvResize(src_img,des_img,CV_INTER_LINEAR);
vector
<
vector
<
int
>>
resultLocation
;
//calculate time
struct
timeval
start
,
end
;
float
time
=
0
;
gettimeofday
(
&
start
,
NULL
);
pic_num
++
;
if
(
pic_num
%
2
==
0
){
continue
;
}
obj_left
=
detect
.
detectAnomaly
(
qImg
,
&
resultLocation
);
gettimeofday
(
&
end
,
NULL
);
time
=
(
1000000
*
(
end
.
tv_sec
-
start
.
tv_sec
)
+
end
.
tv_usec
-
start
.
tv_usec
)
/
(
1000.0
);
cout
<<
"total time = "
<<
time
<<
"ms"
<<
endl
;
//yolo_infer
...
...
@@ -94,10 +95,10 @@ int main()
printf
(
"alram!!
\n
"
);
for
(
int
i
=
0
;
i
<
resultLocation
.
size
();
i
++
){
int
x0
=
resultLocation
[
i
][
0
];
int
y0
=
resultLocation
[
i
][
1
];
int
x1
=
resultLocation
[
i
][
2
];
int
y1
=
resultLocation
[
i
][
3
];
int
x0
=
resultLocation
[
i
][
0
]
*
4
;
int
y0
=
resultLocation
[
i
][
1
]
*
4
+
750
;
int
x1
=
resultLocation
[
i
][
2
]
*
4
;
int
y1
=
resultLocation
[
i
][
3
]
*
4
+
750
;
cv
::
Point
p1
(
x0
,
y0
);
cv
::
Point
p2
(
x1
,
y1
);
...
...
@@ -116,6 +117,10 @@ int main()
}
#endif
}
gettimeofday
(
&
end
,
NULL
);
time
=
(
1000000
*
(
end
.
tv_sec
-
start
.
tv_sec
)
+
end
.
tv_usec
-
start
.
tv_usec
)
/
(
1000.0
);
cout
<<
"total time = "
<<
time
<<
"ms"
<<
endl
;
#ifdef DEBUG
printf
(
"Finished detec, then release ...
\n
"
);
...
...
myDIP.cpp
View file @
0ef776fc
...
...
@@ -28,7 +28,7 @@ void*** Memory_Allocate(int width, int height, int depth)
for
(
int
i
=
0
;
i
<
width
;
i
++
)
for
(
int
j
=
0
;
j
<
height
;
j
++
)
for
(
int
k
=
0
;
k
<
depth
;
k
++
)
pixel_index
[
i
][
j
][
k
]
=
NULL
;
pixel_index
[
i
][
j
][
k
]
=
' '
;
return
(
void
***
)
pixel_index
;
}
...
...
@@ -53,7 +53,7 @@ void* Memory_Allocate1D(int width, int height, int depth)
pixel_index
=
(
unsigned
char
*
)
malloc
(
width
*
height
*
depth
*
sizeof
(
unsigned
char
));
for
(
int
i
=
0
;
i
<
width
*
height
*
depth
;
i
++
)
pixel_index
[
i
]
=
NULL
;
pixel_index
[
i
]
=
' '
;
return
(
void
*
)
pixel_index
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment