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
9f8da9dc
Commit
9f8da9dc
authored
Apr 19, 2021
by
wanghailong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加gdb调试,增加初始化项
parent
683ccfa0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
128 additions
and
64 deletions
+128
-64
.gitignore
.gitignore
+3
-2
CMakeLists.txt
CMakeLists.txt
+1
-1
DetectAnomaly.cpp
DetectAnomaly.cpp
+6
-3
DetectAnomaly.h
DetectAnomaly.h
+7
-2
main.cpp
main.cpp
+109
-54
CMakeLists.txt
yolov3/CMakeLists.txt
+2
-2
No files found.
.gitignore
View file @
9f8da9dc
...
...
@@ -3,4 +3,5 @@
/.vscode
*.mp4
*.md~
/yolov3/configs/models
\ No newline at end of file
/yolov3/configs/models
/data
\ No newline at end of file
CMakeLists.txt
View file @
9f8da9dc
...
...
@@ -6,7 +6,7 @@ link_directories(${MYPROJECT_DIR})
#set(CMAKE_BUILD_TYPE "Debug")
set
(
CMAKE_BUILD_TYPE
"Release"
)
set
(
CMAKE_CXX_FLAGS
"-O0 -march=native"
)
set
(
CMAKE_CXX_FLAGS
"-O0 -march=native
-Wall -g2 -ggdb
"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -g -Wno-write-strings"
)
set
(
CMAKE_EXE_LINKER_FLAGS
"
${
CMAKE_EXE_LINKER_FLAGS
}
-Wl,-rpath -Wl,$ORIGIN"
)
...
...
DetectAnomaly.cpp
View file @
9f8da9dc
...
...
@@ -43,8 +43,10 @@ bool DetectAnomaly::build_model(cv::Mat img){
}
bool
DetectAnomaly
::
build_model
(
config
cfg
,
cv
::
Mat
img
){
cv
::
Rect
rect
(
0
,
img
.
rows
-
cfg
.
image_height
,
cfg
.
image_width
,
cfg
.
image_height
);
//cv::Rect rect(0,img.rows - cfg.image_height,cfg.image_width,cfg.image_height);
cv
::
Rect
rect
(
cfg
.
rect_x
,
cfg
.
rect_y
,
cfg
.
image_width
,
cfg
.
image_height
);
img
=
img
(
rect
);
//cv::imwrite("cut_img.jpg",img);
//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
);
//myimg = &img;
...
...
@@ -81,7 +83,8 @@ bool DetectAnomaly::detectAnomaly(cv::Mat img, vector<vector<int>>* resultLocati
bool
DetectAnomaly
::
detectAnomaly
(
config
cfg
,
cv
::
Mat
img
,
vector
<
vector
<
int
>>*
resultLocation
)
{
//cv::Rect rect(0,610,2400,910);
cv
::
Rect
rect
(
0
,
img
.
rows
-
cfg
.
image_height
,
cfg
.
image_width
,
cfg
.
image_height
);
//cv::Rect rect(0,img.rows - cfg.image_height,cfg.image_width,cfg.image_height);
cv
::
Rect
rect
(
cfg
.
rect_x
,
cfg
.
rect_y
,
cfg
.
image_width
,
cfg
.
image_height
);
img
=
img
(
rect
);
//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
);
...
...
@@ -292,7 +295,7 @@ DetectAnomaly::DetectAnomaly(config cfg) : cfgAnomaly(cfg)
opencv_2_myImage
(
*
mask
,
mymask
);
#ifdef DEBUG
cv
::
imwrite
(
"mask.jpg"
,
Image1
);
//
cv::imwrite("mask.jpg", Image1);
//cv::waitKey(1);
//cvReleaseImage(&Image1);
#endif
...
...
DetectAnomaly.h
View file @
9f8da9dc
...
...
@@ -17,12 +17,17 @@ typedef struct ConfigAnomaly
int
max_fg
=
75000
;
int
min_fg
=
50
;
int
buffer_length
;
int
image_height
;
int
image_width
;
double
gmm_long_learn_rate
=
0
.
0001
;
double
gmm_short_learn_rate
=
0
.
002
;
double
input_resize
=
0
.
25
;
//rect
int
rect_x
;
int
rect_y
;
int
image_height
;
int
image_width
;
//多边形坐标
int
top_left_x
;
int
top_left_y
;
int
top_right_x
;
...
...
main.cpp
View file @
9f8da9dc
...
...
@@ -16,33 +16,51 @@ int main()
//init
Config
yoloconfig
;
yoloconfig
.
file_model_cfg
=
"/
home/zszt/whl
/datang/yolov3/configs/yolov3-spp_1batch.cfg"
;
yoloconfig
.
enginepath
=
"/
home/zszt/whl/datang/yolov3/configs/models/p2200
/yolov3-spp_final-kINT8-batch1.engine"
;
yoloconfig
.
file_model_cfg
=
"/
media/6542bc52-3d7a-4bea-b9b6-f9343ca8560f
/datang/yolov3/configs/yolov3-spp_1batch.cfg"
;
yoloconfig
.
enginepath
=
"/
media/6542bc52-3d7a-4bea-b9b6-f9343ca8560f/datang/yolov3/configs/models/xviver
/yolov3-spp_final-kINT8-batch1.engine"
;
InitCnrt
(
true
,
yoloconfig
);
int
count
=
0
;
char
test_video
[
200
]
=
"
/home/zszt/whl/test_video/test-6.avi
"
;
char
test_video
[
200
]
=
"
../data/vlc-record-2021-03-30-10h59m07s-rtsp___1....mp4
"
;
VideoDetails
*
_video
;
_video
=
new
VideoDetails
(
test_video
);
cv
::
Mat
qImg
;
//抛洒物
config
opt
;
opt
.
image_height
=
910
;
opt
.
image_width
=
2400
;
// opt.rect_x = 0;
// opt.rect_y = 610;
// opt.image_height = 910;
// opt.image_width = 2400;
// opt.buffer_length = 200;
// opt.gmm_learn_frame = 600;
// opt.top_left_x = 1136;
// opt.top_left_y = 3;
// opt.top_right_x = 1340;
// opt.top_right_y = 10;
// opt.bottom_left_x = 198;
// opt.bottom_left_y = 853;
// opt.bottom_right_x = 2168;
// opt.bottom_right_y = 842;
opt
.
rect_x
=
1100
;
opt
.
rect_y
=
260
;
opt
.
image_height
=
1260
;
opt
.
image_width
=
1588
;
opt
.
buffer_length
=
200
;
opt
.
gmm_learn_frame
=
600
;
opt
.
top_left_x
=
113
6
;
opt
.
top_left_y
=
3
;
opt
.
top_right_x
=
1340
;
opt
.
top_right_y
=
10
;
opt
.
bottom_left_x
=
1
98
;
opt
.
bottom_left_y
=
853
;
opt
.
bottom_right_x
=
2168
;
opt
.
bottom_right_y
=
8
42
;
//
DetectAnomaly* detect = new DetectAnomaly(opt);
DetectAnomaly
*
detect
=
new
DetectAnomaly
();
opt
.
top_left_x
=
6
6
;
opt
.
top_left_y
=
15
;
opt
.
top_right_x
=
286
;
opt
.
top_right_y
=
2
;
opt
.
bottom_left_x
=
1
16
;
opt
.
bottom_left_y
=
1260
;
opt
.
bottom_right_x
=
1582
;
opt
.
bottom_right_y
=
8
58
;
DetectAnomaly
*
detect
=
new
DetectAnomaly
(
opt
);
//
DetectAnomaly* detect = new DetectAnomaly();
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);
...
...
@@ -52,9 +70,9 @@ int main()
/************************************************************************/
bool
obj_left
=
false
;
//calculate time
//
struct timeval start, end;
//
float time = 0;
//
gettimeofday(&start, NULL);
struct
timeval
start
,
end
;
float
time
=
0
;
gettimeofday
(
&
start
,
NULL
);
bool
check_build_net
=
false
;
while
(
_video
->
_file
.
read
(
qImg
))
{
...
...
@@ -62,18 +80,19 @@ int main()
float
time
=
0
;
if
(
!
check_build_net
){
gettimeofday
(
&
start
,
NULL
);
//
check_build_net = detect->build_model(opt,qImg);
check_build_net
=
detect
->
build_model
(
qImg
);
check_build_net
=
detect
->
build_model
(
opt
,
qImg
);
//
check_build_net = detect->build_model(qImg);
gettimeofday
(
&
end
,
NULL
);
time
=
(
1000000
*
(
end
.
tv_sec
-
start
.
tv_sec
)
+
end
.
tv_usec
-
start
.
tv_usec
)
/
(
1000.0
);
//cout << "build time = " << time << "ms" << endl;
//break;
}
else
{
gettimeofday
(
&
start
,
NULL
);
vector
<
vector
<
int
>>
resultLocation
;
//
obj_left = detect->detectAnomaly(opt,qImg,&resultLocation);
obj_left
=
detect
->
detectAnomaly
(
qImg
,
&
resultLocation
);
obj_left
=
detect
->
detectAnomaly
(
opt
,
qImg
,
&
resultLocation
);
//
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
);
...
...
@@ -84,49 +103,85 @@ int main()
printf
(
"alram!!
\n
"
);
//
for(int i = 0; i < resultLocation.size();i++){
// int x0 = resultLocation[i][0] * 4
;
// int y0 = resultLocation[i][1] * 4 + 610
;
// int x1 = resultLocation[i][2] * 4
;
// int y1 = resultLocation[i][3] * 4 + 610
;
for
(
int
i
=
0
;
i
<
resultLocation
.
size
();
i
++
){
int
x0
=
resultLocation
[
i
][
0
]
*
(
1.0
/
opt
.
input_resize
)
+
opt
.
rect_x
;
int
y0
=
resultLocation
[
i
][
1
]
*
(
1.0
/
opt
.
input_resize
)
+
opt
.
rect_y
;
int
x1
=
resultLocation
[
i
][
2
]
*
(
1.0
/
opt
.
input_resize
)
+
opt
.
rect_x
;
int
y1
=
resultLocation
[
i
][
3
]
*
(
1.0
/
opt
.
input_resize
)
+
opt
.
rect_y
;
// cv::Point p1(x0, y0);
// cv::Point p2(x1, y1);
// cv::rectangle(qImg, p1, p2, cv::Scalar(0, 255, 0), 2);
// }
// stringstream ss1;
// string outFile;
// ss1 << "abanoned_"
// << "show"
// << count
// << ".jpg";
// ss1 >> outFile;
// cv::imwrite(outFile.c_str(), qImg);
cv
::
Point
p1
(
x0
,
y0
);
cv
::
Point
p2
(
x1
,
y1
);
cv
::
rectangle
(
qImg
,
p1
,
p2
,
cv
::
Scalar
(
0
,
255
,
0
),
2
);
}
std
::
cout
<<
pic_num
;
stringstream
ss1
;
string
outFile
;
ss1
<<
"abanoned_"
<<
"show"
<<
count
<<
".jpg"
;
ss1
>>
outFile
;
cv
::
imwrite
(
outFile
.
c_str
(),
qImg
);
//
count++;
count
++
;
}
#endif
}
pic_num
++
;
// //yolo_infer
vector
<
cv
::
Mat
>*
input_mats
=
new
vector
<
cv
::
Mat
>
;
input_mats
->
push_back
(
qImg
.
clone
());
std
::
map
<
int
,
Results
*>
results_map
;
Results
*
results
=
new
Results
;
results_map
.
insert
(
std
::
make_pair
(
0
,
results
));
inference
(
&
results_map
,
input_mats
);
delete
results_map
[
0
];
delete
input_mats
;
// vector<cv::Mat>* input_mats = new vector<cv::Mat>;
// input_mats->push_back(qImg.clone());
// std::map<int,Results*> results_map;
// Results* results = new Results;
// results_map.insert(std::make_pair(0,results));
// inference(&results_map,input_mats);
// for(int i = 0; i < input_mats->size(); i ++){
// cv::Mat image = input_mats->at(i).clone();
// auto result = results_map->at(i);
// // if(result->facility.size() == 0){
// // continue;
// // }
// //std::cout << result->facility.size() << "\n";
// for (int i = 0; i < result->facility.size(); i++) {
// int x0 = result->facility[i].location[0];
// int y0 = result->facility[i].location[1];
// int x1 = result->facility[i].location[2];
// int y1 = result->facility[i].location[3];
// cv::Point p1(x0, y0);
// cv::Point p2(x1, y1);
// cv::rectangle(image, p1, p2, cv::Scalar(0, 255, 0), 2);
// stringstream ss;
// ss << round(result->facility[i].prob * 1000) / 1000.0;
// std::string str =
// result->facility[i].facility_name + ":" + ss.str();
// cv::Point p5(x0, y0 + 10);
// cv::putText(image, str, p5, cv::FONT_HERSHEY_SIMPLEX, 0.5,
// cv::Scalar(255, 0, 0), 0.5);
// }
// stringstream ss1;
// string outFile;
// ss1 << "yolov3_"
// << "show"
// << i
// << ".jpg";
// ss1 >> outFile;
// cv::imwrite(outFile.c_str(), image);
// }
// delete results_map[0];
// delete input_mats;
}
//
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;
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
"
);
#endif
delete
_video
;
//
delete _video;
delete
detect
;
//system("pause");
return
0
;
...
...
yolov3/CMakeLists.txt
View file @
9f8da9dc
...
...
@@ -6,8 +6,8 @@ project(yolo-trt VERSION 1.0)
#set(CMAKE_BUILD_TYPE "Release")
#set(CMAKE_CXX_COMPILIER "/usr/bin/g++")
#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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -
Wno-write-strings -O0 -Wall -g2 -ggdb
")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,$ORIGIN
")
find_package
(
OpenCV REQUIRED
)
...
...
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