Introduce image importer (#205)
author김정현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh0822.kim@samsung.com>
Mon, 26 Mar 2018 07:25:31 +0000 (16:25 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 26 Mar 2018 07:25:31 +0000 (16:25 +0900)
This commit introduces image importer to convert
jpeg or png images to bin.
The binary file only has the pixel values.
It does not have size.
The output will be used for `tflite_run`.

Signed-off-by: Junghyun Kim <jh0822.kim@samsung.com>
tools/image_importer/image_importer.py [new file with mode: 0755]

diff --git a/tools/image_importer/image_importer.py b/tools/image_importer/image_importer.py
new file mode 100755 (executable)
index 0000000..26aa2e4
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+from PIL import Image
+import sys
+import struct
+
+if( len(sys.argv) < 3 ):
+    print("Usage: %s <input image file> <output bin file>"%(sys.argv[0]));
+    exit(0)
+
+img = Image.open(sys.argv[1])
+outfile = sys.argv[2]
+
+print "Image format = ", img.bits, img.size, img.format
+
+with open(outfile, 'wb') as f:
+    f.write(img.tobytes())
+
+print "Done."