Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv_contrib
Commits
78fabfe6
Commit
78fabfe6
authored
May 25, 2017
by
Aleksandr Rybnikov
Committed by
Vadim Pisarevsky
May 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed blobFromImages() function, so it can handle 1-channel images (#1185)
parent
1ca1a125
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
40 deletions
+50
-40
dnn.cpp
modules/dnn/src/dnn.cpp
+50
-40
No files found.
modules/dnn/src/dnn.cpp
View file @
78fabfe6
...
...
@@ -70,25 +70,8 @@ static String toString(const T &v)
Mat
blobFromImage
(
const
Mat
&
image_
,
double
scalefactor
,
bool
swapRB
)
{
Mat
image
;
if
(
image_
.
depth
()
==
CV_8U
)
{
image_
.
convertTo
(
image
,
CV_32F
,
scalefactor
);
}
else
image
=
image_
;
CV_Assert
(
image
.
dims
==
2
&&
image
.
depth
()
==
CV_32F
);
int
nch
=
image
.
channels
();
CV_Assert
(
nch
==
3
||
nch
==
4
);
int
sz
[]
=
{
1
,
3
,
image
.
rows
,
image
.
cols
};
Mat
blob
(
4
,
sz
,
CV_32F
);
Mat
ch
[
4
];
for
(
int
j
=
0
;
j
<
3
;
j
++
)
ch
[
j
]
=
Mat
(
image
.
rows
,
image
.
cols
,
CV_32F
,
blob
.
ptr
(
0
,
j
));
if
(
swapRB
)
std
::
swap
(
ch
[
0
],
ch
[
2
]);
split
(
image
,
ch
);
return
blob
;
std
::
vector
<
Mat
>
images
(
1
,
image_
);
return
blobFromImages
(
images
,
scalefactor
,
swapRB
);
}
Mat
blobFromImages
(
const
std
::
vector
<
Mat
>&
images
,
double
scalefactor
,
bool
swapRB
)
...
...
@@ -98,30 +81,57 @@ Mat blobFromImages(const std::vector<Mat>& images, double scalefactor, bool swap
return
Mat
();
Mat
image0
=
images
[
0
];
int
nch
=
image0
.
channels
();
CV_Assert
(
image0
.
dims
==
2
&&
(
nch
==
3
||
nch
==
4
));
int
sz
[]
=
{
(
int
)
nimages
,
3
,
image0
.
rows
,
image0
.
cols
};
Mat
blob
(
4
,
sz
,
CV_32F
),
image
;
Mat
ch
[
4
];
for
(
i
=
0
;
i
<
nimages
;
i
++
)
CV_Assert
(
image0
.
dims
==
2
);
Mat
blob
,
image
;
if
(
nch
==
3
||
nch
==
4
)
{
Mat
image_
=
images
[
i
];
if
(
image_
.
depth
()
==
CV_8U
)
int
sz
[]
=
{
(
int
)
nimages
,
3
,
image0
.
rows
,
image0
.
cols
};
blob
=
Mat
(
4
,
sz
,
CV_32F
);
Mat
ch
[
4
];
for
(
i
=
0
;
i
<
nimages
;
i
++
)
{
image_
.
convertTo
(
image
,
CV_32F
,
scalefactor
);
Mat
image_
=
images
[
i
];
if
(
image_
.
depth
()
==
CV_8U
)
{
image_
.
convertTo
(
image
,
CV_32F
,
scalefactor
);
}
else
image
=
image_
;
CV_Assert
(
image
.
depth
()
==
CV_32F
);
nch
=
image
.
channels
();
CV_Assert
(
image
.
dims
==
2
&&
(
nch
==
3
||
nch
==
4
));
CV_Assert
(
image
.
size
()
==
image0
.
size
());
for
(
int
j
=
0
;
j
<
3
;
j
++
)
ch
[
j
]
=
Mat
(
image
.
rows
,
image
.
cols
,
CV_32F
,
blob
.
ptr
((
int
)
i
,
j
));
if
(
swapRB
)
std
::
swap
(
ch
[
0
],
ch
[
2
]);
split
(
image
,
ch
);
}
else
image
=
image_
;
CV_Assert
(
image
.
depth
()
==
CV_32F
);
nch
=
image
.
channels
();
CV_Assert
(
image
.
dims
==
2
&&
(
nch
==
3
||
nch
==
4
));
CV_Assert
(
image
.
size
()
==
image0
.
size
());
for
(
int
j
=
0
;
j
<
3
;
j
++
)
ch
[
j
]
=
Mat
(
image
.
rows
,
image
.
cols
,
CV_32F
,
blob
.
ptr
((
int
)
i
,
j
));
if
(
swapRB
)
std
::
swap
(
ch
[
0
],
ch
[
2
]);
split
(
image
,
ch
);
}
else
{
CV_Assert
(
nch
==
1
);
int
sz
[]
=
{
(
int
)
nimages
,
1
,
image0
.
rows
,
image0
.
cols
};
blob
=
Mat
(
4
,
sz
,
CV_32F
);
for
(
i
=
0
;
i
<
nimages
;
i
++
)
{
Mat
image_
=
images
[
i
];
if
(
image_
.
depth
()
==
CV_8U
)
{
image_
.
convertTo
(
image
,
CV_32F
,
scalefactor
);
}
else
image
=
image_
;
CV_Assert
(
image
.
depth
()
==
CV_32F
);
nch
=
image
.
channels
();
CV_Assert
(
image
.
dims
==
2
&&
(
nch
==
1
));
CV_Assert
(
image
.
size
()
==
image0
.
size
());
image
.
copyTo
(
Mat
(
image
.
rows
,
image
.
cols
,
CV_32F
,
blob
.
ptr
((
int
)
i
,
0
)));
}
}
return
blob
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment