当前位置: 首页 > news >正文

电商网站建设课程大连手机自适应网站建设报价

电商网站建设课程,大连手机自适应网站建设报价,进博会上海2022,商丘网站公司工作小记-YUV的dump和read 工作杂记-YUV的dump和read利用dump生成图片 yuv2imgyuv2img代码 工作杂记-YUV的dump和read 工作中涉及到模型验证相关的工作#xff0c;这里是三个模型的共同作用#xff0c;在感知模型读取图片的时候#xff0c;把输入替换成自己给定的输入… 工作小记-YUV的dump和read 工作杂记-YUV的dump和read利用dump生成图片 yuv2imgyuv2img代码 工作杂记-YUV的dump和read 工作中涉及到模型验证相关的工作这里是三个模型的共同作用在感知模型读取图片的时候把输入替换成自己给定的输入保证一致性再来看输出。 知道了模型输入的宽高和步长之后有如下的dump_yuv和read_yuv函数。其中bpu_addr和bpu_addr_uv是y分量和uv分量的地址。 bool ReadYUVImage(const std::string img_path, int width, int height,uint64_t bpu_addr, uint64_t bpu_addr_uv) {std::ifstream input_img_file(img_path, std::ios::binary);input_img_file.seekg(0, std::ios::end);int len input_img_file.tellg();input_img_file.seekg(0, std::ios::beg);std::vectoruint8_t img_data(width * height * 3 / 2);if (len width * height * 3 / 2) {HSLOG_E file length is not right len img_file: img_path;return false;} else {input_img_file.read(reinterpret_castchar *(img_data.data()),width * height * 3 / 2);memcpy(reinterpret_castvoid *(bpu_addr), img_data.data(), width * height);memcpy(reinterpret_castvoid *(bpu_addr_uv),img_data.data() width * height, width * height / 2);}input_img_file.close();return true; }void DumpYUVImage(const std::string out_file, int width, int height,uint64_t bpu_addr, uint64_t bpu_addr_uv) {std::ofstream fout(out_file, std::ios::out | std::ios::binary);std::vectoruint8_t src_input_image(width * height * 3 / 2);memcpy(src_input_image.data(), reinterpret_castvoid *(bpu_addr),width * height);memcpy(src_input_image.data() width * height,reinterpret_castvoid *(bpu_addr_uv), width * height / 2);fout.write(reinterpret_castchar *(src_input_image.data()),width * height * 3 / 2);fout.close(); }利用dump生成图片 yuv2img 这里需要了解yuv相关的排布知识。 YUV格式有两大类planar和packed。 对于planar的YUV格式先连续存储所有像素点的Y紧接着存储所有像素点的U随后是所有像素点的V。 对于packed的YUV格式每个像素点的Y,U,V是连续交*存储的。 YUV分为三个分量“Y”表示明亮度Luminance或Luma也就是灰度值而“U”和“V” 表示的则是色度Chrominance或Chroma作用是描述影像色彩及饱和度用于指定像素的颜色。 planar的YUV格式分为YUV420P和YUV420SPYUV420P包含I420和YV12。I420格式和YV12格式的不同处在U平面和V平面的位置不同。在I420格式中U平面紧跟在Y平面之后然后才是V平面即YUV但YV12则是相反即YVU。 YUV420SP, Y分量平面格式UV打包格式, 即NV12。 NV12与NV21类似U 和 V 交错排列,不同在于UV顺序。 I420: YYYYYYYY UU VV YUV420P YV12: YYYYYYYY VV UU YUV420P NV12: YYYYYYYY UVUV YUV420SP NV21: YYYYYYYY VUVU YUV420SP 注意转化时要知道文件的uv排列先后顺序实测uv颠倒后的图片色差会有变化。 正确的结果 错误的结果 核心代码这里有一个opencv的坑在merge时 会报错Invalid number of channels in input image: ‘VScn::contains(scn)’ ‘scn’原因时Y U V的shape不一致解决方案时把UV插值成和Y一样的在merge这样shape就成了(hw3)这种形式。再调用cv2.COLOR_YUV2BGR去做转化。 # 分离UV通道为U和VU UV[:, ::2]V UV[:, 1::2]# 扩展U和V通道为与Y通道一致的大小U cv2.resize(U, (width, height), interpolationcv2.INTER_LINEAR)V cv2.resize(V, (width, height), interpolationcv2.INTER_LINEAR)# 合并Y、U、V通道数据YUV420p_image cv2.merge((Y, U, V))# 转换为RGB格式image_rgb cv2.cvtColor(YUV420p_image, cv2.COLOR_YUV2BGR)yuv2img代码 如下是根据dump的yuv文件生成图片其中三个函数分别为灰度(only y 分量)420sp直接转RGB420sp 提取 U、V分量后再插值和Y分量组成YUV444再转成RGB。 Y np.frombuffer(buffer[:Y_size], dtypenp.uint8).reshape(height, width) UV np.frombuffer(buffer[Y_size:], dtypenp.uint8).reshape(height // 2, width)# 分离UV通道为U和V U UV[:, ::2] # 实际上是选择 UV 数组的所有行但只选择每一行中的偶数列元素即第0列、第2列、第4列等 V UV[:, 1::2] # 扩展U和V通道为与Y通道一致的大小 U cv2.resize(U, (width, height), interpolationcv2.INTER_LINEAR) V cv2.resize(V, (width, height), interpolationcv2.INTER_LINEAR)# 合并Y、U、V通道数据 YUV420p_image cv2.merge((Y, U, V))import cv2 import numpy as np import re import osdef convert_YUV420sp_RGB(yuv_file):# 从文件名中提取宽度和高度match re.search(r_w_(\d)_h_(\d), yuv_file)if match:width int(match.group(1))height int(match.group(2))else:print(无法提取分辨率信息:, yuv_file)returnprint(width, height)with open(yuv_file, rb) as f:buffer f.read()image np.frombuffer(buffer, np.uint8).reshape(height*3//2, width)print(image.size, image.shape)image_rgb cv2.cvtColor(image, cv2.COLOR_YUV420SP2RGB)yuv_file os.path.basename(yuv_file)output_file yuv_file.replace(.yuv, .jpg)output_file os.path.join(output_folder_path, f{output_file}.jpg)cv2.imwrite(output_file, image_rgb)# print(output_file)def convert_YUV420sp_YUV444_RGB(yuv_file):# 从文件名中提取宽度和高度match re.search(r_w_(\d)_h_(\d), yuv_file)if match:width int(match.group(1))height int(match.group(2))else:print(无法提取分辨率信息:, yuv_file)return# 读取YUV420sp图像数据with open(yuv_file, rb) as f:buffer f.read()# 解析Y、UV通道数据Y_size width * heightUV_size width * height // 2Y np.frombuffer(buffer[:Y_size], dtypenp.uint8).reshape(height, width)UV np.frombuffer(buffer[Y_size:], dtypenp.uint8).reshape(height // 2, width)# 分离UV通道为U和VU UV[:, ::2]V UV[:, 1::2]# 扩展U和V通道为与Y通道一致的大小U cv2.resize(U, (width, height), interpolationcv2.INTER_LINEAR)V cv2.resize(V, (width, height), interpolationcv2.INTER_LINEAR)# 合并Y、U、V通道数据YUV420p_image cv2.merge((Y, U, V))# 转换为RGB格式image_rgb cv2.cvtColor(YUV420p_image, cv2.COLOR_YUV2BGR)yuv_file os.path.basename(yuv_file)output_file yuv_file.replace(.yuv, .jpg)output_file os.path.join(output_folder_path, f{output_file}.jpg)cv2.imwrite(output_file, image_rgb)# print(output_file)def convert_YUV420sp_GRAY(yuv_file):file_name os.path.splitext(yuv_file)[0]match re.search(r_w_(\d)_h_(\d), yuv_file)if match:width int(match.group(1))height int(match.group(2))else:print(无法提取分辨率信息:, yuv_file)return# 打开YUV文件并读取数据with open(yuv_file, rb) as file:buffer file.read()Y_size width * heightY_data buffer[:Y_size]# 将Y数据转换为NumPy数组Y np.frombuffer(Y_data, dtypenp.uint8).reshape((height, width))gray_image cv2.cvtColor(Y, cv2.COLOR_GRAY2BGR)yuv_file os.path.basename(yuv_file)output_file yuv_file.replace(.yuv, .jpg)output_file os.path.join(output_folder_path, f{output_file}.jpg)cv2.imwrite(output_file, gray_image)return# 定义输入YUV文件夹路径 input_folder_path ./dump_yuv # 替换为包含YUV文件的文件夹路径# 定义输出JPEG文件夹路径 output_folder_path input_folder_path _output # 保存JPEG文件的文件夹路径 if not os.path.exists(output_folder_path):os.makedirs(output_folder_path)# 获取输入文件夹中的所有YUV文件 yuv_files [file for file in os.listdir(input_folder_path) if file.endswith(.yuv)]for yuv_file in yuv_files:print(yuv_file)# convert_YUV420sp_YUV444_RGB(input_folder_path / yuv_file)# convert_YUV420sp_RGB(input_folder_path / yuv_file)convert_YUV420sp_GRAY(input_folder_path / yuv_file)model_id:0 percepts_[0] rect num:1 model_id:0 rect:388.95 1034.04 520.791 1163.19 7.03816 0 model_id:0 percepts_[5] rect num:8 model_id:0 rect:2164.7 1034.81 2261.26 1110.25 8.7623 5 model_id:0 rect:2464.56 996.751 2519.25 1059.25 7.19807 5 model_id:0 rect:2654.99 593.22 2744.83 696.733 8.5591 5 model_id:0 rect:2914.5 570.069 3007.19 666.134 8.76954 5 model_id:0 rect:3044.18 553.215 3152.04 664.448 8.68193 5 model_id:0 rect:3185.64 543.125 3295.19 652.673 7.15572 5 model_id:0 rect:3750.75 609.548 3836 781.291 8.73659 5 model_id:0 rect:3761.16 792.687 3836 1073.72 9.44854 5 model_id:0 percepts_[11] rect num:3 model_id:0 rect:247.464 1250.77 334.153 1311.08 7.29449 11 model_id:0 rect:1664.7 1409.73 2243.79 1526.45 7.30121 11 model_id:0 rect:3057.62 1149.15 3528.76 1186.85 7.29843 11 model_id:0 percepts_[13] rect num:3 model_id:0 rect:1390.61 1212.43 1441.98 1423.03 8.79426 13 model_id:0 rect:1992.3 1189.52 2025.68 1335.91 7.29169 13 model_id:0 rect:2816.59 1182.99 2865.39 1378.19 7.29921 13再额外附一段画框的代码 import cv2 import re# 读取图片 image_path ./dump_yuv_v3_output/model_50_frame_1694608049106_w_3840_h_2160.jpg.jpg image cv2.imread(image_path)# 打开包含矩形框坐标的文件 with open(rect.txt, r) as file:lines file.readlines()# 正则表达式模式用于匹配包含model_id和percepts的行 model_pattern re.compile(rmodel_id:\d percepts_\[(\d)\] rect num:(\d))# 正则表达式模式用于匹配包含model_id和rect的行 rect_pattern re.compile(rmodel_id:\d rect:(\d(?:\.\d)?) (\d(?:\.\d)?) (\d(?:\.\d)?) (\d(?:\.\d)?))# 初始化一个字典来存储percepts_值和颜色的映射 percepts_color_mapping {0: (0, 0, 255), # 红色5: (0, 255, 0), # 绿色11: (255, 0, 0), # 蓝色13: (0, 255, 255), # 黄色 }# 遍历文件中的每一行 for line in lines:# 尝试匹配包含矩形坐标的行model_match model_pattern.match(line)if model_match:percept_index model_match.group(1)num_rects model_match.group(2)print(fPercept Index: {percept_index})print(fNumber of Rectangles: {num_rects})# 匹配对应的框rect_match rect_pattern.search(line)if rect_match:x1, y1, x2, y2 map(float, rect_match.groups())# 获取颜色color percepts_color_mapping.get(percept_index) # 默认为红色# 绘制矩形框x1, y1, x2, y2 int(x1), int(y1), int(x2), int(y2)print(x1, y1, x2, y2)cv2.rectangle(image, (x1, y1), (x2, y2), color, 2)font cv2.FONT_HERSHEY_SIMPLEXcv2.putText(image, str(percept_index), (x1, y1 - 10), font, 0.5, color, 1, cv2.LINE_AA)# 保存包含绘制框的图像 output_image_path output_image.png cv2.imwrite(output_image_path, image)# 保存包含绘制框的图像 output_image_path output_image.png cv2.imwrite(output_image_path, image)
http://www.pierceye.com/news/949516/

相关文章:

  • wordpress网站需要多大空间建设营销型网站
  • id97网站怎么做的项目营销策划方案
  • 站群网站怎么做缓存
  • 网站(网店)建设方案范文北京网站搭建服务
  • 建设银行网站怎么设置转账额度百度竞价培训班
  • 八大员继续教育入口做优化网站注意什么
  • 网络空间服务商宁波seo网络推广推荐公众号
  • 网站登录注册做验证码的目地汕头网站建设浩森宇特
  • 做鼻翼整形整形的网站开原网站开发
  • 宿州专业网站建设学做app
  • 宁德商城网站开发设计个人网站在那建设
  • 培训网站建设情况淄博网站排名优化
  • 运营一个网站的成本网络营销第二板斧是什么
  • 企业建站报价手机网站开发开发
  • 足彩网站怎样做推广友情链接官网
  • 十大免费音乐网站网络营销策划推广公司有哪些
  • 免费开源代码网站上海企业建设网站
  • 万家灯火网站建设win7系统做网站服务器
  • 网站直播用php怎么做做家旅游的视频网站好
  • 平台网站建设方案查看自己电脑的网站开发语言
  • 织梦如何做网站地图建设一个网站用什么软件下载
  • 建设银行互联网网站怎么制作小程序软件
  • 做购物网站平台视觉比较好看的网站
  • 网站建设要做什么会计科目网站建设的展望 视频
  • 那种广告式网站怎么做网站为什么具有网络营销价值
  • 包头建站怎么下载网站动态图片
  • 大企业网站建设哪里好qq网站登录入口
  • 手机网站有什么区别是什么wordpress模板2zzt
  • 想做个网站报价蔬菜价格怎么做公司做网站一般多少钱
  • 南宁老牌网站建设公司公司网站搭建教程