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

json格式存储b64编码的rgb raw数据

1.rgb raw数据准备

利用python将jpg里面的rgb raw数据提取出来。

import cv2# 读取 JPG 图像
image_path = '1.jpg'
image = cv2.imread(image_path)#imread读出来的顺序是BGR
print("image shape:",image.shape)# 将图像由BGR转换为 RGB 数据
rgb_data = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# cv2.imwrite() function is used to save the RGB data to a file. 
# The output_path variable specifies the path and filename for the output file, which should have a JPG extension
#output_path = 'output'
#cv2.imwrite(output_path,rgb_data)
# 将RGB存为RAW数据
output_path = 'rgb.raw'
rgb_data.tofile(output_path)

1.1 查看raw数据

在这里插入图片描述

2.代码实现

在这里插入图片描述

2.1 cjson库:https://github.com/DaveGamble/cJSON

2.2 base64库:https://github.com/jwerle/b64.c

2.3 工程目录

在这里插入图片描述

#include <stdio.h>
#include "cjson/cJSON.h"
#include "b64.c-0.1.0/b64.c-0.1.0/b64.h"
#include <stdlib.h>
int main()
{cJSON* json_test = cJSON_CreateObject();cJSON_AddNumberToObject(json_test, "emiss", 95);cJSON* json_point1 = cJSON_CreateObject();cJSON_AddNumberToObject(json_point1, "x", 0);cJSON_AddNumberToObject(json_point1, "y", 0);cJSON* json_point2 = cJSON_CreateObject();cJSON_AddNumberToObject(json_point2, "x", 0);cJSON_AddNumberToObject(json_point2, "y", 0);cJSON* json_points = cJSON_CreateArray();cJSON_AddItemToArray(json_points, json_point1);cJSON_AddItemToArray(json_points, json_point2);cJSON* json_point = cJSON_CreateObject();cJSON_AddItemToObject(json_test, "point", json_points);FILE* fp = fopen("rgb.raw", "rb+");char* buf = NULL;int len = 0;if (fp) {fseek(fp, 0, SEEK_END);len = ftell(fp);buf = (char*)malloc(len);fseek(fp, 0, SEEK_SET);fread(buf, 1, len, fp);}//编码char* enc = b64_encode(buf, len);//printf("enc:%s\n", enc);cJSON_AddStringToObject(json_test, "y16data", enc);cJSON* testy16 = cJSON_GetObjectItem(json_test, "y16data");char* buf1 = testy16->valuestring;char* dec = b64_decode(buf1, strlen(buf1));//printf("dec:%s\n", dec);FILE* fp1 = fopen("rgb_result.raw", "wb+");if (fp1) {fwrite(dec, 1, len, fp1);fclose(fp1);}char* str = cJSON_Print(json_test);printf("str:%s,len:%d\n", str,strlen(str));cJSON_Delete(json_test);fclose(fp);free(buf);return 0;
}

在这里插入图片描述

相关文章:

  • leetcode_2558 从数量最多的堆取走礼物
  • 进制转换10进制转二进制,n进制转16进制
  • 一个简单的注册的页面,如有错误请指正;(3.JavaScript)
  • 记一次fineBI的增量删除更新BUG
  • Ansible上通过roles简化playbook演示介绍
  • 2023年【河北省安全员B证】新版试题及河北省安全员B证试题及解析
  • Vue中this指向问题
  • mongodb数据迁移的方法
  • CTF-Web(2)SQL注入
  • 【java学习—九】内部类(7)
  • 线程池的理解
  • 软考-网络安全审计技术原理与应用
  • LeetCode|股票问题|714. 买卖股票的最佳时机含手续费、309. 买卖股票的最佳时机含冷冻期
  • flutter升级+生成drift文件
  • python:使用Scikit-image对遥感影像进行傅里叶变换特征提取(fourier)
  • [LeetCode] Wiggle Sort
  • CSS相对定位
  • ES6简单总结(搭配简单的讲解和小案例)
  • export和import的用法总结
  • express如何解决request entity too large问题
  • HTTP中的ETag在移动客户端的应用
  • Laravel5.4 Queues队列学习
  • nginx 负载服务器优化
  • PhantomJS 安装
  • React系列之 Redux 架构模式
  • Swoft 源码剖析 - 代码自动更新机制
  • vue2.0一起在懵逼的海洋里越陷越深(四)
  • 深度学习中的信息论知识详解
  • 使用parted解决大于2T的磁盘分区
  • 用jQuery怎么做到前后端分离
  • 字符串匹配基础上
  • 阿里云移动端播放器高级功能介绍
  • ​用户画像从0到100的构建思路
  • # 日期待t_最值得等的SUV奥迪Q9:空间比MPV还大,或搭4.0T,香
  • #include到底该写在哪
  • #pragma once与条件编译
  • #每天一道面试题# 什么是MySQL的回表查询
  • (007)XHTML文档之标题——h1~h6
  • (4)Elastix图像配准:3D图像
  • (6)【Python/机器学习/深度学习】Machine-Learning模型与算法应用—使用Adaboost建模及工作环境下的数据分析整理
  • (C语言)fgets与fputs函数详解
  • (C语言)输入一个序列,判断是否为奇偶交叉数
  • (done) 两个矩阵 “相似” 是什么意思?
  • (Matlab)使用竞争神经网络实现数据聚类
  • (八十八)VFL语言初步 - 实现布局
  • (非本人原创)史记·柴静列传(r4笔记第65天)
  • (附源码)node.js知识分享网站 毕业设计 202038
  • (附源码)springboot宠物医疗服务网站 毕业设计688413
  • (个人笔记质量不佳)SQL 左连接、右连接、内连接的区别
  • (欧拉)openEuler系统添加网卡文件配置流程、(欧拉)openEuler系统手动配置ipv6地址流程、(欧拉)openEuler系统网络管理说明
  • (算法)求1到1亿间的质数或素数
  • (原創) 博客園正式支援VHDL語法著色功能 (SOC) (VHDL)
  • (转)【Hibernate总结系列】使用举例
  • (转)http协议
  • (转)详解PHP处理密码的几种方式