Skip to content

Commit 9665dde

Browse files
committed
Merge pull request opencv#10112 from haritha1313:bugfix_doc1
2 parents 66e09bc + be4fa03 commit 9665dde

File tree

6 files changed

+6
-56
lines changed

6 files changed

+6
-56
lines changed

doc/tutorials/dnn/dnn_googlenet/dnn_googlenet.markdown

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ Explanation
3737

3838
-# Read input image and convert to the blob, acceptable by GoogleNet
3939
@snippet dnn/caffe_googlenet.cpp Prepare blob
40-
Firstly, we resize the image and change its channel sequence order.
41-
42-
Now image is actually a 3-dimensional array with 224x224x3 shape.
43-
44-
Next, we convert the image to 4-dimensional blob (so-called batch) with 1x3x224x224 shape by using special cv::dnn::blobFromImages constructor.
40+
We convert the image to a 4-dimensional blob (so-called batch) with 1x3x224x224 shape after applying necessary pre-processing like resizing and mean subtraction using cv::dnn::blobFromImage constructor.
4541

4642
-# Pass the blob to the network
4743
@snippet dnn/caffe_googlenet.cpp Set input blob

samples/dnn/squeezenet_halide.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ int main(int argc, char **argv)
7979
exit(-1);
8080
}
8181

82-
resize(img, img, Size(227, 227)); // SqueezeNet v1.1 predict class by 3x227x227 input image.
83-
Mat inputBlob = blobFromImage(img, 1.0, Size(), Scalar(), false); // Convert Mat to 4-dimensional batch.
82+
Mat inputBlob = blobFromImage(img, 1.0, Size(227, 227), Scalar(), false, false); // Convert Mat to 4-dimensional batch.
8483
//! [Prepare blob]
8584

8685
//! [Set input blob]

samples/dnn/ssd_object_detection.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,6 @@ using namespace cv::dnn;
1010
#include <cstdlib>
1111
using namespace std;
1212

13-
const size_t width = 300;
14-
const size_t height = 300;
15-
16-
static Mat getMean(const size_t& imageHeight, const size_t& imageWidth)
17-
{
18-
Mat mean;
19-
20-
const int meanValues[3] = {104, 117, 123};
21-
vector<Mat> meanChannels;
22-
for(int i = 0; i < 3; i++)
23-
{
24-
Mat channel((int)imageHeight, (int)imageWidth, CV_32F, Scalar(meanValues[i]));
25-
meanChannels.push_back(channel);
26-
}
27-
cv::merge(meanChannels, mean);
28-
return mean;
29-
}
30-
31-
static Mat preprocess(const Mat& frame)
32-
{
33-
Mat preprocessed;
34-
frame.convertTo(preprocessed, CV_32F);
35-
resize(preprocessed, preprocessed, Size(width, height)); //SSD accepts 300x300 RGB-images
36-
37-
Mat mean = getMean(width, height);
38-
cv::subtract(preprocessed, mean, preprocessed);
39-
40-
return preprocessed;
41-
}
42-
4313
const char* classNames[] = {"background",
4414
"aeroplane", "bicycle", "bird", "boat",
4515
"bottle", "bus", "car", "cat", "chair",
@@ -126,9 +96,7 @@ int main(int argc, char** argv)
12696
cvtColor(frame, frame, COLOR_BGRA2BGR);
12797

12898
//! [Prepare blob]
129-
Mat preprocessedFrame = preprocess(frame);
130-
131-
Mat inputBlob = blobFromImage(preprocessedFrame, 1.0f, Size(), Scalar(), false); //Convert Mat to batch of images
99+
Mat inputBlob = blobFromImage(frame, 1.0f, Size(300, 300), Scalar(104, 117, 123), false, false); //Convert Mat to batch of images
132100
//! [Prepare blob]
133101

134102
//! [Set input blob]

samples/dnn/tf_inception.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,7 @@ int main(int argc, char **argv)
7878
exit(-1);
7979
}
8080

81-
cv::Size inputImgSize = cv::Size(224, 224);
82-
83-
if (inputImgSize != img.size())
84-
resize(img, img, inputImgSize); //Resize image to input size
85-
86-
Mat inputBlob = blobFromImage(img); //Convert Mat to image batch
81+
Mat inputBlob = blobFromImage(img, 1.0f, Size(224, 224), Scalar(), true, false); //Convert Mat to batch of images
8782
//! [Prepare blob]
8883
inputBlob -= 117.0;
8984
//! [Set input blob]

samples/dnn/torch_enet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
7676
exit(-1);
7777
}
7878

79-
Mat inputBlob = blobFromImage(img, 1./255, Size(1024, 512), Scalar(), true, false); //Convert Mat to image batch
79+
Mat inputBlob = blobFromImage(img, 1./255, Size(1024, 512), Scalar(), true, false); //Convert Mat to batch of images
8080
//! [Prepare blob]
8181

8282
//! [Set input blob]

samples/dnn/yolo_object_detection.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ using namespace std;
1414
using namespace cv;
1515
using namespace cv::dnn;
1616

17-
const size_t network_width = 416;
18-
const size_t network_height = 416;
19-
2017
static const char* about =
2118
"This sample uses You only look once (YOLO)-Detector (https://arxiv.org/abs/1612.08242) to detect objects on camera/video/image.\n"
2219
"Models can be downloaded here: https://pjreddie.com/darknet/yolo/\n"
@@ -104,13 +101,8 @@ int main(int argc, char** argv)
104101
if (frame.channels() == 4)
105102
cvtColor(frame, frame, COLOR_BGRA2BGR);
106103

107-
//! [Resizing without keeping aspect ratio]
108-
Mat resized;
109-
resize(frame, resized, Size(network_width, network_height));
110-
//! [Resizing without keeping aspect ratio]
111-
112104
//! [Prepare blob]
113-
Mat inputBlob = blobFromImage(resized, 1 / 255.F); //Convert Mat to batch of images
105+
Mat inputBlob = blobFromImage(frame, 1 / 255.F, Size(416, 416), Scalar(), true, false); //Convert Mat to batch of images
114106
//! [Prepare blob]
115107

116108
//! [Set input blob]

0 commit comments

Comments
 (0)