diff --git a/doc/tutorials/dnn/dnn_googlenet/dnn_googlenet.markdown b/doc/tutorials/dnn/dnn_googlenet/dnn_googlenet.markdown index 83fef32f33..feb1e0985e 100644 --- a/doc/tutorials/dnn/dnn_googlenet/dnn_googlenet.markdown +++ b/doc/tutorials/dnn/dnn_googlenet/dnn_googlenet.markdown @@ -37,11 +37,7 @@ Explanation -# Read input image and convert to the blob, acceptable by GoogleNet @snippet dnn/caffe_googlenet.cpp Prepare blob - Firstly, we resize the image and change its channel sequence order. - - Now image is actually a 3-dimensional array with 224x224x3 shape. - - Next, we convert the image to 4-dimensional blob (so-called batch) with 1x3x224x224 shape by using special cv::dnn::blobFromImages constructor. + 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. -# Pass the blob to the network @snippet dnn/caffe_googlenet.cpp Set input blob diff --git a/samples/dnn/squeezenet_halide.cpp b/samples/dnn/squeezenet_halide.cpp index 6de90cbfce..f79c146df2 100644 --- a/samples/dnn/squeezenet_halide.cpp +++ b/samples/dnn/squeezenet_halide.cpp @@ -79,8 +79,7 @@ int main(int argc, char **argv) exit(-1); } - resize(img, img, Size(227, 227)); // SqueezeNet v1.1 predict class by 3x227x227 input image. - Mat inputBlob = blobFromImage(img, 1.0, Size(), Scalar(), false); // Convert Mat to 4-dimensional batch. + Mat inputBlob = blobFromImage(img, 1.0, Size(227, 227), Scalar(), false, false); // Convert Mat to 4-dimensional batch. //! [Prepare blob] //! [Set input blob] diff --git a/samples/dnn/ssd_object_detection.cpp b/samples/dnn/ssd_object_detection.cpp index 3f89510f9f..d88d65498e 100644 --- a/samples/dnn/ssd_object_detection.cpp +++ b/samples/dnn/ssd_object_detection.cpp @@ -10,36 +10,6 @@ using namespace cv::dnn; #include using namespace std; -const size_t width = 300; -const size_t height = 300; - -static Mat getMean(const size_t& imageHeight, const size_t& imageWidth) -{ - Mat mean; - - const int meanValues[3] = {104, 117, 123}; - vector meanChannels; - for(int i = 0; i < 3; i++) - { - Mat channel((int)imageHeight, (int)imageWidth, CV_32F, Scalar(meanValues[i])); - meanChannels.push_back(channel); - } - cv::merge(meanChannels, mean); - return mean; -} - -static Mat preprocess(const Mat& frame) -{ - Mat preprocessed; - frame.convertTo(preprocessed, CV_32F); - resize(preprocessed, preprocessed, Size(width, height)); //SSD accepts 300x300 RGB-images - - Mat mean = getMean(width, height); - cv::subtract(preprocessed, mean, preprocessed); - - return preprocessed; -} - const char* classNames[] = {"background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", @@ -126,9 +96,7 @@ int main(int argc, char** argv) cvtColor(frame, frame, COLOR_BGRA2BGR); //! [Prepare blob] - Mat preprocessedFrame = preprocess(frame); - - Mat inputBlob = blobFromImage(preprocessedFrame, 1.0f, Size(), Scalar(), false); //Convert Mat to batch of images + Mat inputBlob = blobFromImage(frame, 1.0f, Size(300, 300), Scalar(104, 117, 123), false, false); //Convert Mat to batch of images //! [Prepare blob] //! [Set input blob] diff --git a/samples/dnn/tf_inception.cpp b/samples/dnn/tf_inception.cpp index f184d39270..e411cc8519 100644 --- a/samples/dnn/tf_inception.cpp +++ b/samples/dnn/tf_inception.cpp @@ -78,12 +78,7 @@ int main(int argc, char **argv) exit(-1); } - cv::Size inputImgSize = cv::Size(224, 224); - - if (inputImgSize != img.size()) - resize(img, img, inputImgSize); //Resize image to input size - - Mat inputBlob = blobFromImage(img); //Convert Mat to image batch + Mat inputBlob = blobFromImage(img, 1.0f, Size(224, 224), Scalar(), true, false); //Convert Mat to batch of images //! [Prepare blob] inputBlob -= 117.0; //! [Set input blob] diff --git a/samples/dnn/torch_enet.cpp b/samples/dnn/torch_enet.cpp index 6101d17f06..37a5db8da4 100644 --- a/samples/dnn/torch_enet.cpp +++ b/samples/dnn/torch_enet.cpp @@ -76,7 +76,7 @@ int main(int argc, char **argv) exit(-1); } - Mat inputBlob = blobFromImage(img, 1./255, Size(1024, 512), Scalar(), true, false); //Convert Mat to image batch + Mat inputBlob = blobFromImage(img, 1./255, Size(1024, 512), Scalar(), true, false); //Convert Mat to batch of images //! [Prepare blob] //! [Set input blob] diff --git a/samples/dnn/yolo_object_detection.cpp b/samples/dnn/yolo_object_detection.cpp index 3bc277898f..9740fbac40 100644 --- a/samples/dnn/yolo_object_detection.cpp +++ b/samples/dnn/yolo_object_detection.cpp @@ -14,9 +14,6 @@ using namespace std; using namespace cv; using namespace cv::dnn; -const size_t network_width = 416; -const size_t network_height = 416; - static const char* about = "This sample uses You only look once (YOLO)-Detector (https://arxiv.org/abs/1612.08242) to detect objects on camera/video/image.\n" "Models can be downloaded here: https://pjreddie.com/darknet/yolo/\n" @@ -104,13 +101,8 @@ int main(int argc, char** argv) if (frame.channels() == 4) cvtColor(frame, frame, COLOR_BGRA2BGR); - //! [Resizing without keeping aspect ratio] - Mat resized; - resize(frame, resized, Size(network_width, network_height)); - //! [Resizing without keeping aspect ratio] - //! [Prepare blob] - Mat inputBlob = blobFromImage(resized, 1 / 255.F); //Convert Mat to batch of images + Mat inputBlob = blobFromImage(frame, 1 / 255.F, Size(416, 416), Scalar(), true, false); //Convert Mat to batch of images //! [Prepare blob] //! [Set input blob]