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
e1126306
Commit
e1126306
authored
Mar 01, 2021
by
wanghailong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决初始化失败的问题
parent
26243a88
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
448 additions
and
445 deletions
+448
-445
CBM_model.cpp
CBM_model.cpp
+6
-6
CBM_model.h
CBM_model.h
+4
-4
CMakeLists.txt
CMakeLists.txt
+1
-1
DetectAnomaly.cpp
DetectAnomaly.cpp
+23
-21
DetectAnomaly.h
DetectAnomaly.h
+3
-4
ObjLeftDetect.cpp
ObjLeftDetect.cpp
+377
-375
ObjLeftDetect.h
ObjLeftDetect.h
+6
-6
main.cpp
main.cpp
+27
-27
CMakeLists.txt
yolov3/CMakeLists.txt
+1
-1
No files found.
CBM_model.cpp
View file @
e1126306
...
@@ -57,9 +57,9 @@ void CBM_model::Initialize()
...
@@ -57,9 +57,9 @@ void CBM_model::Initialize()
// _writer10.open("DPM.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
);
//
mog_fg = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC1);
mog_fg2
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC1
);
//
mog_fg2 = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC1);
imgStatic
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC3
);
//
imgStatic = cv::Mat::zeros(cv::Size(new_width, new_height), CV_8UC3);
my_mog_fg
=
myCreateImage
(
new_width
,
new_height
,
1
);
my_mog_fg
=
myCreateImage
(
new_width
,
new_height
,
1
);
my_mog_fg2
=
myCreateImage
(
new_width
,
new_height
,
1
);
my_mog_fg2
=
myCreateImage
(
new_width
,
new_height
,
1
);
...
@@ -196,9 +196,9 @@ bool CBM_model::Motion_Detection(myImage *img)
...
@@ -196,9 +196,9 @@ bool CBM_model::Motion_Detection(myImage *img)
staticFG_pixel_num_pre
=
staticFG_pixel_num_now
;
staticFG_pixel_num_pre
=
staticFG_pixel_num_now
;
staticFG_pixel_num_now
=
check_foreground2
(
my_imgStatic
);
staticFG_pixel_num_now
=
check_foreground2
(
my_imgStatic
);
myImage_2_opencv
(
my_imgStatic
,
imgStatic
);
//
myImage_2_opencv(my_imgStatic,imgStatic);
myImage_2_opencv
(
my_mog_fg
,
mog_fg
);
//
myImage_2_opencv(my_mog_fg,mog_fg);
myImage_2_opencv
(
my_mog_fg2
,
mog_fg2
);
//
myImage_2_opencv(my_mog_fg2,mog_fg2);
// cv::imwrite("static_obj.jpg", imgStatic);
// cv::imwrite("static_obj.jpg", imgStatic);
// cv::imwrite("Long-term.jpg", mog_fg);
// cv::imwrite("Long-term.jpg", mog_fg);
// cv::imwrite("Short-term.jpg", mog_fg2);
// cv::imwrite("Short-term.jpg", mog_fg2);
...
...
CBM_model.h
View file @
e1126306
...
@@ -91,7 +91,7 @@ public:
...
@@ -91,7 +91,7 @@ public:
int
TEMPORAL_RULE
;
int
TEMPORAL_RULE
;
//VideoDetails *_video;//input video
//VideoDetails *_video;//input video
cv
::
VideoWriter
_writer6
,
_writer7
,
_writer8
,
_writer9
,
_writer10
;
//
cv::VideoWriter _writer6, _writer7, _writer8, _writer9, _writer10;
CBM_model
(
myImage
*
input
,
int
set_MOG_LearnFrame
,
int
set_min_area
,
int
set_buffer_len
,
float
set_resize
,
myImage
*
mask
);
CBM_model
(
myImage
*
input
,
int
set_MOG_LearnFrame
,
int
set_min_area
,
int
set_buffer_len
,
float
set_resize
,
myImage
*
mask
);
~
CBM_model
();
~
CBM_model
();
void
Initialize
();
void
Initialize
();
...
@@ -143,9 +143,9 @@ public:
...
@@ -143,9 +143,9 @@ public:
myImage
*
maskROI
;
myImage
*
maskROI
;
myImage
*
input_temp
;
myImage
*
input_temp
;
private
:
private
:
cv
::
Mat
mog_fg
;
//long term
//
cv::Mat mog_fg;//long term
cv
::
Mat
mog_fg2
;
//short term
//
cv::Mat mog_fg2;//short term
cv
::
Mat
imgStatic
;
//
cv::Mat imgStatic;
myImage
*
my_mog_fg
;
//long term
myImage
*
my_mog_fg
;
//long term
...
...
CMakeLists.txt
View file @
e1126306
cmake_minimum_required
(
VERSION 2.8
)
cmake_minimum_required
(
VERSION 2.8
)
project
(
ObjLeft
)
project
(
ObjLeft
)
find_package
(
OpenCV
4.1.1
REQUIRED
)
find_package
(
OpenCV REQUIRED
)
link_directories
(
${
MYPROJECT_DIR
}
)
link_directories
(
${
MYPROJECT_DIR
}
)
...
...
DetectAnomaly.cpp
View file @
e1126306
...
@@ -28,13 +28,13 @@ double INPUT_RESIZE;
...
@@ -28,13 +28,13 @@ double INPUT_RESIZE;
bool
DetectAnomaly
::
detectAnomaly
(
cv
::
Mat
img
,
vector
<
vector
<
int
>>*
resultLocation
)
bool
DetectAnomaly
::
detectAnomaly
(
cv
::
Mat
img
,
vector
<
vector
<
int
>>*
resultLocation
)
{
{
yolo_test
=
img
.
clone
();
cv
::
Rect
rect
(
0
,
610
,
2400
,
910
);
cv
::
Rect
rect
(
0
,
610
,
2400
,
910
);
img
=
img
(
rect
);
img
=
img
(
rect
);
cv
::
resize
(
img
,
img
,
cv
::
Size
(
2400
*
0.25
,
910
*
0.25
),
cv
::
INTER_CUBIC
);
cv
::
resize
(
img
,
img
,
cv
::
Size
(
2400
*
0.25
,
910
*
0.25
),
cv
::
INTER_CUBIC
);
img
.
copyTo
(
myimg
);
//img.copyTo(*myimg);
medianBlur
(
mat_myimg
,
mat_myimg
,
3
);
myimg
=
&
img
;
opencv_2_myImage
(
myimg
,
myimg1
);
//transfer opencv data to myimage data
medianBlur
(
*
mat_myimg
,
*
mat_myimg
,
3
);
opencv_2_myImage
(
*
myimg
,
myimg1
);
//transfer opencv data to myimage data
/************************************************************************/
/************************************************************************/
/* abandoned object detection algorithm */
/* abandoned object detection algorithm */
...
@@ -51,9 +51,9 @@ bool DetectAnomaly::detectAnomaly(config cfg, cv::Mat img, vector<vector<int>>*
...
@@ -51,9 +51,9 @@ bool DetectAnomaly::detectAnomaly(config cfg, cv::Mat img, vector<vector<int>>*
img
=
img
(
rect
);
img
=
img
(
rect
);
//cv::resize(img, img,cv::Size(2400*0.25, 910*0.25), cv::INTER_CUBIC);
//cv::resize(img, img,cv::Size(2400*0.25, 910*0.25), cv::INTER_CUBIC);
cv
::
resize
(
img
,
img
,
cv
::
Size
(
cfg
.
image_width
*
cfg
.
input_resize
,
cfg
.
image_height
*
cfg
.
input_resize
),
cv
::
INTER_CUBIC
);
cv
::
resize
(
img
,
img
,
cv
::
Size
(
cfg
.
image_width
*
cfg
.
input_resize
,
cfg
.
image_height
*
cfg
.
input_resize
),
cv
::
INTER_CUBIC
);
img
.
copyTo
(
myimg
)
;
myimg
=
&
img
;
medianBlur
(
mat_myimg
,
mat_myimg
,
3
);
medianBlur
(
*
mat_myimg
,
*
mat_myimg
,
3
);
opencv_2_myImage
(
myimg
,
myimg1
);
//transfer opencv data to myimage data
opencv_2_myImage
(
*
myimg
,
myimg1
);
//transfer opencv data to myimage data
/************************************************************************/
/************************************************************************/
/* abandoned object detection algorithm */
/* abandoned object detection algorithm */
...
@@ -142,8 +142,9 @@ DetectAnomaly::DetectAnomaly()
...
@@ -142,8 +142,9 @@ DetectAnomaly::DetectAnomaly()
mymask
=
myCreateImage
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
,
3
);
mymask
=
myCreateImage
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
,
3
);
myInverse
(
mymask
,
mymask
);
myInverse
(
mymask
,
mymask
);
myimg1
=
myCreateImage
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
,
3
);
myimg1
=
myCreateImage
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
,
3
);
myimg
=
cv
::
Mat
(
cv
::
Size
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
),
CV_8UC3
);
myimg
=
new
cv
::
Mat
(
cv
::
Size
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
),
CV_8UC3
);
myimg
.
copyTo
(
mat_myimg
);
//*myimg.copyTo(*mat_myimg);
mat_myimg
=
myimg
;
// mat_myimg(myimg, 0);
// mat_myimg(myimg, 0);
// set roi
// set roi
...
@@ -163,15 +164,15 @@ DetectAnomaly::DetectAnomaly()
...
@@ -163,15 +164,15 @@ DetectAnomaly::DetectAnomaly()
cv
::
polylines
(
Image1
,
PointArray
,
arr
,
1
,
true
,
cv
::
Scalar
(
255
,
255
,
255
),
5
,
8
,
0
);
cv
::
polylines
(
Image1
,
PointArray
,
arr
,
1
,
true
,
cv
::
Scalar
(
255
,
255
,
255
),
5
,
8
,
0
);
cv
::
fillPoly
(
Image1
,
ppt
,
arr
,
1
,
cv
::
Scalar
(
255
,
255
,
255
),
0
);
cv
::
fillPoly
(
Image1
,
ppt
,
arr
,
1
,
cv
::
Scalar
(
255
,
255
,
255
),
0
);
cv
::
threshold
(
Image1
,
Image1
,
254
,
255
,
THRESH_BINARY
);
cv
::
threshold
(
Image1
,
Image1
,
254
,
255
,
THRESH_BINARY
);
mask
=
Image1
.
clone
()
;
mask
=
&
Image1
;
opencv_2_myImage
(
mask
,
mymask
);
opencv_2_myImage
(
*
mask
,
mymask
);
#ifdef DEBUG
#ifdef DEBUG
//cv::imwrite("mask.jpg",
Image1
);
//cv::imwrite("mask.jpg",
*mask
);
cv
::
waitKey
(
1
);
//
cv::waitKey(1);
//cvReleaseImage(&Image1);
//cvReleaseImage(&Image1);
#endif
#endif
_objleft
.
ObjLeftSet
(
myimg1
,
cfgAnomaly
.
gmm_learn_frame
,
cfgAnomaly
.
min_fg
,
cfgAnomaly
.
buffer_length
,
mymask
);
_objleft
.
ObjLeftSet
(
myimg1
,
cfgAnomaly
.
gmm_learn_frame
,
cfgAnomaly
.
min_fg
,
cfgAnomaly
.
buffer_length
,
mymask
,
mask
);
#ifdef DEBUG
#ifdef DEBUG
printf
(
"Finished initialization.
\n
"
);
printf
(
"Finished initialization.
\n
"
);
#endif
#endif
...
@@ -220,8 +221,9 @@ DetectAnomaly::DetectAnomaly(config cfg) : cfgAnomaly(cfg)
...
@@ -220,8 +221,9 @@ DetectAnomaly::DetectAnomaly(config cfg) : cfgAnomaly(cfg)
mymask
=
myCreateImage
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
,
3
);
mymask
=
myCreateImage
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
,
3
);
myInverse
(
mymask
,
mymask
);
myInverse
(
mymask
,
mymask
);
myimg1
=
myCreateImage
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
,
3
);
myimg1
=
myCreateImage
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
,
3
);
myimg
=
cv
::
Mat
(
cv
::
Size
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
),
CV_8UC3
);
myimg
=
new
cv
::
Mat
(
cv
::
Size
(
cfgAnomaly
.
image_width
,
cfgAnomaly
.
image_height
),
CV_8UC3
);
myimg
.
copyTo
(
mat_myimg
);
//myimg.copyTo(mat_myimg);
mat_myimg
=
myimg
;
// mat_myimg(myimg, 0);
// mat_myimg(myimg, 0);
// set roi
// set roi
...
@@ -251,15 +253,15 @@ DetectAnomaly::DetectAnomaly(config cfg) : cfgAnomaly(cfg)
...
@@ -251,15 +253,15 @@ DetectAnomaly::DetectAnomaly(config cfg) : cfgAnomaly(cfg)
cv
::
polylines
(
Image1
,
PointArray
,
arr
,
1
,
true
,
cv
::
Scalar
(
255
,
255
,
255
),
5
,
8
,
0
);
cv
::
polylines
(
Image1
,
PointArray
,
arr
,
1
,
true
,
cv
::
Scalar
(
255
,
255
,
255
),
5
,
8
,
0
);
cv
::
fillPoly
(
Image1
,
ppt
,
arr
,
1
,
cv
::
Scalar
(
255
,
255
,
255
),
0
);
cv
::
fillPoly
(
Image1
,
ppt
,
arr
,
1
,
cv
::
Scalar
(
255
,
255
,
255
),
0
);
cv
::
threshold
(
Image1
,
Image1
,
254
,
255
,
THRESH_BINARY
);
cv
::
threshold
(
Image1
,
Image1
,
254
,
255
,
THRESH_BINARY
);
mask
=
Image1
.
clone
()
;
mask
=
&
Image1
;
opencv_2_myImage
(
mask
,
mymask
);
opencv_2_myImage
(
*
mask
,
mymask
);
#ifdef DEBUG
#ifdef DEBUG
//
cv::imwrite("mask.jpg", Image1);
cv
::
imwrite
(
"mask.jpg"
,
Image1
);
cv
::
waitKey
(
1
);
//
cv::waitKey(1);
//cvReleaseImage(&Image1);
//cvReleaseImage(&Image1);
#endif
#endif
_objleft
.
ObjLeftSet
(
myimg1
,
cfgAnomaly
.
gmm_learn_frame
,
cfgAnomaly
.
min_fg
,
cfgAnomaly
.
buffer_length
,
mymask
);
_objleft
.
ObjLeftSet
(
myimg1
,
cfgAnomaly
.
gmm_learn_frame
,
cfgAnomaly
.
min_fg
,
cfgAnomaly
.
buffer_length
,
mymask
,
mask
);
#ifdef DEBUG
#ifdef DEBUG
printf
(
"Finished initialization.
\n
"
);
printf
(
"Finished initialization.
\n
"
);
#endif
#endif
...
...
DetectAnomaly.h
View file @
e1126306
...
@@ -44,13 +44,13 @@ private:
...
@@ -44,13 +44,13 @@ private:
cv
::
Point
PointArray1
[
4
];
cv
::
Point
PointArray1
[
4
];
cv
::
Point
*
PointArray
[
2
]
=
{
&
PointArray1
[
0
],
&
PointArray1
[
2
]};
cv
::
Point
*
PointArray
[
2
]
=
{
&
PointArray1
[
0
],
&
PointArray1
[
2
]};
cv
::
Mat
mask
;
cv
::
Mat
*
mask
;
myImage
*
mymask
;
myImage
*
mymask
;
cv
::
Mat
myimg
;
cv
::
Mat
*
myimg
;
myImage
*
myimg1
;
myImage
*
myimg1
;
cv
::
Mat
mat_myimg
;
cv
::
Mat
*
mat_myimg
;
ObjLeftDetect
_objleft
;
ObjLeftDetect
_objleft
;
bool
obj_left
;
bool
obj_left
;
...
@@ -63,7 +63,6 @@ public:
...
@@ -63,7 +63,6 @@ public:
DetectAnomaly
();
DetectAnomaly
();
DetectAnomaly
(
config
cfg
);
DetectAnomaly
(
config
cfg
);
cv
::
Mat
yolo_test
;
~
DetectAnomaly
();
~
DetectAnomaly
();
};
};
...
...
ObjLeftDetect.cpp
View file @
e1126306
...
@@ -22,34 +22,36 @@ ObjLeftDetect::ObjLeftDetect()
...
@@ -22,34 +22,36 @@ ObjLeftDetect::ObjLeftDetect()
{
{
}
}
void
ObjLeftDetect
::
ObjLeftSet
(
myImage
*
input
,
int
set_MOG_LearnFrame
,
int
set_min_area
,
int
set_buffer_len
,
myImage
*
mask
)
void
ObjLeftDetect
::
ObjLeftSet
(
myImage
*
input
,
int
set_MOG_LearnFrame
,
int
set_min_area
,
int
set_buffer_len
,
myImage
*
mask
,
cv
::
Mat
*
cvmask
)
{
{
_CBM_model
=
new
CBM_model
(
input
,
set_MOG_LearnFrame
,
set_min_area
,
set_buffer_len
,
INPUT_RESIZE
,
mask
);
_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_width
=
(
int
)(
input
->
width
*
INPUT_RESIZE
);
new_height
=
(
int
)(
input
->
height
*
INPUT_RESIZE
);
new_height
=
(
int
)(
input
->
height
*
INPUT_RESIZE
);
objmask
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC1
);
myImage_2_opencv
(
mask
,
objmask
);
//objmask = new cv::Mat(cv::Size(new_width,new_height),CV_8UC1);
cv
::
findContours
(
objmask
,
contours
,
cv
::
noArray
(),
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_SIMPLE
);
//myImage_2_opencv(mask, *objmask);
//cv::imwrite("mask2.jpg",*cvmask);
cv
::
findContours
(
*
cvmask
,
contours
,
cv
::
noArray
(),
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_SIMPLE
);
if
(
contours
.
size
()
>
0
)
if
(
contours
.
size
()
>
0
)
{
{
for
(
size_t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
if
(
cv
::
contourArea
(
contours
[
i
])
<
10000
)
{
{
contours
.
erase
(
contours
.
begin
()
+
i
);
if
(
cv
::
contourArea
(
contours
[
i
])
<
10000
)
i
--
;
{
}
contours
.
erase
(
contours
.
begin
()
+
i
);
i
--
;
}
}
}
}
}
cv
::
Mat
showpic
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC1
);
//
cv::Mat showpic = cv::Mat::zeros(cv::Size(new_width,new_height),CV_8UC1);
drawContours
(
showpic
,
contours
,
0
,
Scalar
::
all
(
255
));
//
drawContours(showpic, contours, 0, Scalar::all(255));
//cv::imwrite("show.jpg",showpic);
//cv::imwrite("show.jpg",showpic);
// new_width = (int)(input->width);
// new_width = (int)(input->width);
// new_height = (int)(input->height);
// new_height = (int)(input->height);
//
std::cout << "contours size : " << contours.size() << " "<< contours[0].size() <<std::endl;
//std::cout << "contours size : " << contours.size() << " "<< contours[0].size() <<std::endl;
// new_width = (int)(input->width);
// new_width = (int)(input->width);
// new_height = (int)(input->height);
// new_height = (int)(input->height);
initialize
();
initialize
();
...
@@ -77,11 +79,11 @@ void ObjLeftDetect::initialize()
...
@@ -77,11 +79,11 @@ void ObjLeftDetect::initialize()
ObjLocation
.
clear
();
ObjLocation
.
clear
();
LeftLocation
.
clear
();
LeftLocation
.
clear
();
myimg2
=
myCreateImage
(
new_width
,
new_height
,
3
);
//
myimg2 = myCreateImage(new_width,new_height,3);
_ImgSynopsis
=
myCreateImage
(
new_width
,
new_height
,
3
);
//
_ImgSynopsis = myCreateImage(new_width,new_height,3);
A
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC3
);
//
A = cv::Mat::zeros(cv::Size(new_width,new_height),CV_8UC3);
B
=
cv
::
Mat
::
zeros
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC3
);
//
B = cv::Mat::zeros(cv::Size(new_width,new_height),CV_8UC3);
...
@@ -167,25 +169,25 @@ bool ObjLeftDetect::process(myImage * input, vector<vector<int>>* resultLocation
...
@@ -167,25 +169,25 @@ bool ObjLeftDetect::process(myImage * input, vector<vector<int>>* resultLocation
}
}
myImageZero
(
_ImgSynopsis
);
//
myImageZero(_ImgSynopsis);
for
(
int
i
=
0
;
i
<
_ImgSynopsis
->
width
;
i
++
)
//
for (int i = 0; i < _ImgSynopsis->width; i++)
{
//
{
for
(
int
j
=
0
;
j
<
_ImgSynopsis
->
height
;
j
++
)
//
for (int j = 0; j < _ImgSynopsis->height; j++)
{
//
{
myColor
aaa
=
myGet2D
(
_CBM_model
->
my_imgStatic
,
i
,
j
);
//
myColor aaa = myGet2D(_CBM_model->my_imgStatic,i,j);
myColor
bbb
;
bbb
.
B
=
200
;
bbb
.
G
=
250
;
bbb
.
R
=
10
;
//
myColor bbb; bbb.B = 200; bbb.G = 250; bbb.R = 10;
if
((
aaa
.
B
==
0
)
&&
(
aaa
.
G
==
200
)
&&
(
aaa
.
R
==
255
))
//
if ((aaa.B==0)&&(aaa.G==200)&&(aaa.R==255))
{
//
{
mySet2D
(
_ImgSynopsis
,
bbb
,
i
,
j
);
//
mySet2D(_ImgSynopsis,bbb,i,j);
}
//
}
}
//
}
}
//
}
myImage_2_opencv
(
_ImgSynopsis
,
test
);
//
myImage_2_opencv(_ImgSynopsis,test);
// cvShowImage("summary",test);
//
//
cvShowImage("summary",test);
cv
::
waitKey
(
1
);
//
cv::waitKey(1);
test
.
copyTo
(
A
);
//
test.copyTo(A);
myImageZero
(
_ImgSynopsis
);
//
myImageZero(_ImgSynopsis);
// set_alarm = soft_validation3( _ImgSynopsis, LeftLocation);
// set_alarm = soft_validation3( _ImgSynopsis, LeftLocation);
if
(
resultLocation
!=
nullptr
){
if
(
resultLocation
!=
nullptr
){
if
(
resultLocation
->
size
()
>
0
){
if
(
resultLocation
->
size
()
>
0
){
...
@@ -212,367 +214,367 @@ bool ObjLeftDetect::process(myImage * input, vector<vector<int>>* resultLocation
...
@@ -212,367 +214,367 @@ bool ObjLeftDetect::process(myImage * input, vector<vector<int>>* resultLocation
}
}
bool
ObjLeftDetect
::
soft_validation3
(
myImage
*
ImgSynopsis
,
vector
<
Obj_info
*>
obj_left
)
// bool ObjLeftDetect::soft_validation3( myImage * ImgSynopsis, vector<Obj_info*> obj_left)
{
// {
bool
_set_alarm
=
false
;
// bool _set_alarm = false;
bool
**
foreground
;
// bool ** foreground;
int
temporal_rule
=
BUFFER_LENGTH
;
// int temporal_rule = BUFFER_LENGTH;
int
retreval_time
=
temporal_rule
/
2
+
temporal_rule
/
6
;
// int retreval_time = temporal_rule/2 + temporal_rule/6;
bool
**
ForeSynopsis
;
// bool ** ForeSynopsis;
ForeSynopsis
=
(
bool
**
)
malloc
(
new_width
*
sizeof
(
bool
*
));
// ForeSynopsis = (bool **)malloc(new_width*sizeof(bool *));
for
(
int
i
=
0
;
i
<
new_width
;
i
++
){
// for (int i = 0; i < new_width; i++){
ForeSynopsis
[
i
]
=
(
bool
*
)
malloc
(
new_height
*
sizeof
(
bool
));
// ForeSynopsis[i] = (bool *)malloc(new_height*sizeof(bool));
}
// }
for
(
int
i
=
0
;
i
<
new_width
;
i
++
){
// for (int i = 0; i < new_width; i++){
for
(
int
j
=
0
;
j
<
new_height
;
j
++
){
// for (int j = 0; j < new_height; j++){
ForeSynopsis
[
i
][
j
]
=
false
;
// ForeSynopsis[i][j] = false;
}
// }
}
// }
int
**
floodfillMap
;
floodfillMap
=
(
int
**
)
malloc
(
new_width
*
sizeof
(
int
*
));
for
(
int
i
=
0
;
i
<
new_width
;
i
++
){
floodfillMap
[
i
]
=
(
int
*
)
malloc
(
new_height
*
sizeof
(
int
));
}
for
(
int
i
=
0
;
i
<
new_width
;
i
++
){
for
(
int
j
=
0
;
j
<
new_height
;
j
++
){
floodfillMap
[
i
][
j
]
=
0
;
}
}
/************************************************************************/
/* capture the color information of the suspected owner */
/************************************************************************/
foreground
=
_CBM_model
->
GetPrevious_nForeground
(
retreval_time
-
1
);
//the moment the bag dropped (need to check!!)
bool
foreground_found
=
false
;
#pragma omp parallel for num_threads(12)
for
(
int
j
=
0
;
j
<
new_width
;
j
++
)
{
for
(
int
k
=
0
;
k
<
new_height
;
k
++
)
{
if
(
foreground
[
j
][
k
]
==
true
)
{
for
(
int
n
=
0
;
n
<
obj_left
.
size
();
n
++
)
{
float
owner_dist
=
point_dist
(
(
float
)
j
,
(
float
)
k
,
(
float
)
obj_left
.
at
(
n
)
->
x
,
(
float
)
obj_left
.
at
(
n
)
->
y
);
if
(
owner_dist
<
OWNER_SEARCH_ROI
)
//distance threshold
{
for
(
int
w
=
-
30
;
w
<
30
;
w
++
)
{
//rgb histogram accumulated
myColor
color
;
color
=
myGet2D
(
_CBM_model
->
_GetPrevious_nFrame
(
retreval_time
-
1
),
j
,
k
);
//printf("get color: r = %lf, g = %lf, b = %lf\n",(float)color.R,(float)color.G, (float)color.B);
obj_left
.
at
(
n
)
->
Owner_B
[(
int
)((
float
)
color
.
B
/
255.0
*
10.0
)]
+=
1.0
;
obj_left
.
at
(
n
)
->
Owner_G
[(
int
)((
float
)
color
.
G
/
255.0
*
10.0
)]
+=
1.0
;
obj_left
.
at
(
n
)
->
Owner_R
[(
int
)((
float
)
color
.
R
/
255.0
*
10.0
)]
+=
1.0
;
}
foreground_found
=
true
;
}
}
}
}
}
//if there is no foreground found near to the suspected left object, that is, we have a false alarm of object left detection
//than return nothing!
if
(
foreground_found
==
false
)
return
false
;
//else if we found foregournd object, it must be the owner, than we extract the color information of further processing
// int ** floodfillMap;
// floodfillMap = (int **)malloc(new_width*sizeof(int *));
// for (int i = 0; i < new_width; i++){
// floodfillMap[i] = (int *)malloc(new_height*sizeof(int));
// }
// for (int i = 0; i < new_width; i++){
// for (int j = 0; j < new_height; j++){
// floodfillMap[i][j] = 0;
// }
// }
myFloatColor
**
obj_colors
;
obj_colors
=
(
myFloatColor
**
)
malloc
(
obj_left
.
size
()
*
sizeof
(
myFloatColor
*
));
for
(
int
i
=
0
;
i
<
obj_left
.
size
();
i
++
)
obj_colors
[
i
]
=
(
myFloatColor
*
)
malloc
(
10
*
sizeof
(
myFloatColor
));
for
(
int
i
=
0
;
i
<
obj_left
.
size
();
i
++
)
// /************************************************************************/
{
// /* capture the color information of the suspected owner */
//normalizing the histogram accumulated information
// /************************************************************************/
double
total_r
=
0.0
,
total_g
=
0.0
,
total_b
=
0.0
;
// foreground = _CBM_model->GetPrevious_nForeground(retreval_time-1);//the moment the bag dropped (need to check!!)
for
(
int
j
=
0
;
j
<
10
;
j
++
)
// bool foreground_found = false;
{
// #pragma omp parallel for num_threads(12)
total_r
=
total_r
+
obj_left
.
at
(
i
)
->
Owner_R
[
j
];
// for (int j = 0; j < new_width; j++)
total_g
=
total_g
+
obj_left
.
at
(
i
)
->
Owner_G
[
j
];
// {
total_b
=
total_b
+
obj_left
.
at
(
i
)
->
Owner_B
[
j
];
// for (int k = 0; k < new_height; k++)
}
// {
for
(
int
j
=
0
;
j
<
10
;
j
++
)
// if (foreground[j][k] == true)
{
// {
obj_left
.
at
(
i
)
->
Owner_R
[
j
]
=
(
obj_left
.
at
(
i
)
->
Owner_R
[
j
]
/
(
total_r
+
0.001
));
// for (int n = 0; n < obj_left.size(); n++)
obj_left
.
at
(
i
)
->
Owner_G
[
j
]
=
(
obj_left
.
at
(
i
)
->
Owner_G
[
j
]
/
(
total_g
+
0.001
));
// {
obj_left
.
at
(
i
)
->
Owner_B
[
j
]
=
(
obj_left
.
at
(
i
)
->
Owner_B
[
j
]
/
(
total_b
+
0.001
));
// float owner_dist = point_dist( (float)j, (float)k, (float)obj_left.at(n)->x, (float)obj_left.at(n)->y);
// if (owner_dist<OWNER_SEARCH_ROI)//distance threshold
// {
// for (int w = -30; w < 30; w++)
// {
// //rgb histogram accumulated
// myColor color;
// color = myGet2D( _CBM_model->_GetPrevious_nFrame(retreval_time-1), j, k);
// //printf("get color: r = %lf, g = %lf, b = %lf\n",(float)color.R,(float)color.G, (float)color.B);
// obj_left.at(n)->Owner_B[(int)((float)color.B/255.0*10.0)] += 1.0;
// obj_left.at(n)->Owner_G[(int)((float)color.G/255.0*10.0)] += 1.0;
// obj_left.at(n)->Owner_R[(int)((float)color.R/255.0*10.0)] += 1.0;
// }
// foreground_found = true;
// }
// }
// }
// }
// }
obj_colors
[
i
][
j
].
R
=
obj_left
.
at
(
i
)
->
Owner_R
[
j
];
// //if there is no foreground found near to the suspected left object, that is, we have a false alarm of object left detection
obj_colors
[
i
][
j
].
G
=
obj_left
.
at
(
i
)
->
Owner_G
[
j
];
// //than return nothing!
obj_colors
[
i
][
j
].
B
=
obj_left
.
at
(
i
)
->
Owner_B
[
j
];
// if (foreground_found==false)
}
// return false;
}
// //else if we found foregournd object, it must be the owner, than we extract the color information of further processing
// myFloatColor ** obj_colors;
// obj_colors = (myFloatColor **)malloc(obj_left.size()*sizeof(myFloatColor *));
// for (int i = 0; i < obj_left.size(); i++)
// obj_colors[i] = (myFloatColor *)malloc(10*sizeof(myFloatColor));
// for (int i = 0; i < obj_left.size(); i++)
// {
// //normalizing the histogram accumulated information
// double total_r = 0.0, total_g = 0.0, total_b = 0.0;
// for (int j = 0; j < 10; j++)
// {
// total_r = total_r + obj_left.at(i)->Owner_R[j];
// total_g = total_g + obj_left.at(i)->Owner_G[j];
// total_b = total_b + obj_left.at(i)->Owner_B[j];
// }
// for (int j = 0; j < 10; j++)
// {
// obj_left.at(i)->Owner_R[j] = (obj_left.at(i)->Owner_R[j]/(total_r+0.001));
// obj_left.at(i)->Owner_G[j] = (obj_left.at(i)->Owner_G[j]/(total_g+0.001));
// obj_left.at(i)->Owner_B[j] = (obj_left.at(i)->Owner_B[j]/(total_b+0.001));
// obj_colors[i][j].R = obj_left.at(i)->Owner_R[j];
// obj_colors[i][j].G = obj_left.at(i)->Owner_G[j];
// obj_colors[i][j].B = obj_left.at(i)->Owner_B[j];
// }
// }
/************************************************************************/
//
/************************************************************************/
/* generate the synopsis image */
//
/* generate the synopsis image */
/************************************************************************/
//
/************************************************************************/
//SYSTEMTIME s;
//
//SYSTEMTIME s;
//GetSystemTime(&s);
//
//GetSystemTime(&s);
for
(
int
i
=
1
;
i
<
retreval_time
;
i
=
i
+
1
)
//���e���Oi=i+3
//
for (int i = 1; i < retreval_time; i=i+1)//���e���Oi=i+3
{
//
{
cv
::
Mat
img
=
cv
::
Mat
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC3
);
//
cv::Mat img = cv::Mat(cv::Size(new_width,new_height),CV_8UC3);
cv
::
Mat
fg
=
cv
::
Mat
(
cv
::
Size
(
new_width
,
new_height
),
CV_8UC1
);
//
cv::Mat fg = cv::Mat(cv::Size(new_width,new_height),CV_8UC1);
foreground
=
_CBM_model
->
GetPrevious_nForeground
(
i
);
//
foreground = _CBM_model->GetPrevious_nForeground(i);
#pragma omp parallel for num_threads(12)
//
#pragma omp parallel for num_threads(12)
for
(
int
j
=
0
;
j
<
new_width
;
j
++
)
//
for (int j = 0; j < new_width; j++)
{
//
{
for
(
int
k
=
0
;
k
<
new_height
;
k
++
)
//
for (int k = 0; k < new_height; k++)
{
//
{
if
(
foreground
[
j
][
k
]
==
true
)
//
if (foreground[j][k] == true)
{
//
{
myColor
color
;
//
myColor color;
color
=
myGet2D
(
_CBM_model
->
_GetPrevious_nFrame
(
i
),
j
,
k
);
//
color = myGet2D( _CBM_model->_GetPrevious_nFrame(i), j, k);
mySet2D
(
ImgSynopsis
,
color
,
j
,
k
);
//
mySet2D(ImgSynopsis,color,j,k);
ForeSynopsis
[
j
][
k
]
=
true
;
//
ForeSynopsis[j][k] = true;
cv
::
Scalar
ppp
;
//
cv::Scalar ppp;
ppp
.
val
[
0
]
=
color
.
B
;
ppp
.
val
[
1
]
=
color
.
G
;
ppp
.
val
[
2
]
=
color
.
R
;
//
ppp.val[0] = color.B; ppp.val[1] = color.G; ppp.val[2] = color.R;
Set2D
(
img
,
k
,
j
,
ppp
);
//
Set2D(img,k,j,ppp);
cv
::
Scalar
aaa
;
//
cv::Scalar aaa;
aaa
.
val
[
0
]
=
aaa
.
val
[
1
]
=
aaa
.
val
[
2
]
=
255
;
//
aaa.val[0] = aaa.val[1] = aaa.val[2] = 255;
Set2D
(
fg
,
k
,
j
,
aaa
);
//
Set2D(fg,k,j,aaa);
}
//
}
else
//
else
{
//
{
cv
::
Scalar
ppp
;
//
cv::Scalar ppp;
ppp
.
val
[
0
]
=
ppp
.
val
[
1
]
=
ppp
.
val
[
2
]
=
0
;
//
ppp.val[0] = ppp.val[1] = ppp.val[2] = 0;
Set2D
(
img
,
k
,
j
,
ppp
);
//
Set2D(img,k,j,ppp);
cv
::
Scalar
aaa
;
//
cv::Scalar aaa;
aaa
.
val
[
0
]
=
aaa
.
val
[
1
]
=
aaa
.
val
[
2
]
=
0
;
//
aaa.val[0] = aaa.val[1] = aaa.val[2] = 0;
Set2D
(
fg
,
k
,
j
,
aaa
);
//
Set2D(fg,k,j,aaa);
}
//
}
}
//
}
}
//
}
//char a[50], b[50];
//
//char a[50], b[50];
//sprintf(a,"temp\\mask%d%d%d%d%d%d_%d.bmp",s.wYear,s.wMonth,s.wDay,s.wHour,s.wMinute,s.wMilliseconds,i);
//
//sprintf(a,"temp\\mask%d%d%d%d%d%d_%d.bmp",s.wYear,s.wMonth,s.wDay,s.wHour,s.wMinute,s.wMilliseconds,i);
//sprintf(b,"temp\\image%d%d%d%d%d%d_%d.bmp",s.wYear,s.wMonth,s.wDay,s.wHour,s.wMinute,s.wMilliseconds,i);
//
//sprintf(b,"temp\\image%d%d%d%d%d%d_%d.bmp",s.wYear,s.wMonth,s.wDay,s.wHour,s.wMinute,s.wMilliseconds,i);
//cvSaveImage(a,fg);
//
//cvSaveImage(a,fg);
//cvSaveImage(b,img);
//
//cvSaveImage(b,img);
//cvReleaseImage(&img);
//
//cvReleaseImage(&img);
//cvReleaseImage(&fg);
//
//cvReleaseImage(&fg);
}
//
}
cv
::
Mat
temp
=
cv
::
Mat
(
cv
::
Size
(
ImgSynopsis
->
width
,
ImgSynopsis
->
height
),
CV_8UC3
);
//
cv::Mat temp = cv::Mat(cv::Size(ImgSynopsis->width,ImgSynopsis->height),CV_8UC3);
myImage_2_opencv
(
ImgSynopsis
,
temp
);
//
myImage_2_opencv(ImgSynopsis,temp);
// cvShowImage("synopsis",temp);
//
// cvShowImage("synopsis",temp);
//cvReleaseImage(&temp);
//
//cvReleaseImage(&temp);
//cvZero(B);
//
//cvZero(B);
/************************************************************************/
//
/************************************************************************/
/* Pedestrian detector */
//
/* Pedestrian detector */
/************************************************************************/
//
/************************************************************************/
for
(
int
t
=
(
retreval_time
-
1
);
t
>=
2
;
t
--
)
//
for (int t = (retreval_time-1); t>=2; t--)
{
//
{
//_CBM_model->DetectPrevious_nForeground_HOG(t);
//
//_CBM_model->DetectPrevious_nForeground_HOG(t);
//_CBM_model->DetectPrevious_nForeground_DPM(t);
//
//_CBM_model->DetectPrevious_nForeground_DPM(t);
}
//
}
/************************************************************************/
//
/************************************************************************/
/* use mounatin climbing algorithm to extract the candidate trajectory */
//
/* use mounatin climbing algorithm to extract the candidate trajectory */
/************************************************************************/
//
/************************************************************************/
for
(
int
n
=
0
;
n
<
obj_left
.
size
();
n
++
)
//
for (int n = 0; n < obj_left.size(); n++)
{
//
{
int
_t_time
=
retreval_time
-
1
;
//
int _t_time = retreval_time-1;
obj_left
.
at
(
n
)
->
traj_label
=
n
+
1
;
//
obj_left.at(n)->traj_label = n+1;
for
(
int
i
=
-
OWNER_SEARCH_ROI
/
2
;
i
<
OWNER_SEARCH_ROI
/
2
+
1
;
i
++
)
//
for (int i = -OWNER_SEARCH_ROI/2; i < OWNER_SEARCH_ROI/2+1; i++)
{
//
{
for
(
int
j
=
-
OWNER_SEARCH_ROI
/
2
;
j
<
OWNER_SEARCH_ROI
/
2
+
1
;
j
++
)
//
for (int j = -OWNER_SEARCH_ROI/2; j < OWNER_SEARCH_ROI/2+1; j++)
{
//
{
Spatial_Temporal_Search
(
floodfillMap
,
obj_left
.
at
(
n
)
->
x
+
i
,
obj_left
.
at
(
n
)
->
y
+
j
,
obj_colors
[
n
],
_t_time
,
n
+
1
);
//
Spatial_Temporal_Search(floodfillMap,obj_left.at(n)->x + i, obj_left.at(n)->y + j, obj_colors[n], _t_time, n+1);
}
//
}
}
//
}
}
//
}
/************************************************************************/
//
/************************************************************************/
/* Verifing the object left event by distance information */
//
/* Verifing the object left event by distance information */
/************************************************************************/
//
/************************************************************************/
cv
::
Mat
temp2
=
cv
::
Mat
(
cv
::
Size
(
ImgSynopsis
->
width
,
ImgSynopsis
->
height
),
CV_8UC3
);
//
cv::Mat temp2 = cv::Mat(cv::Size(ImgSynopsis->width,ImgSynopsis->height),CV_8UC3);
//myImage_2_opencv(ImgSynopsis,temp2);
//
//myImage_2_opencv(ImgSynopsis,temp2);
B
.
copyTo
(
temp2
);
//
B.copyTo(temp2);
for
(
int
n
=
0
;
n
<
obj_left
.
size
();
n
++
){
//
for (int n = 0; n < obj_left.size(); n++){
bool
inside
=
false
,
outside
=
false
;
//
bool inside = false, outside = false;
int
inside_count
=
0
,
outside_count
=
0
;
//
int inside_count = 0, outside_count = 0;
for
(
int
i
=
0
;
i
<
new_width
;
i
++
){
//
for (int i = 0; i < new_width; i++){
for
(
int
j
=
0
;
j
<
new_height
;
j
++
){
//
for (int j = 0; j < new_height; j++){
//if (floodfillMap[i][j] == obj_left.at(n)->traj_label){
//
//if (floodfillMap[i][j] == obj_left.at(n)->traj_label){
if
(
floodfillMap
[
i
][
j
]
==
(
n
+
1
)){
//
if (floodfillMap[i][j] == (n+1)){
float
dist
=
point_dist
(
(
float
)
i
,
(
float
)
j
,
(
float
)
obj_left
.
at
(
n
)
->
x
,
(
float
)
obj_left
.
at
(
n
)
->
y
);
//
float dist = point_dist( (float)i, (float)j, (float)obj_left.at(n)->x, (float)obj_left.at(n)->y);
if
(
dist
>
OWNER_SEARCH_ROI
/
2
){
// if (dist>OWNER_SEARCH_ROI/2){
inside_count
++
;
// inside_count++;
//outside = true;
// //outside = true;
//printf("outside dist = %lf, i = %d, j = %d, objx = %d, objy = %d\n",dist,i,j,obj_left.at(n)->x,obj_left.at(n)->y);
// //printf("outside dist = %lf, i = %d, j = %d, objx = %d, objy = %d\n",dist,i,j,obj_left.at(n)->x,obj_left.at(n)->y);
}
// }
else
if
(
dist
<
OWNER_SEARCH_ROI
/
2
){
// else if (dist<OWNER_SEARCH_ROI/2){
outside_count
++
;
// outside_count++;
//inside = true;
// //inside = true;
//printf("inside dist = %lf, i = %d, j = %d, objx = %d, objy = %d\n",dist,i,j,obj_left.at(n)->x,obj_left.at(n)->y);
// //printf("inside dist = %lf, i = %d, j = %d, objx = %d, objy = %d\n",dist,i,j,obj_left.at(n)->x,obj_left.at(n)->y);
}
// }
}
// }
}
// }
}
// }
if
(
inside_count
>
OWNER_SEARCH_ROI
)
inside
=
true
;
// if (inside_count>OWNER_SEARCH_ROI) inside = true;
if
(
outside_count
>
OWNER_SEARCH_ROI
)
outside
=
true
;
// if (outside_count>OWNER_SEARCH_ROI) outside = true;
if
((
inside
==
true
)
&&
(
outside
==
true
)){
// if ((inside==true)&&(outside==true)){
printf
(
"
\a
"
);
// printf("\a");
printf
(
"
\a
"
);
// printf("\a");
_set_alarm
=
true
;
// _set_alarm = true;
//cvCircle( temp2, cvPoint(obj_left.at(n)->x,obj_left.at(n)->y), OWNER_SEARCH_ROI/3, cv::Scalar(0,255,255),2,8,0);
// //cvCircle( temp2, cvPoint(obj_left.at(n)->x,obj_left.at(n)->y), OWNER_SEARCH_ROI/3, cv::Scalar(0,255,255),2,8,0);
}
// }
}
// }
// cvShowImage("synopsis",temp2);
// // cvShowImage("synopsis",temp2);
temp2
.
copyTo
(
B
);
// temp2.copyTo(B);
cv
::
waitKey
(
1
);
// cv::waitKey(1);
//cvReleaseImage(&temp2);
// //cvReleaseImage(&temp2);
free
(
*
ForeSynopsis
);
free
(
ForeSynopsis
);
free
(
*
floodfillMap
);
free
(
floodfillMap
);
free
(
*
obj_colors
);
free
(
obj_colors
);
return
_set_alarm
;
}
int
ObjLeftDetect
::
Spatial_Temporal_Search
(
int
**
Image
,
int
i
,
int
j
,
myFloatColor
*
colors
,
int
time_stamp
,
int
my_label
)
{
if
((
j
<
0
)
||
(
j
>=
new_height
-
1
))
return
0
;
if
((
i
<
0
)
||
(
i
>=
new_width
-
1
))
return
0
;
if
(
Image
[
i
][
j
]
==
my_label
)
return
0
;
int
object_x
=
i
;
int
object_y
=
j
;
bool
**
foreground
;
for
(
int
t
=
time_stamp
;
t
>=
2
;
t
--
)
{
foreground
=
_CBM_model
->
GetPrevious_nForeground
(
t
);
//foreground = _CBM_model->GetPrevious_nForeground_DPM(t);
//foreground = _CBM_model->GetPrevious_nForeground_HOG(t);
if
(
foreground
[
object_x
][
object_y
]
==
true
)
{
for
(
int
k
=
0
;
k
<
new_width
;
k
++
)
for
(
int
l
=
0
;
l
<
new_height
;
l
++
)
image
[
k
][
l
]
=
0
;
spatial_flood
(
foreground
,
object_x
,
object_y
);
for
(
int
k
=
0
;
k
<
10
;
k
++
)
{
connect_colors
[
k
].
B
=
0.0
;
connect_colors
[
k
].
G
=
0.0
;
connect_colors
[
k
].
R
=
0.0
;
}
int
min_x
=
new_width
,
max_x
=
0
;
int
min_y
=
new_height
,
max_y
=
0
;
for
(
int
k
=
0
;
k
<
new_width
;
k
++
)
{
for
(
int
l
=
0
;
l
<
new_height
;
l
++
)
{
if
(
image
[
k
][
l
]
==
1
)
{
myColor
color_temp
;
color_temp
=
myGet2D
(
_CBM_model
->
_GetPrevious_nFrame
(
t
),
k
,
l
);
connect_colors
[(
int
)((
double
)
color_temp
.
R
/
255.0
*
10.0
)].
R
+=
1.0
;
connect_colors
[(
int
)((
double
)
color_temp
.
G
/
255.0
*
10.0
)].
G
+=
1.0
;
connect_colors
[(
int
)((
double
)
color_temp
.
B
/
255.0
*
10.0
)].
B
+=
1.0
;
if
(
min_x
>
k
)
min_x
=
k
;
// free(*ForeSynopsis);
if
(
max_x
<
k
)
max_x
=
k
;
// free(ForeSynopsis);
// free(*floodfillMap);
// free(floodfillMap);
if
(
min_y
>
l
)
min_y
=
l
;
// free(*obj_colors)
;
if
(
max_y
<
l
)
max_y
=
l
;
// free(obj_colors)
;
}
// return _set_alarm;
}
// }
}
object_x
=
min_x
+
(
max_x
-
min_x
)
/
2
;
// int ObjLeftDetect::Spatial_Temporal_Search( int ** Image, int i, int j, myFloatColor * colors, int time_stamp,int my_label)
object_y
=
min_y
+
(
max_y
-
min_y
)
/
2
;
// {
// if ((j < 0) || (j >= new_height-1)) return 0;
// if ((i < 0) || (i >= new_width-1)) return 0;
// if(Image[i][j] == my_label) return 0;
// int object_x = i;
// int object_y = j;
// bool ** foreground;
// for (int t = time_stamp; t>=2; t--)
// {
// foreground = _CBM_model->GetPrevious_nForeground(t);
// //foreground = _CBM_model->GetPrevious_nForeground_DPM(t);
// //foreground = _CBM_model->GetPrevious_nForeground_HOG(t);
// if (foreground[object_x][object_y] == true)
// {
// for (int k = 0; k < new_width; k++)
// for (int l = 0; l < new_height; l++)
// image[k][l] = 0;
// spatial_flood( foreground, object_x, object_y);
// for (int k = 0; k < 10; k++)
// {
// connect_colors[k].B = 0.0;
// connect_colors[k].G = 0.0;
// connect_colors[k].R = 0.0;
// }
// int min_x = new_width, max_x = 0;
// int min_y = new_height, max_y = 0;
// for (int k = 0; k < new_width; k++)
// {
// for (int l = 0; l < new_height; l++)
// {
// if (image[k][l] == 1)
// {
// myColor color_temp;
// color_temp = myGet2D( _CBM_model->_GetPrevious_nFrame(t), k, l);
// connect_colors[(int)((double)color_temp.R/255.0*10.0)].R+=1.0;
// connect_colors[(int)((double)color_temp.G/255.0*10.0)].G+=1.0;
// connect_colors[(int)((double)color_temp.B/255.0*10.0)].B+=1.0;
// if (min_x > k) min_x = k;
// if (max_x < k) max_x = k;
// if (min_y > l) min_y = l;
// if (max_y < l) max_y = l;
// }
// }
// }
// object_x = min_x + (max_x-min_x)/2;
// object_y = min_y + (max_y-min_y)/2;
//normalizing the histogram accumulated information
//
//normalizing the histogram accumulated information
double
total_r
=
0.0
,
total_g
=
0.0
,
total_b
=
0.0
;
//
double total_r = 0.0, total_g = 0.0, total_b = 0.0;
for
(
int
w
=
0
;
w
<
10
;
w
++
)
//
for (int w = 0; w < 10; w++)
{
//
{
total_r
=
total_r
+
connect_colors
[
w
].
R
;
//
total_r = total_r + connect_colors[w].R;
total_g
=
total_g
+
connect_colors
[
w
].
G
;
//
total_g = total_g + connect_colors[w].G;
total_b
=
total_b
+
connect_colors
[
w
].
B
;
//
total_b = total_b + connect_colors[w].B;
}
//
}
for
(
int
w
=
0
;
w
<
10
;
w
++
)
//
for (int w = 0; w < 10; w++)
{
//
{
connect_colors
[
w
].
R
=
connect_colors
[
w
].
R
/
(
total_r
+
0.001
);
//
connect_colors[w].R = connect_colors[w].R/(total_r+0.001);
connect_colors
[
w
].
G
=
connect_colors
[
w
].
G
/
(
total_g
+
0.001
);
//
connect_colors[w].G = connect_colors[w].G/(total_g+0.001);
connect_colors
[
w
].
B
=
connect_colors
[
w
].
B
/
(
total_b
+
0.001
);
//
connect_colors[w].B = connect_colors[w].B/(total_b+0.001);
}
//
}
double
color_prob_r
=
0.0
,
color_prob_g
=
0.0
,
color_prob_b
=
0.0
;
//
double color_prob_r = 0.0, color_prob_g = 0.0, color_prob_b = 0.0;
for
(
int
s
=
0
;
s
<
10
;
s
++
)
//
for (int s = 0; s < 10; s++)
{
//
{
color_prob_r
=
color_prob_r
+
colors
[
s
].
R
*
connect_colors
[
s
].
R
;
//
color_prob_r = color_prob_r + colors[s].R*connect_colors[s].R;
color_prob_g
=
color_prob_g
+
colors
[
s
].
G
*
connect_colors
[
s
].
G
;
//
color_prob_g = color_prob_g + colors[s].G*connect_colors[s].G;
color_prob_b
=
color_prob_b
+
colors
[
s
].
B
*
connect_colors
[
s
].
B
;
//
color_prob_b = color_prob_b + colors[s].B*connect_colors[s].B;
}
//
}
if
((
color_prob_r
>=
0.0
)
&&
(
color_prob_g
>=
0.0
)
&&
(
color_prob_b
>=
0.0
))
//
if ((color_prob_r>=0.0)&&(color_prob_g>=0.0)&&(color_prob_b>=0.0))
{
//
{
int
foreground_num
=
0
,
overlap_num
=
0
;
//
int foreground_num = 0, overlap_num = 0;
for
(
int
k
=
0
;
k
<
new_width
;
k
++
)
//
for (int k = 0; k < new_width; k++)
{
//
{
for
(
int
l
=
0
;
l
<
new_height
;
l
++
)
//
for (int l = 0; l < new_height; l++)
{
//
{
if
((
Image
[
k
][
l
]
==
my_label
)
&&
(
image
[
k
][
l
]
==
1
))
//
if ((Image[k][l] == my_label)&&(image[k][l] == 1))
overlap_num
++
;
//
overlap_num++;
}
//
}
}
//
}
myColor
color_temp
,
color_add
;
//
myColor color_temp, color_add;
color_add
=
color_rainbow
(
time_stamp
,
t
);
//
color_add = color_rainbow(time_stamp, t);
for
(
int
k
=
0
;
k
<
new_width
;
k
++
)
//
for (int k = 0; k < new_width; k++)
{
//
{
for
(
int
l
=
0
;
l
<
new_height
;
l
++
)
//
for (int l = 0; l < new_height; l++)
{
//
{
if
(
image
[
k
][
l
]
==
1
)
//
if (image[k][l] == 1)
{
//
{
Image
[
k
][
l
]
=
my_label
;
//
Image[k][l] = my_label;
if
(
overlap_num
<
1000
)
//
if (overlap_num < 1000)
{
//
{
color_temp
=
myGet2D
(
_CBM_model
->
_GetPrevious_nFrame
(
t
),
k
,
l
);
//
color_temp = myGet2D( _CBM_model->_GetPrevious_nFrame(t), k, l);
cv
::
Scalar
setcolor
;
//
cv::Scalar setcolor;
setcolor
.
val
[
0
]
=
color_temp
.
B
+
color_add
.
B
;
//
setcolor.val[0] = color_temp.B + color_add.B;
setcolor
.
val
[
1
]
=
color_temp
.
G
+
color_add
.
G
;
//
setcolor.val[1] = color_temp.G + color_add.G;
setcolor
.
val
[
2
]
=
color_temp
.
R
+
color_add
.
R
;
//
setcolor.val[2] = color_temp.R + color_add.R;
if
(
setcolor
.
val
[
0
]
>
255
)
setcolor
.
val
[
0
]
=
255
;
//
if (setcolor.val[0] > 255) setcolor.val[0] = 255;
if
(
setcolor
.
val
[
1
]
>
255
)
setcolor
.
val
[
1
]
=
255
;
//
if (setcolor.val[1] > 255) setcolor.val[1] = 255;
if
(
setcolor
.
val
[
2
]
>
255
)
setcolor
.
val
[
2
]
=
255
;
//
if (setcolor.val[2] > 255) setcolor.val[2] = 255;
Set2D
(
B
,
l
,
k
,
setcolor
);
//
Set2D(B,l,k,setcolor);
}
//
}
}
//
}
}
//
}
}
//
}
}
//
}
}
//
}
}
//
}
return
0
;
//
return 0;
}
//
}
int
ObjLeftDetect
::
spatial_flood
(
bool
**
foreground
,
int
i
,
int
j
)
int
ObjLeftDetect
::
spatial_flood
(
bool
**
foreground
,
int
i
,
int
j
)
{
{
if
((
j
<
0
)
||
(
j
>=
new_height
-
1
))
return
0
;
if
((
j
<
0
)
||
(
j
>=
new_height
-
1
))
return
0
;
...
...
ObjLeftDetect.h
View file @
e1126306
...
@@ -31,11 +31,11 @@ public:
...
@@ -31,11 +31,11 @@ public:
bool
process
(
myImage
*
input
,
vector
<
vector
<
int
>>*
resultLocation
);
bool
process
(
myImage
*
input
,
vector
<
vector
<
int
>>*
resultLocation
);
CBM_model
*
_CBM_model
;
CBM_model
*
_CBM_model
;
//cv::VideoWriter _writer1, _writer2;
//cv::VideoWriter _writer1, _writer2;
cv
::
Mat
A
,
B
;
//
cv::Mat A, B;
int
**
image
;
int
**
image
;
myFloatColor
*
connect_colors
;
myFloatColor
*
connect_colors
;
void
ObjLeftSet
(
myImage
*
input
,
int
set_MOG_LearnFrame
,
int
set_min_area
,
int
set_buffer_len
,
myImage
*
mask
);
void
ObjLeftSet
(
myImage
*
input
,
int
set_MOG_LearnFrame
,
int
set_min_area
,
int
set_buffer_len
,
myImage
*
mask
,
cv
::
Mat
*
cvmask
);
private
:
private
:
//SYSTEMTIME st;
//SYSTEMTIME st;
...
@@ -55,9 +55,9 @@ private:
...
@@ -55,9 +55,9 @@ private:
int
new_width
,
new_height
;
int
new_width
,
new_height
;
vector
<
Obj_info
*>
alarmList
;
vector
<
Obj_info
*>
alarmList
;
myImage
*
myimg1
,
*
myimg2
;
//
myImage * myimg1, * myimg2;
cv
::
Mat
ImgSynopsis
;
//
cv::Mat ImgSynopsis;
myImage
*
_ImgSynopsis
;
//
myImage * _ImgSynopsis;
int
Spatial_Temporal_Search
(
int
**
Image
,
int
i
,
int
j
,
myFloatColor
*
colors
,
int
time_stamp
,
int
my_label
);
int
Spatial_Temporal_Search
(
int
**
Image
,
int
i
,
int
j
,
myFloatColor
*
colors
,
int
time_stamp
,
int
my_label
);
int
spatial_flood
(
bool
**
foreground
,
int
i
,
int
j
);
int
spatial_flood
(
bool
**
foreground
,
int
i
,
int
j
);
...
@@ -70,7 +70,7 @@ private:
...
@@ -70,7 +70,7 @@ private:
int
pic_num
=
0
;
int
pic_num
=
0
;
//get mask points
//get mask points
cv
::
Mat
objmask
;
cv
::
Mat
*
objmask
;
std
::
vector
<
std
::
vector
<
cv
::
Point
>>
contours
;
std
::
vector
<
std
::
vector
<
cv
::
Point
>>
contours
;
};
};
...
...
main.cpp
View file @
e1126306
...
@@ -40,8 +40,8 @@ int main()
...
@@ -40,8 +40,8 @@ int main()
opt
.
bottom_left_y
=
853
;
opt
.
bottom_left_y
=
853
;
opt
.
bottom_right_x
=
2168
;
opt
.
bottom_right_x
=
2168
;
opt
.
bottom_right_y
=
842
;
opt
.
bottom_right_y
=
842
;
//
DetectAnomaly* detect = new DetectAnomaly(opt);
DetectAnomaly
*
detect
=
new
DetectAnomaly
(
opt
);
DetectAnomaly
*
detect
=
new
DetectAnomaly
();
//
DetectAnomaly* detect = new DetectAnomaly();
int
pic_num
=
0
;
int
pic_num
=
0
;
#ifdef DEBUG
#ifdef DEBUG
//cv::VideoWriter _writer;
//cv::VideoWriter _writer;
...
@@ -65,8 +65,8 @@ int main()
...
@@ -65,8 +65,8 @@ int main()
// continue;
// continue;
// }
// }
//
obj_left = detect->detectAnomaly(opt,qImg,&resultLocation);
obj_left
=
detect
->
detectAnomaly
(
opt
,
qImg
,
&
resultLocation
);
obj_left
=
detect
->
detectAnomaly
(
qImg
,
&
resultLocation
);
//
obj_left = detect->detectAnomaly(qImg,&resultLocation);
...
@@ -80,32 +80,32 @@ int main()
...
@@ -80,32 +80,32 @@ int main()
delete
results_map
[
0
];
delete
results_map
[
0
];
delete
input_mats
;
delete
input_mats
;
#ifdef DEBUG
#ifdef DEBUG
//
if (obj_left == true)
if
(
obj_left
==
true
)
//
{
{
//
printf("alram!!\n");
printf
(
"alram!!
\n
"
);
//
for(int i = 0; i < resultLocation.size();i++){
for
(
int
i
=
0
;
i
<
resultLocation
.
size
();
i
++
){
//
int x0 = resultLocation[i][0] * 4;
int
x0
=
resultLocation
[
i
][
0
]
*
4
;
//
int y0 = resultLocation[i][1] * 4 + 610;
int
y0
=
resultLocation
[
i
][
1
]
*
4
+
610
;
//
int x1 = resultLocation[i][2] * 4;
int
x1
=
resultLocation
[
i
][
2
]
*
4
;
//
int y1 = resultLocation[i][3] * 4 + 610;
int
y1
=
resultLocation
[
i
][
3
]
*
4
+
610
;
//
cv::Point p1(x0, y0);
cv
::
Point
p1
(
x0
,
y0
);
//
cv::Point p2(x1, y1);
cv
::
Point
p2
(
x1
,
y1
);
//
cv::rectangle(qImg, p1, p2, cv::Scalar(0, 255, 0), 2);
cv
::
rectangle
(
qImg
,
p1
,
p2
,
cv
::
Scalar
(
0
,
255
,
0
),
2
);
//
}
}
//
stringstream ss1;
stringstream
ss1
;
//
string outFile;
string
outFile
;
//
ss1 << "abanoned_"
ss1
<<
"abanoned_"
//
<< "show"
<<
"show"
//
<< count
<<
count
//
<< ".jpg";
<<
".jpg"
;
//
ss1 >> outFile;
ss1
>>
outFile
;
//
cv::imwrite(outFile.c_str(), qImg);
cv
::
imwrite
(
outFile
.
c_str
(),
qImg
);
//
count++;
count
++
;
//
}
}
#endif
#endif
}
}
gettimeofday
(
&
end
,
NULL
);
gettimeofday
(
&
end
,
NULL
);
...
@@ -116,7 +116,7 @@ int main()
...
@@ -116,7 +116,7 @@ int main()
printf
(
"Finished detec, then release ...
\n
"
);
printf
(
"Finished detec, then release ...
\n
"
);
#endif
#endif
delete
detect
;
//
delete detect;
//system("pause");
//system("pause");
return
0
;
return
0
;
}
}
yolov3/CMakeLists.txt
View file @
e1126306
...
@@ -9,7 +9,7 @@ project(yolo-trt VERSION 1.0)
...
@@ -9,7 +9,7 @@ project(yolo-trt VERSION 1.0)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wno-write-strings")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wno-write-strings")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,$ORIGIN")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,$ORIGIN")
find_package
(
OpenCV
4.1.1
REQUIRED
)
find_package
(
OpenCV REQUIRED
)
#cuda
#cuda
#export PATH=/usr/local/cuda-10.2/bin:$PATH
#export PATH=/usr/local/cuda-10.2/bin:$PATH
...
...
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