在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1631|回复: 3

[原创] Linux下用convert将RGB/YCbCr格式输出的txt转JPG

[复制链接]
发表于 2023-2-10 10:58:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x

前提:linux安装了ImageMagick(里面包含convert指令),会基本的verilog文件输出函数以生成所需txt文件格式。
1. txt 的格式

       首行是格式声明,包含(尺寸,位宽最大值,格式)
              例: 尺寸宽640x高480,位宽8,格式RGB,则首行为 “# ImageMagick pixel enumeration:         640,        480,255,RGB”
       其余行是输出像素数据,包含(坐标,数值)
              例:行坐标为0,列坐标为1,R=1,G=2,B=3, 则该像素的格式为“1,0: (1, 2, 3)”


                               
登录/注册后可看大图
            

                               
登录/注册后可看大图


2. 转换指令



     convert RGB.txt RGB.jpg
     convert YCbCr.txt YCbCr.jpg
 楼主| 发表于 2023-2-10 11:12:25 | 显示全部楼层
 楼主| 发表于 2025-5-16 09:42:52 | 显示全部楼层
#!/bin/sh
if [ $# != 1 ]; then
    echo "Usage: $0 [FileName]"
    exit 1
else
    file=$1
    if [ ! -f "$file" ];then
        echo "$file does not exit!"
        exit 1
    else
        rm result.log
        for line in `cat $1`
        do
#            ./run_sim_cmd.csh $line
            cnt_error=$(grep *E $line/work/irun_rtl.log | wc -l)
            if [ $cnt_error != 0 ];then
                echo "$line: NG" >> result.log
            else
                echo "$line: OK" >> result.log
            fi
        done
    fi
fi
 楼主| 发表于 2025-5-16 17:24:42 | 显示全部楼层
#!/usr/bin/python3
import numpy as np
import cv2
import os
import sys

argv = sys.argv[1:]
tc_name = argv[0]

src_path = os.path.join(tc_name, 'image/')
sav_path = os.path.join(tc_name, 'video.avi')

image_size = (18,18)
video_size = (18*20,18*20)
image_length = image_size[0]*image_size[1]
fps = 1
color = 0
fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
videowrite = cv2.VideoWriter(sav_path, fourcc, fps, video_size, color)
print("Picture size: {}".format(image_size))
print("Video size: {}".format(video_size))

all_files = os.listdir(src_path)
index = len(all_files)
print("Picture num:" + str(index))

img_array=[]
for filename in [src_path + r'{0}.raw'.format(i) for i in range(0,index)]:
    with open(filename, 'rb') as file:
        raw_data = file.read()
        img = np.frombuffer(raw_data, dtype=np.uint8)
        img = np.pad(img, (0, image_length - len(img)))     # when img_length is not enough, add 0 to fill the size
        img = img.reshape(image_size)
        img_array.append(img)

for i in range(0,index):
    img_array[i] = cv2.resize(img_array[i],video_size,interpolation=cv2.INTER_NEAREST)
    videowrite.write(img_array[i])
    #print(img_array[i])
videowrite.release()
print('------done!!!-------')
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

X

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-6-6 01:11 , Processed in 0.018660 second(s), 7 queries , Gzip On, MemCached On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表