mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 11:45:30 +08:00
crop parameter usage in blobFromImage() calls
This commit is contained in:
parent
66e09bc9a4
commit
be4fa03fac
@ -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
|
||||
|
@ -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]
|
||||
|
@ -10,36 +10,6 @@ using namespace cv::dnn;
|
||||
#include <cstdlib>
|
||||
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<Mat> 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]
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user