Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
3470b58a
Commit
3470b58a
authored
Apr 10, 2019
by
chsin
Committed by
Mark Daoust
Jul 30, 2019
Browse files
Support for non-TYPE_3BYTE_BGR images
parent
443461cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
4 deletions
+5
-4
samples/languages/java/object_detection/src/main/java/DetectObjects.java
...es/java/object_detection/src/main/java/DetectObjects.java
+5
-4
No files found.
samples/languages/java/object_detection/src/main/java/DetectObjects.java
View file @
3470b58a
...
@@ -147,11 +147,12 @@ public class DetectObjects {
...
@@ -147,11 +147,12 @@ public class DetectObjects {
private
static
Tensor
<
UInt8
>
makeImageTensor
(
String
filename
)
throws
IOException
{
private
static
Tensor
<
UInt8
>
makeImageTensor
(
String
filename
)
throws
IOException
{
BufferedImage
img
=
ImageIO
.
read
(
new
File
(
filename
));
BufferedImage
img
=
ImageIO
.
read
(
new
File
(
filename
));
if
(
img
.
getType
()
!=
BufferedImage
.
TYPE_3BYTE_BGR
)
{
if
(
img
.
getType
()
!=
BufferedImage
.
TYPE_3BYTE_BGR
)
{
throw
new
IOException
(
BufferedImage
newImage
=
new
BufferedImage
(
String
.
format
(
img
.
getWidth
(),
img
.
getHeight
(),
BufferedImage
.
TYPE_3BYTE_BGR
);
"Expected 3-byte BGR encoding in BufferedImage, found %d (file: %s). This code could be made more robust"
,
newImage
.
createGraphics
().
drawImage
(
img
,
0
,
0
,
img
.
getWidth
(),
img
.
getHeight
(),
null
);
img
.
getType
(),
filename
))
;
img
=
newImage
;
}
}
byte
[]
data
=
((
DataBufferByte
)
img
.
getData
().
getDataBuffer
()).
getData
();
byte
[]
data
=
((
DataBufferByte
)
img
.
getData
().
getDataBuffer
()).
getData
();
// ImageIO.read seems to produce BGR-encoded images, but the model expects RGB.
// ImageIO.read seems to produce BGR-encoded images, but the model expects RGB.
bgr2rgb
(
data
);
bgr2rgb
(
data
);
...
...
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