Skip to content

Instantly share code, notes, and snippets.

@parthpower
Last active April 4, 2017 20:59
Show Gist options
  • Save parthpower/0e2d0379b80ee1274507 to your computer and use it in GitHub Desktop.
Save parthpower/0e2d0379b80ee1274507 to your computer and use it in GitHub Desktop.
Simple gray scale image data to COE file convertor for Xilinx Block Memory initialization
__author__ = 'Parth Parikh'
import sys
import cv2
def help1():
print "Usage: imgtocoe <image path> <output name>"
exit()
if len(sys.argv) <3:
help1()
img = cv2.imread(sys.argv[1])
img = cv2.cvtColor(img,cv2.cv.CV_RGB2GRAY)
r, c = img.shape
fp = open(sys.argv[2],'w')
fp.write("memory_initialization_radix=10;\n")
fp.write("memory_initialization_vector=")
print "Writing COE Data..."
for i in range(r):
for j in range(c):
if i == r-1 and j == c -1:
fp.write(str(img[i][j])+";")
else:
fp.write(str(img[i][j])+",")
fp.close()
print "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment