Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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
submodule
opencv_contrib
Commits
740ca1d2
Commit
740ca1d2
authored
Jul 21, 2016
by
Anna Petrovicheva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finalized the sample
parent
9b7ffbce
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
90 deletions
+75
-90
ssd_object_detection.cpp
modules/dnn/samples/ssd_object_detection.cpp
+75
-90
No files found.
modules/dnn/samples/ssd_object_detection.cpp
View file @
740ca1d2
...
@@ -9,54 +9,42 @@ using namespace cv::dnn;
...
@@ -9,54 +9,42 @@ using namespace cv::dnn;
#include <cstdlib>
#include <cstdlib>
using
namespace
std
;
using
namespace
std
;
const
size_t
width
=
300
;
const
size_t
height
=
300
;
//static void colorizeSegmentation(dnn::Blob& score,
Mat
getMean
(
const
size_t
&
height
,
const
size_t
&
width
)
// const vector<cv::Vec3b>& colors,
{
// cv::Mat& segm)
Mat
mean
;
//{
// const int rows = score.rows();
const
int
meanValues
[
3
]
=
{
104
,
117
,
123
};
// const int cols = score.cols();
vector
<
Mat
>
meanChannels
;
// const int chns = score.channels();
for
(
size_t
i
=
0
;
i
<
3
;
i
++
)
{
// cv::Mat maxCl(rows, cols, CV_8UC1);
Mat
channel
(
height
,
width
,
CV_32F
,
Scalar
(
meanValues
[
i
]));
// cv::Mat maxVal(rows, cols, CV_32FC1);
meanChannels
.
push_back
(
channel
);
// for (int ch = 0; ch < chns; ch++)
}
// {
cv
::
merge
(
meanChannels
,
mean
);
// for (int row = 0; row < rows; row++)
return
mean
;
// {
}
// const float* ptrScore = score.ptrf(0, ch, row);
// uchar* ptrMaxCl = maxCl.ptr<uchar>(row);
void
preprocess
(
Mat
&
frame
)
// float* ptrMaxVal = maxVal.ptr<float>(row);
{
// for (int col = 0; col < cols; col++)
frame
.
convertTo
(
frame
,
CV_32FC3
);
// {
resize
(
frame
,
frame
,
Size
(
width
,
height
));
//SSD accepts 300x300 RGB-images
// if (ptrScore[col] > ptrMaxVal[col])
// {
Mat
mean
=
getMean
(
width
,
height
);
// ptrMaxVal[col] = ptrScore[col];
cv
::
subtract
(
frame
,
mean
,
frame
);
// ptrMaxCl[col] = ch;
}
// }
// }
const
char
*
about
=
"This sample uses Single-Shot Detector "
// }
"(https://arxiv.org/abs/1512.02325)"
// }
"to detect objects on image
\n
"
;
// TODO: link
// segm.create(rows, cols, CV_8UC3);
// for (int row = 0; row < rows; row++)
// {
// const uchar* ptrMaxCl = maxCl.ptr<uchar>(row);
// cv::Vec3b* ptrSegm = segm.ptr<cv::Vec3b>(row);
// for (int col = 0; col < cols; col++)
// {
// ptrSegm[col] = colors[ptrMaxCl[col]];
// }
// }
//}
const
char
*
about
=
"This sample uses Single-Shot Detector to detect objects "
"from camera
\n
"
;
// TODO: link
const
char
*
params
const
char
*
params
=
"{ help | help | false | print usage }"
=
"{ help | help | false | print usage }"
"{ proto | model prototxt file | | model configuration }"
"{ proto | model prototxt file | | model configuration }"
"{ model | caffemodel file | | model weights }"
;
"{ model | caffemodel file | | model weights }"
"{ image | image file | | image for detection }"
;
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
...
@@ -102,53 +90,50 @@ int main(int argc, char** argv)
...
@@ -102,53 +90,50 @@ int main(int argc, char** argv)
importer
.
release
();
//We don't need importer anymore
importer
.
release
();
//We don't need importer anymore
//! [Initialize network]
//! [Initialize network]
VideoCapture
camera
;
cv
::
Mat
frame
=
cv
::
imread
(
parser
.
get
<
string
>
(
"image"
),
-
1
);
if
(
!
camera
.
open
(
0
))
{
cout
<<
"Unable to open camera stream"
<<
endl
;
return
0
;
}
size_t
i
=
0
;
//! [Prepare blob]
for
(;;
)
preprocess
(
frame
);
dnn
::
Blob
inputBlob
=
dnn
::
Blob
(
frame
);
//Convert Mat to dnn::Blob image
//! [Prepare blob]
//! [Set input blob]
net
.
setBlob
(
".data"
,
inputBlob
);
//set the network input
//! [Set input blob]
//! [Make forward pass]
net
.
forward
();
//compute output
//! [Make forward pass]
//! [Gather output]
dnn
::
Blob
detection
=
net
.
getBlob
(
"detection_out"
);
Mat
detectionMat
(
detection
.
rows
(),
detection
.
cols
(),
CV_32F
,
detection
.
ptrf
());
for
(
size_t
i
=
0
;
i
<
detectionMat
.
rows
;
i
++
)
{
{
Mat
frame
;
std
::
cout
<<
"Class: "
<<
detectionMat
.
at
<
float
>
(
i
,
1
)
<<
std
::
endl
;
camera
>>
frame
;
std
::
cout
<<
"Confidence: "
<<
detectionMat
.
at
<
float
>
(
i
,
2
)
<<
std
::
endl
;
if
(
frame
.
empty
())
break
;
std
::
cout
<<
" "
<<
detectionMat
.
at
<
float
>
(
i
,
3
)
*
width
;
std
::
cout
<<
" "
<<
detectionMat
.
at
<
float
>
(
i
,
4
)
*
height
;
//! [Prepare blob]
std
::
cout
<<
" "
<<
detectionMat
.
at
<
float
>
(
i
,
5
)
*
width
;
resize
(
frame
,
frame
,
Size
(
300
,
300
));
//SSD accepts 300x300 RGB-images
std
::
cout
<<
" "
<<
detectionMat
.
at
<
float
>
(
i
,
6
)
*
height
;
dnn
::
Blob
inputBlob
=
dnn
::
Blob
(
frame
);
//Convert Mat to dnn::Blob image
//! [Prepare blob]
float
xLeftBottom
=
detectionMat
.
at
<
float
>
(
i
,
3
)
*
width
;
float
yLeftBottom
=
detectionMat
.
at
<
float
>
(
i
,
4
)
*
height
;
std
::
ostringstream
stream
;
float
xRightTop
=
detectionMat
.
at
<
float
>
(
i
,
5
)
*
width
;
stream
<<
"folder/"
<<
i
<<
".jpg"
;
float
yRightTop
=
detectionMat
.
at
<
float
>
(
i
,
6
)
*
height
;
imwrite
(
stream
.
str
(),
frame
);
Rect
object
(
xLeftBottom
,
yLeftBottom
,
//! [Set input blob]
xRightTop
-
xLeftBottom
,
net
.
setBlob
(
".data"
,
inputBlob
);
//set the network input
yRightTop
-
yLeftBottom
);
//! [Set input blob]
rectangle
(
frame
,
object
,
Scalar
(
0
,
255
,
0
));
//! [Make forward pass]
net
.
forward
();
//compute output
//! [Make forward pass]
// //! [Gather output]
// dnn::Blob detection = net.getBlob("detection_out");
// // cv::Mat colorize;
// // colorizeSegmentation(score, colors, colorize);
// // cv::Mat show;
// // cv::addWeighted(img, 0.4, colorize, 0.6, 0.0, show);
// // cv::imshow("show", show);
// // cv::waitKey(0);
// // return 0;
// imshow("frame", frame);
// if (waitKey(1) == 27)
// break; // stop capturing by pressing ESC
}
}
camera
.
release
();
imshow
(
"detections"
,
frame
);
waitKey
();
return
0
;
}
// main
}
// main
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