Commit 3470b58a authored by chsin's avatar chsin Committed by Mark Daoust
Browse files

Support for non-TYPE_3BYTE_BGR images

parent 443461cc
...@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment