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,
* 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 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.
/** @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,
* 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 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.
Mat blob, image;
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);
Mat ch[4];
CV_Assert(image.dims == 2 && (nch == 3 || nch == 4));
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));
if(swapRB)
std::swap(ch[0], ch[2]);
--- /dev/null
+// 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);
+ }
+}
+
+}