Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
江流儿的夏天
opencv
提交
5350fba3
O
opencv
项目概览
江流儿的夏天
/
opencv
与 Fork 源项目一致
Fork自
OpenCV / opencv
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
5350fba3
编写于
9月 06, 2023
作者:
A
Alexander Smorkalov
提交者:
GitHub
9月 06, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #24128 from CSBVision:CSBVision-patch-1
Fix bug at blobFromImagesWithParams
上级
f6473821
674c6184
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
27 deletion
+60
-27
modules/dnn/src/dnn_utils.cpp
modules/dnn/src/dnn_utils.cpp
+38
-27
modules/dnn/test/test_misc.cpp
modules/dnn/test/test_misc.cpp
+22
-0
未找到文件。
modules/dnn/src/dnn_utils.cpp
浏览文件 @
5350fba3
...
...
@@ -5,6 +5,7 @@
#include "precomp.hpp"
#include <opencv2/imgproc.hpp>
#include <opencv2/core/utils/logger.hpp>
namespace
cv
{
...
...
@@ -100,13 +101,27 @@ void blobFromImagesWithParams(InputArrayOfArrays images_, OutputArray blob_, con
images_
.
getMatVector
(
images
);
CV_Assert
(
!
images
.
empty
());
if
(
param
.
ddepth
==
CV_8U
)
{
CV_Assert
(
param
.
scalefactor
==
Scalar
::
all
(
1.0
)
&&
"Scaling is not supported for CV_8U blob depth"
);
CV_Assert
(
param
.
mean
==
Scalar
()
&&
"Mean subtraction is not supported for CV_8U blob depth"
);
}
int
nch
=
images
[
0
].
channels
();
Scalar
scalefactor
=
param
.
scalefactor
;
Scalar
mean
=
param
.
mean
;
if
(
param
.
ddepth
==
CV_8U
)
if
(
param
.
swapRB
)
{
CV_Assert
(
scalefactor
==
Scalar
::
all
(
1.0
)
&&
"Scaling is not supported for CV_8U blob depth"
);
CV_Assert
(
param
.
mean
==
Scalar
()
&&
"Mean subtraction is not supported for CV_8U blob depth"
);
if
(
nch
>
2
)
{
std
::
swap
(
mean
[
0
],
mean
[
2
]);
std
::
swap
(
scalefactor
[
0
],
scalefactor
[
2
]);
}
else
{
CV_LOG_WARNING
(
NULL
,
"Red/blue color swapping requires at least three image channels."
);
}
}
for
(
size_t
i
=
0
;
i
<
images
.
size
();
i
++
)
...
...
@@ -126,34 +141,26 @@ void blobFromImagesWithParams(InputArrayOfArrays images_, OutputArray blob_, con
size
);
images
[
i
]
=
images
[
i
](
crop
);
}
else
if
(
param
.
paddingmode
==
DNN_PMODE_LETTERBOX
)
{
float
resizeFactor
=
std
::
min
(
size
.
width
/
(
float
)
imgSize
.
width
,
size
.
height
/
(
float
)
imgSize
.
height
);
int
rh
=
int
(
imgSize
.
height
*
resizeFactor
);
int
rw
=
int
(
imgSize
.
width
*
resizeFactor
);
resize
(
images
[
i
],
images
[
i
],
Size
(
rw
,
rh
),
INTER_LINEAR
);
int
top
=
(
size
.
height
-
rh
)
/
2
;
int
bottom
=
size
.
height
-
top
-
rh
;
int
left
=
(
size
.
width
-
rw
)
/
2
;
int
right
=
size
.
width
-
left
-
rw
;
copyMakeBorder
(
images
[
i
],
images
[
i
],
top
,
bottom
,
left
,
right
,
BORDER_CONSTANT
);
}
else
{
if
(
param
.
paddingmode
==
DNN_PMODE_LETTERBOX
)
{
float
resizeFactor
=
std
::
min
(
size
.
width
/
(
float
)
imgSize
.
width
,
size
.
height
/
(
float
)
imgSize
.
height
);
int
rh
=
int
(
imgSize
.
height
*
resizeFactor
);
int
rw
=
int
(
imgSize
.
width
*
resizeFactor
);
resize
(
images
[
i
],
images
[
i
],
Size
(
rw
,
rh
),
INTER_LINEAR
);
int
top
=
(
size
.
height
-
rh
)
/
2
;
int
bottom
=
size
.
height
-
top
-
rh
;
int
left
=
(
size
.
width
-
rw
)
/
2
;
int
right
=
size
.
width
-
left
-
rw
;
copyMakeBorder
(
images
[
i
],
images
[
i
],
top
,
bottom
,
left
,
right
,
BORDER_CONSTANT
);
}
else
resize
(
images
[
i
],
images
[
i
],
size
,
0
,
0
,
INTER_LINEAR
);
resize
(
images
[
i
],
images
[
i
],
size
,
0
,
0
,
INTER_LINEAR
);
}
}
Scalar
mean
=
param
.
mean
;
if
(
param
.
swapRB
)
{
std
::
swap
(
mean
[
0
],
mean
[
2
]);
std
::
swap
(
scalefactor
[
0
],
scalefactor
[
2
]);
}
if
(
images
[
i
].
depth
()
==
CV_8U
&&
param
.
ddepth
==
CV_32F
)
images
[
i
].
convertTo
(
images
[
i
],
CV_32F
);
...
...
@@ -220,18 +227,22 @@ void blobFromImagesWithParams(InputArrayOfArrays images_, OutputArray blob_, con
CV_Assert
(
image
.
depth
()
==
blob_
.
depth
());
CV_Assert
(
image
.
channels
()
==
image0
.
channels
());
CV_Assert
(
image
.
size
()
==
image0
.
size
());
if
(
param
.
swapRB
)
if
(
nch
>
2
&&
param
.
swapRB
)
{
Mat
tmpRB
;
cvtColor
(
image
,
tmpRB
,
COLOR_BGR2RGB
);
tmpRB
.
copyTo
(
Mat
(
tmpRB
.
rows
,
tmpRB
.
cols
,
subMatType
,
blob
.
ptr
((
int
)
i
,
0
)));
}
else
{
image
.
copyTo
(
Mat
(
image
.
rows
,
image
.
cols
,
subMatType
,
blob
.
ptr
((
int
)
i
,
0
)));
}
}
}
else
{
CV_Error
(
Error
::
StsUnsupportedFormat
,
"Unsupported data layout in blobFromImagesWithParams function."
);
}
}
void
imagesFromBlob
(
const
cv
::
Mat
&
blob_
,
OutputArrayOfArrays
images_
)
...
...
modules/dnn/test/test_misc.cpp
浏览文件 @
5350fba3
...
...
@@ -120,6 +120,28 @@ TEST(blobFromImageWithParams_4ch, letter_box)
EXPECT_EQ
(
0
,
cvtest
::
norm
(
targetBlob
,
blob
,
NORM_INF
));
}
TEST
(
blobFromImagesWithParams_4ch
,
multi_image
)
{
Mat
img
(
10
,
10
,
CV_8UC4
,
cv
::
Scalar
(
0
,
1
,
2
,
3
));
Scalar
scalefactor
(
0.1
,
0.2
,
0.3
,
0.4
);
Image2BlobParams
param
;
param
.
scalefactor
=
scalefactor
;
param
.
datalayout
=
DNN_LAYOUT_NHWC
;
Mat
blobs
=
blobFromImagesWithParams
(
std
::
vector
<
Mat
>
{
img
,
2
*
img
},
param
);
vector
<
Range
>
ranges
;
ranges
.
push_back
(
Range
(
0
,
1
));
ranges
.
push_back
(
Range
(
0
,
blobs
.
size
[
1
]));
ranges
.
push_back
(
Range
(
0
,
blobs
.
size
[
2
]));
ranges
.
push_back
(
Range
(
0
,
blobs
.
size
[
3
]));
Mat
blob0
=
blobs
(
ranges
);
ranges
[
0
]
=
Range
(
1
,
2
);
Mat
blob1
=
blobs
(
ranges
);
EXPECT_EQ
(
0
,
cvtest
::
norm
(
2
*
blob0
,
blob1
,
NORM_INF
));
}
TEST
(
readNet
,
Regression
)
{
Net
net
=
readNet
(
findDataFile
(
"dnn/squeezenet_v1.1.prototxt"
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录