zoukankan      html  css  js  c++  java
  • FPGA开发小程序——图像数据转换.coe文件

    因为开发需要,编写了一个图像数据转换成.coe 文件的小程序,发布出来给有需要的人

    1.先给出源程序

    import tkinter as tk
    from tkinter import filedialog
    import os
    application_window = tk.Tk()
    my_filetypes = [('all files', '.*'), ('text files', '.txt')]
    answer = filedialog.askopenfilename(parent=application_window,
                                        initialdir=os.getcwd(),
                                        title="请选择文件:",
                                        filetypes=my_filetypes)#对话框选择文件
    k = os.path.basename(answer)#获取文件名
    def func(f):
        a = f.readlines()
        return a
    with open(answer,encoding='utf-8') as f, open('answer.bak','w',encoding='utf-8') as f2:
        s = func(f)#取出所有行形成一个列表
        s.pop(0)#删除第0个元素也就是0行
        s.insert(0,'memory_initialization_radix=16;
    memory_initialization_vector=
    ')#在第0行添加.coe文件头
        s1 = ''.join(s)#将列表转成字符串
        s2 = s1.replace('
    ','')#去掉换行符
        s3 = s2.replace(',','')#去掉逗号
        s4 = s3.replace('}','')#去掉}
        s5 = s4.replace('0X','')#去掉0X
        l = 0
        while l < len(s5):
            f2.write(s5[l])
            if l == 30:#在字符memory_initialization_radix=16;后面加入换行符
                f2.write('
    ')
            if l > 59 or l == 59:#将.coe文件头写入answer.bak
                if (l + 1) % 6 == 0:#6个字符分成一组,因为是16进制数,所以形成的数据位宽是4bit*6 = 24bit
                    if (l + 1) % 60 == 0:#10个组分成一行
                        f2.write('
    ')
                    else:
                        f2.write(' ')
            l += 1
    # os.remove('answer')
    os.rename('answer.bak',k.replace('.c','.coe'))#将文件转换成.coe文件
    print("转换成功!")
    import time
    time.sleep(2)

    2.操作流程

    首先需要有一张图片,然后用Img2Lcd.exe软件转成对应的c语言数组的.c文件,转换成功后就可以用我的小程序了

    废话不多说,有图有真相

    双击我的小程序文件

    会弹出文件选择对话框

    选择.c文件之后会自动转换成.coe文件

    此文件可以直接放到xilinx的romIP中使用,如需要其他位宽请自行修改代码

    .exe文件百度网盘链接:

    链接:https://pan.baidu.com/s/1Uxsjdskx8G7xNIoPhhBtrw
    提取码:2jsa

  • 相关阅读:
    centos配置WordPress(Apache+mysql+php)
    sublime text3配置Python2、Python3的编译环境
    Python3——字典
    Python3基础——函数
    Python3基础——递归
    Python3基础——字符串类型
    activiti会签直接写死人员
    delete执行速度优化
    C盘空间满了怎么办
    python运算符
  • 原文地址:https://www.cnblogs.com/jian-jia/p/13215465.html
Copyright © 2011-2022 走看看