mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
dnn: handle 4-channel images in blobFromImage (#9944)
This commit is contained in:
parent
e5766513a4
commit
5bf39ceb5d
@ -688,7 +688,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
|
|||||||
CV_EXPORTS_W Mat readTorchBlob(const String &filename, bool isBinary = true);
|
CV_EXPORTS_W Mat readTorchBlob(const String &filename, bool isBinary = true);
|
||||||
/** @brief Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center,
|
/** @brief Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center,
|
||||||
* subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
|
* subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels.
|
||||||
* @param image input image (with 1- or 3-channels).
|
* @param image input image (with 1-, 3- or 4-channels).
|
||||||
* @param size spatial size for output image
|
* @param size spatial size for output image
|
||||||
* @param mean scalar with mean values which are subtracted from channels. Values are intended
|
* @param mean scalar with mean values which are subtracted from channels. Values are intended
|
||||||
* to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
|
* to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
|
||||||
@ -706,7 +706,7 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
|
|||||||
/** @brief Creates 4-dimensional blob from series of images. Optionally resizes and
|
/** @brief Creates 4-dimensional blob from series of images. Optionally resizes and
|
||||||
* crops @p images from center, subtract @p mean values, scales values by @p scalefactor,
|
* crops @p images from center, subtract @p mean values, scales values by @p scalefactor,
|
||||||
* swap Blue and Red channels.
|
* swap Blue and Red channels.
|
||||||
* @param images input images (all with 1- or 3-channels).
|
* @param images input images (all with 1-, 3- or 4-channels).
|
||||||
* @param size spatial size for output image
|
* @param size spatial size for output image
|
||||||
* @param mean scalar with mean values which are subtracted from channels. Values are intended
|
* @param mean scalar with mean values which are subtracted from channels. Values are intended
|
||||||
* to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
|
* to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true.
|
||||||
|
@ -136,7 +136,7 @@ Mat blobFromImages(const std::vector<Mat>& images_, double scalefactor, Size siz
|
|||||||
Mat blob, image;
|
Mat blob, image;
|
||||||
if (nch == 3 || nch == 4)
|
if (nch == 3 || nch == 4)
|
||||||
{
|
{
|
||||||
int sz[] = { (int)nimages, 3, image0.rows, image0.cols };
|
int sz[] = { (int)nimages, nch, image0.rows, image0.cols };
|
||||||
blob = Mat(4, sz, CV_32F);
|
blob = Mat(4, sz, CV_32F);
|
||||||
Mat ch[4];
|
Mat ch[4];
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ Mat blobFromImages(const std::vector<Mat>& images_, double scalefactor, Size siz
|
|||||||
CV_Assert(image.dims == 2 && (nch == 3 || nch == 4));
|
CV_Assert(image.dims == 2 && (nch == 3 || nch == 4));
|
||||||
CV_Assert(image.size() == image0.size());
|
CV_Assert(image.size() == image0.size());
|
||||||
|
|
||||||
for( int j = 0; j < 3; j++ )
|
for( int j = 0; j < nch; j++ )
|
||||||
ch[j] = Mat(image.rows, image.cols, CV_32F, blob.ptr((int)i, j));
|
ch[j] = Mat(image.rows, image.cols, CV_32F, blob.ptr((int)i, j));
|
||||||
if(swapRB)
|
if(swapRB)
|
||||||
std::swap(ch[0], ch[2]);
|
std::swap(ch[0], ch[2]);
|
||||||
|
30
modules/dnn/test/test_misc.cpp
Normal file
30
modules/dnn/test/test_misc.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// This file is part of OpenCV project.
|
||||||
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||||
|
// of this distribution and at http://opencv.org/license.html.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2017, Intel Corporation, all rights reserved.
|
||||||
|
// Third party copyrights are property of their respective owners.
|
||||||
|
|
||||||
|
#include "test_precomp.hpp"
|
||||||
|
|
||||||
|
namespace cvtest
|
||||||
|
{
|
||||||
|
|
||||||
|
TEST(blobFromImage_4ch, Regression)
|
||||||
|
{
|
||||||
|
Mat ch[4];
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
ch[i] = Mat::ones(10, 10, CV_8U)*i;
|
||||||
|
|
||||||
|
Mat img;
|
||||||
|
merge(ch, 4, img);
|
||||||
|
Mat blob = dnn::blobFromImage(img, 1., Size(), Scalar(), false, false);
|
||||||
|
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
ch[i] = Mat(img.rows, img.cols, CV_32F, blob.ptr(0, i));
|
||||||
|
ASSERT_DOUBLE_EQ(cvtest::norm(ch[i], cv::NORM_INF), i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user