mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge pull request #9835 from sovrasov:blob_from_img_crop_opt
This commit is contained in:
+15
-10
@@ -85,15 +85,15 @@ static String toString(const T &v)
|
||||
}
|
||||
|
||||
Mat blobFromImage(const Mat& image, double scalefactor, const Size& size,
|
||||
const Scalar& mean, bool swapRB)
|
||||
const Scalar& mean, bool swapRB, bool crop)
|
||||
{
|
||||
CV_TRACE_FUNCTION();
|
||||
std::vector<Mat> images(1, image);
|
||||
return blobFromImages(images, scalefactor, size, mean, swapRB);
|
||||
return blobFromImages(images, scalefactor, size, mean, swapRB, crop);
|
||||
}
|
||||
|
||||
Mat blobFromImages(const std::vector<Mat>& images_, double scalefactor, Size size,
|
||||
const Scalar& mean_, bool swapRB)
|
||||
const Scalar& mean_, bool swapRB, bool crop)
|
||||
{
|
||||
CV_TRACE_FUNCTION();
|
||||
std::vector<Mat> images = images_;
|
||||
@@ -104,13 +104,18 @@ Mat blobFromImages(const std::vector<Mat>& images_, double scalefactor, Size siz
|
||||
size = imgSize;
|
||||
if (size != imgSize)
|
||||
{
|
||||
float resizeFactor = std::max(size.width / (float)imgSize.width,
|
||||
size.height / (float)imgSize.height);
|
||||
resize(images[i], images[i], Size(), resizeFactor, resizeFactor);
|
||||
Rect crop(Point(0.5 * (images[i].cols - size.width),
|
||||
0.5 * (images[i].rows - size.height)),
|
||||
size);
|
||||
images[i] = images[i](crop);
|
||||
if(crop)
|
||||
{
|
||||
float resizeFactor = std::max(size.width / (float)imgSize.width,
|
||||
size.height / (float)imgSize.height);
|
||||
resize(images[i], images[i], Size(), resizeFactor, resizeFactor);
|
||||
Rect crop(Point(0.5 * (images[i].cols - size.width),
|
||||
0.5 * (images[i].rows - size.height)),
|
||||
size);
|
||||
images[i] = images[i](crop);
|
||||
}
|
||||
else
|
||||
resize(images[i], images[i], size);
|
||||
}
|
||||
if(images[i].depth() == CV_8U)
|
||||
images[i].convertTo(images[i], CV_32F);
|
||||
|
||||
Reference in New Issue
Block a user