arm 解决Rk1126 画框颜色变色问题(RGB转NV12)
在Rv1126上直接对Nv12图像进行绘制时,颜色是灰色。故将Nv12转BGR后绘制图像,绘制完成后转成Nv12,BGR的图像颜色是正常的,但是NV12的图像颜色未画全,如图:
1.排查发现是RGB转NV12的函数出现问题,故百度找到一个可用的网址:RGB转换为NV12的代码_rgb转nv12-CSDN博客
//https://software.intel.com/en-us/node/503873
//YCbCr Color Model:
// The YCbCr color space is used for component digital video and was developed as part of the ITU-R BT.601 Recommendation. YCbCr is a scaled and offset version of the YUV color space.
// The Intel IPP functions use the following basic equations [Jack01] to convert between R'G'B' in the range 0-255 and Y'Cb'Cr' (this notation means that all components are derived from gamma-corrected R'G'B'):
// Y' = 0.257*R' + 0.504*G' + 0.098*B' + 16
// Cb' = -0.148*R' - 0.291*G' + 0.439*B' + 128
// Cr' = 0.439*R' - 0.368*G' - 0.071*B' + 128//Y' = 0.257*R' + 0.504*G' + 0.098*B' + 16
static float Rgb2Y(float r0, float g0, float b0)
{float y0 = 0.257f*r0 + 0.504f*g0 + 0.098f*b0 + 16.0f;return y0;
}//U equals Cb'
//Cb' = -0.148*R' - 0.291*G' + 0.439*B' + 128
static float Rgb2U(float r0, float g0, float b0)
{float u0 = -0.148f*r0 - 0.291f*g0 + 0.439f*b0 + 128.0f;return u0;
}//V equals Cr'
//Cr' = 0.439*R' - 0.368*G' - 0.071*B' + 128
static float Rgb2V(float r0, float g0, float b0)
{float v0 = 0.439f*r0 - 0.368f*g0 - 0.071f*b0 + 128.0f;return v0;
}//Convert two rows from RGB to two Y rows, and one row of interleaved U,V.
//I0 and I1 points two sequential source rows.
//I0 -> rgbrgbrgbrgbrgbrgb...
//I1 -> rgbrgbrgbrgbrgbrgb...
//Y0 and Y1 points two sequential destination rows of Y plane.
//Y0 -> yyyyyy
//Y1 -> yyyyyy
//UV0 points destination rows of interleaved UV plane.
//UV0 -> uvuvuv
static void Rgb2NV12TwoRows(const unsigned char I0[],const unsigned char I1[],int step,const int image_width,unsigned char Y0[],unsigned char Y1[],unsigned char UV0[])
{int x; //Column index//Process 4 source pixels per iteration (2 pixels of row I0 and 2 pixels of row I1).for (x = 0; x < image_width; x += 2){//Load R,G,B elements from first row (and convert to float).float r00 = (float)I0[x*step + 0];float g00 = (float)I0[x*step + 1];float b00 = (float)I0[x*step + 2];//Load next R,G,B elements from first row (and convert to float).float r01 = (float)I0[x*step + step+0];float g01 = (float)I0[x*step + step+1];float b01 = (float)I0[x*step + step+2];//Load R,G,B elements from second row (and convert to float).float r10 = (float)I1[x*step + 0];float g10 = (float)I1[x*step + 1];float b10 = (float)I1[x*step + 2];//Load next R,G,B elements from second row (and convert to float).float r11 = (float)I1[x*step + step+0];float g11 = (float)I1[x*step + step+1];float b11 = (float)I1[x*step + step+2];//Calculate 4 Y elements.float y00 = Rgb2Y(r00, g00, b00);float y01 = Rgb2Y(r01, g01, b01);float y10 = Rgb2Y(r10, g10, b10);float y11 = Rgb2Y(r11, g11, b11);//Calculate 4 U elements.float u00 = Rgb2U(r00, g00, b00);float u01 = Rgb2U(r01, g01, b01);float u10 = Rgb2U(r10, g10, b10);float u11 = Rgb2U(r11, g11, b11);//Calculate 4 V elements.float v00 = Rgb2V(r00, g00, b00);float v01 = Rgb2V(r01, g01, b01);float v10 = Rgb2V(r10, g10, b10);float v11 = Rgb2V(r11, g11, b11);//Calculate destination U element: average of 2x2 "original" U elements.float u0 = (u00 + u01 + u10 + u11)*0.25f;//Calculate destination V element: average of 2x2 "original" V elements.float v0 = (v00 + v01 + v10 + v11)*0.25f;//Store 4 Y elements (two in first row and two in second row).Y0[x + 0] = (unsigned char)(y00 + 0.5f);Y0[x + 1] = (unsigned char)(y01 + 0.5f);Y1[x + 0] = (unsigned char)(y10 + 0.5f);Y1[x + 1] = (unsigned char)(y11 + 0.5f);//Store destination U element.UV0[x + 0] = (unsigned char)(u0 + 0.5f);//Store destination V element (next to stored U element).UV0[x + 1] = (unsigned char)(v0 + 0.5f);}
}//Convert image I from pixel ordered RGB to NV12 format.
//I - Input image in pixel ordered RGB format
//image_width - Number of columns of I
//image_height - Number of rows of I
//J - Destination "image" in NV12 format.//I is pixel ordered RGB color format (size in bytes is image_width*image_height*3):
//RGBRGBRGBRGBRGBRGB
//RGBRGBRGBRGBRGBRGB
//RGBRGBRGBRGBRGBRGB
//RGBRGBRGBRGBRGBRGB
//
//J is in NV12 format (size in bytes is image_width*image_height*3/2):
//YYYYYY
//YYYYYY
//UVUVUV
//Each element of destination U is average of 2x2 "original" U elements
//Each element of destination V is average of 2x2 "original" V elements
//
//Limitations:
//1. image_width must be a multiple of 2.
//2. image_height must be a multiple of 2.
//3. I and J must be two separate arrays (in place computation is not supported).
void Rgb2NV12(const unsigned char I[], int step,const int image_width, const int image_height,unsigned char J[])
{//In NV12 format, UV plane starts below Y plane.unsigned char *UV = &J[image_width*image_height];//I0 and I1 points two sequential source rows.const unsigned char *I0; //I0 -> rgbrgbrgbrgbrgbrgb...const unsigned char *I1; //I1 -> rgbrgbrgbrgbrgbrgb...//Y0 and Y1 points two sequential destination rows of Y plane.unsigned char *Y0; //Y0 -> yyyyyyunsigned char *Y1; //Y1 -> yyyyyy//UV0 points destination rows of interleaved UV plane.unsigned char *UV0; //UV0 -> uvuvuvint y; //Row index//In each iteration: process two rows of Y plane, and one row of interleaved UV plane.for (y = 0; y < image_height; y += 2){I0 = &I[y*image_width*step]; //Input row width is image_width*3 bytes (each pixel is R,G,B).I1 = &I[(y+1)*image_width*step];Y0 = &J[y*image_width]; //Output Y row width is image_width bytes (one Y element per pixel).Y1 = &J[(y+1)*image_width];UV0 = &UV[(y/2)*image_width]; //Output UV row - width is same as Y row width.//Process two source rows into: Two Y destination row, and one destination interleaved U,V row.Rgb2NV12TwoRows(I0,I1,step,image_width,Y0,Y1,UV0);}
}
调用:
cv::Mat m_stJpg_640x384 = cv::imread("D:\\ImageToNv12\\111.jpg");if (!m_stJpg_640x384.empty()) {cv::cvtColor(m_stJpg_640x384, m_stJpg_640x384, COLOR_BGR2RGB);unsigned char* pData = new unsigned char[1920 * 1080 * 3];Rgb2NV12(m_stJpg_640x384.data, 3/*RGB为3,RGBA为4*/, m_stJpg_640x384.cols, m_stJpg_640x384.rows, pData);WriteFile("m.yuv", "wb+", pData, m_stJpg_640x384.cols * m_stJpg_640x384.rows * 3 / 2);delete[] pData;}
相关文章:
arm 解决Rk1126 画框颜色变色问题(RGB转NV12)
在Rv1126上直接对Nv12图像进行绘制时,颜色是灰色。故将Nv12转BGR后绘制图像,绘制完成后转成Nv12,BGR的图像颜色是正常的,但是NV12的图像颜色未画全,如图: 1.排查发现是RGB转NV12的函数出现问题,…...
113 链接集10--ctrl+左键单击多选
1.ctrl左键单击多选,单击单选 精简代码 <div class"model-list"><divmousedown.prevent"handleClick(item, $event)"class"model-list-item"v-for"item in modelList":key"item.id":class"{ model…...
详解JavaScript中this指向
this 原理 this 是一个指针型变量,它指向当前函数的运行环境。 1.内存的数据结构 var obj { foo: 5 };2.函数 var obj { foo: function () {} };引擎会将函数单独保存在内存中,然后再将函数的地址赋值给foo属性的value属性。 由于函数是一个单独的…...
c语言之在函数中传递指针
c语言中定义一个函数,如果说是形参一个数组,这个数组在编译后会变成一个指针变量 比如下面的代码例子 #include<stdio.h> void ff(char a[]) {a[1]r;a[4]r;printf("%d\n",a); }int main() {char a[]"peogeam";ff(a);printf(…...
vue2 插槽(默认插槽 slot 、具名插槽 v-slot 、作用域插槽 slot-scope -- 插槽传值 )
插槽:用于在子组件的指定位置插入指定内容,类似在电梯里挂的若干广告显示屏,可以给指定的位置传入指定的广告 单插槽(匿名/默认插槽) 父组件中( 此时的 ) <Child><template><p…...
(第79天)单机转 RAC:19C 单机 到 19C RAC
前言 单机转 RAC 分为两种: 同版本迁移:可以使用 RMAN 或者 ADG 方式升级迁移:建议使用数据泵 或者 XTTS 方式升级迁移使用数据泵的方式与 (第72天)数据泵升级:11GR2 到 19C 步骤基本一致,这里不作演示,只演示使用 ADG 来进行同版本迁移。 升级前准备 本次测试尽量按…...
Spring Cloud微服务Actuator和Vue
目录 前言一、引入Actuator依赖二、暴露Actuator端点1. 配置文件2. 监控端点 三、自定义健康检查自定义健康检查类 四、vue前端代码五、监控器的优势六、监控指标的可视化1. Grafana2. Prometheus 七、安全性考虑安全配置示例 八、总结 前言 随着微服务架构的流行,…...
Iterator对象功能学习
package config;import java.util.Iterator; import java.util.Properties; import java.util.Set;/*** 这个类演示了如何使用Properties类来存储和访问键值对。* Properties类继承自Hashtable,因此它可以用来存储键值对数据,且支持同步。*/ public clas…...
Linux的一些基本指令
目录 前言: 1.以指令的形式登录 2.ls指令 语法: 功能: 常用选项: 3.pwd指令 4.cd指令 4.1 绝对路径与相对路径 4.2 cd .与cd ..(注意cd后先空格,然后两个点是连一起的࿰…...
【tips】Git使用指南
文章目录 一、Git介绍1. 什么是Git2.Git对比SVN3.Git安装 二.Git常用命令1. git config2. 初始化本地库3. 工作区、暂存区和版本库4. git add5. git commit6. git reset 与 git revertgit resetgit revert 三. Git 分支1.初识分支2.创建分支3.切换分支4.合并分支5.删除分支 四.…...
【字节序】
字节序 高字节(低字节)高地址(低地址)大端模式(小端模式) 高字节(低字节) 一个16位(双字节)的数据,比如0xAABB,那么高位字节就是0xAA,低位是0xBB …...
数据结构(五)——树森林
5.4 树和森林 5.4.1 树的存储结构 树的存储1:双亲表示法 用数组顺序存储各结点,每个结点中保存数据元素、指向双亲结点(父结点)的“指针” #define MAX_TREE_SIZE 100// 树的结点 typedef struct{ElemType data;int parent; }PTNode;// 树的类型 type…...
vscode配置c/c++调试环境
本文记录win平台使用vscode远程连接ubuntu server服务器下,如何配置c/c调试环境。 过程 1. 服务器配置编译环境 这里的前置条件是vscode已经能够连接到服务器,第一步安装编译构建套件(gcc、g、make、链接器等)和调试器…...
食品输送带的材质
食品输送带的材质:确保安全与卫生的关键选择 在食品生产和加工过程中,食品输送带扮演着至关重要的角色。它负责将原材料、半成品和成品在各个环节之间进行有效传输,确保生产流程的顺畅进行。然而,在食品行业中,输送带…...
普通用户权限运行Docker
普通用户权限运行Docker 安装Docker Docker的安装比较简单,在Docker官网已经给出了具体的方案,可以直接使用apt安装 # Add Dockers official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl sudo install -m 0755 -d /etc/…...
7.Java并发编程—掌握线程池的标准创建方式和优雅关闭技巧,提升任务调度效率
文章目录 线程池的标准创建方式线程池参数1.核心线程(corePoolSize)2.最大线程数(maximumPoolSize)3.阻塞队列(BlockingQueue) 向线程提交任务的两种方式1.execute()1.1.案例-execute()向线程池提交任务 2.submit()2.1.submit(Callable<T> task)2.2.案例-submit()向线程池…...
从边缘设备丰富你的 Elasticsearch 文档
作者:David Pilato 我们在之前的文章中已经了解了如何丰富 Elasticsearch 本身和 Logstash 中的数据。 但如果我们可以从边缘设备中做到这一点呢? 这将减少 Elasticsearch 要做的工作。 让我们看看如何从具有代理处理器的 Elastic 代理中执行此操作。 E…...
day29|leetcode|C++|491. 非递减子序列|46. 全排列|47. 全排列 II
Leetcode 491. 非递减子序列 链接:491. 非递减子序列 thought: 设 stack 中最后一个值的位置为 last。如果 stack 为空,则 last -1。 设当前正在处理的位置为 pos。如果在 nums 的子区间 [last1, pos) 中,存在和 nums[pos] 相同的值&…...
[Java、Android面试]_12_java访问修饰符、抽象类和接口
文章目录 1. java访问修饰符2. 抽象类和接口2.1 抽象类2.2 接口2.3 抽象类和接口的区别 本人今年参加了很多面试,也有幸拿到了一些大厂的offer,整理了众多面试资料,后续还会分享众多面试资料。 整理成了面试系列,由于时间有限&…...
Linux:Prometheus的源码包安装及操作(2)
环境介绍 三台centos 7系统,运行内存都2G 1.prometheus监控服务器:192.168.6.1 主机名:pm 2.grafana展示服务器:192.168.6.2 主机名:gr 3.被监控服务器:192.168.6.3 …...
3.3.1_1 检错编码(奇偶校验码)
从这节课开始,我们会探讨数据链路层的差错控制功能,差错控制功能的主要目标是要发现并且解决一个帧内部的位错误,我们需要使用特殊的编码技术去发现帧内部的位错误,当我们发现位错误之后,通常来说有两种解决方案。第一…...
uni-app学习笔记二十二---使用vite.config.js全局导入常用依赖
在前面的练习中,每个页面需要使用ref,onShow等生命周期钩子函数时都需要像下面这样导入 import {onMounted, ref} from "vue" 如果不想每个页面都导入,需要使用node.js命令npm安装unplugin-auto-import npm install unplugin-au…...
五年级数学知识边界总结思考-下册
目录 一、背景二、过程1.观察物体小学五年级下册“观察物体”知识点详解:由来、作用与意义**一、知识点核心内容****二、知识点的由来:从生活实践到数学抽象****三、知识的作用:解决实际问题的工具****四、学习的意义:培养核心素养…...
论文浅尝 | 基于判别指令微调生成式大语言模型的知识图谱补全方法(ISWC2024)
笔记整理:刘治强,浙江大学硕士生,研究方向为知识图谱表示学习,大语言模型 论文链接:http://arxiv.org/abs/2407.16127 发表会议:ISWC 2024 1. 动机 传统的知识图谱补全(KGC)模型通过…...
【C++从零实现Json-Rpc框架】第六弹 —— 服务端模块划分
一、项目背景回顾 前五弹完成了Json-Rpc协议解析、请求处理、客户端调用等基础模块搭建。 本弹重点聚焦于服务端的模块划分与架构设计,提升代码结构的可维护性与扩展性。 二、服务端模块设计目标 高内聚低耦合:各模块职责清晰,便于独立开发…...
Device Mapper 机制
Device Mapper 机制详解 Device Mapper(简称 DM)是 Linux 内核中的一套通用块设备映射框架,为 LVM、加密磁盘、RAID 等提供底层支持。本文将详细介绍 Device Mapper 的原理、实现、内核配置、常用工具、操作测试流程,并配以详细的…...
Typeerror: cannot read properties of undefined (reading ‘XXX‘)
最近需要在离线机器上运行软件,所以得把软件用docker打包起来,大部分功能都没问题,出了一个奇怪的事情。同样的代码,在本机上用vscode可以运行起来,但是打包之后在docker里出现了问题。使用的是dialog组件,…...
QT3D学习笔记——圆台、圆锥
类名作用Qt3DWindow3D渲染窗口容器QEntity场景中的实体(对象或容器)QCamera控制观察视角QPointLight点光源QConeMesh圆锥几何网格QTransform控制实体的位置/旋转/缩放QPhongMaterialPhong光照材质(定义颜色、反光等)QFirstPersonC…...
探索Selenium:自动化测试的神奇钥匙
目录 一、Selenium 是什么1.1 定义与概念1.2 发展历程1.3 功能概述 二、Selenium 工作原理剖析2.1 架构组成2.2 工作流程2.3 通信机制 三、Selenium 的优势3.1 跨浏览器与平台支持3.2 丰富的语言支持3.3 强大的社区支持 四、Selenium 的应用场景4.1 Web 应用自动化测试4.2 数据…...
AI语音助手的Python实现
引言 语音助手(如小爱同学、Siri)通过语音识别、自然语言处理(NLP)和语音合成技术,为用户提供直观、高效的交互体验。随着人工智能的普及,Python开发者可以利用开源库和AI模型,快速构建自定义语音助手。本文由浅入深,详细介绍如何使用Python开发AI语音助手,涵盖基础功…...
