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

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图像进行绘制时&#xff0c;颜色是灰色。故将Nv12转BGR后绘制图像&#xff0c;绘制完成后转成Nv12&#xff0c;BGR的图像颜色是正常的&#xff0c;但是NV12的图像颜色未画全&#xff0c;如图&#xff1a; 1.排查发现是RGB转NV12的函数出现问题&#xff0c…...

113 链接集10--ctrl+左键单击多选

1.ctrl左键单击多选&#xff0c;单击单选 精简代码 <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 是一个指针型变量&#xff0c;它指向当前函数的运行环境。 1.内存的数据结构 var obj { foo: 5 };2.函数 var obj { foo: function () {} };引擎会将函数单独保存在内存中&#xff0c;然后再将函数的地址赋值给foo属性的value属性。 由于函数是一个单独的…...

c语言之在函数中传递指针

c语言中定义一个函数&#xff0c;如果说是形参一个数组&#xff0c;这个数组在编译后会变成一个指针变量 比如下面的代码例子 #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 -- 插槽传值 )

插槽&#xff1a;用于在子组件的指定位置插入指定内容&#xff0c;类似在电梯里挂的若干广告显示屏&#xff0c;可以给指定的位置传入指定的广告 单插槽&#xff08;匿名/默认插槽&#xff09; 父组件中&#xff08; 此时的 &#xff09; <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 七、安全性考虑安全配置示例 八、总结 前言 随着微服务架构的流行&#xff0c;…...

Iterator对象功能学习

package config;import java.util.Iterator; import java.util.Properties; import java.util.Set;/*** 这个类演示了如何使用Properties类来存储和访问键值对。* Properties类继承自Hashtable&#xff0c;因此它可以用来存储键值对数据&#xff0c;且支持同步。*/ public clas…...

Linux的一些基本指令

​​​​​​​ 目录 前言&#xff1a; 1.以指令的形式登录 2.ls指令 语法&#xff1a; 功能&#xff1a; 常用选项&#xff1a; 3.pwd指令 4.cd指令 4.1 绝对路径与相对路径 4.2 cd .与cd ..&#xff08;注意cd后先空格&#xff0c;然后两个点是连一起的&#xff0…...

【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.删除分支 四.…...

【字节序】

字节序 高字节&#xff08;低字节&#xff09;高地址&#xff08;低地址&#xff09;大端模式&#xff08;小端模式&#xff09; 高字节&#xff08;低字节&#xff09; 一个16位(双字节)的数据&#xff0c;比如0xAABB&#xff0c;那么高位字节就是0xAA&#xff0c;低位是0xBB …...

数据结构(五)——树森林

5.4 树和森林 5.4.1 树的存储结构 树的存储1&#xff1a;双亲表示法 用数组顺序存储各结点&#xff0c;每个结点中保存数据元素、指向双亲结点(父结点)的“指针” #define MAX_TREE_SIZE 100// 树的结点 typedef struct{ElemType data;int parent; }PTNode;// 树的类型 type…...

vscode配置c/c++调试环境

本文记录win平台使用vscode远程连接ubuntu server服务器下&#xff0c;如何配置c/c调试环境。 过程 1. 服务器配置编译环境 这里的前置条件是vscode已经能够连接到服务器&#xff0c;第一步安装编译构建套件&#xff08;gcc、g、make、链接器等&#xff09;和调试器&#xf…...

食品输送带的材质

食品输送带的材质&#xff1a;确保安全与卫生的关键选择 在食品生产和加工过程中&#xff0c;食品输送带扮演着至关重要的角色。它负责将原材料、半成品和成品在各个环节之间进行有效传输&#xff0c;确保生产流程的顺畅进行。然而&#xff0c;在食品行业中&#xff0c;输送带…...

普通用户权限运行Docker

普通用户权限运行Docker 安装Docker Docker的安装比较简单&#xff0c;在Docker官网已经给出了具体的方案&#xff0c;可以直接使用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 文档

作者&#xff1a;David Pilato 我们在之前的文章中已经了解了如何丰富 Elasticsearch 本身和 Logstash 中的数据。 但如果我们可以从边缘设备中做到这一点呢&#xff1f; 这将减少 Elasticsearch 要做的工作。 让我们看看如何从具有代理处理器的 Elastic 代理中执行此操作。 E…...

day29|leetcode|C++|491. 非递减子序列|46. 全排列|47. 全排列 II

Leetcode 491. 非递减子序列 链接&#xff1a;491. 非递减子序列 thought: 设 stack 中最后一个值的位置为 last。如果 stack 为空&#xff0c;则 last -1。 设当前正在处理的位置为 pos。如果在 nums 的子区间 [last1, pos) 中&#xff0c;存在和 nums[pos] 相同的值&…...

[Java、Android面试]_12_java访问修饰符、抽象类和接口

文章目录 1. java访问修饰符2. 抽象类和接口2.1 抽象类2.2 接口2.3 抽象类和接口的区别 本人今年参加了很多面试&#xff0c;也有幸拿到了一些大厂的offer&#xff0c;整理了众多面试资料&#xff0c;后续还会分享众多面试资料。 整理成了面试系列&#xff0c;由于时间有限&…...

Linux:Prometheus的源码包安装及操作(2)

环境介绍 三台centos 7系统&#xff0c;运行内存都2G 1.prometheus监控服务器&#xff1a;192.168.6.1 主机名&#xff1a;pm 2.grafana展示服务器:192.168.6.2 主机名&#xff1a;gr 3.被监控服务器&#xff1a;192.168.6.3 …...

多模态2025:技术路线“神仙打架”,视频生成冲上云霄

文&#xff5c;魏琳华 编&#xff5c;王一粟 一场大会&#xff0c;聚集了中国多模态大模型的“半壁江山”。 智源大会2025为期两天的论坛中&#xff0c;汇集了学界、创业公司和大厂等三方的热门选手&#xff0c;关于多模态的集中讨论达到了前所未有的热度。其中&#xff0c;…...

SkyWalking 10.2.0 SWCK 配置过程

SkyWalking 10.2.0 & SWCK 配置过程 skywalking oap-server & ui 使用Docker安装在K8S集群以外&#xff0c;K8S集群中的微服务使用initContainer按命名空间将skywalking-java-agent注入到业务容器中。 SWCK有整套的解决方案&#xff0c;全安装在K8S群集中。 具体可参…...

AtCoder 第409​场初级竞赛 A~E题解

A Conflict 【题目链接】 原题链接&#xff1a;A - Conflict 【考点】 枚举 【题目大意】 找到是否有两人都想要的物品。 【解析】 遍历两端字符串&#xff0c;只有在同时为 o 时输出 Yes 并结束程序&#xff0c;否则输出 No。 【难度】 GESP三级 【代码参考】 #i…...

Auto-Coder使用GPT-4o完成:在用TabPFN这个模型构建一个预测未来3天涨跌的分类任务

通过akshare库&#xff0c;获取股票数据&#xff0c;并生成TabPFN这个模型 可以识别、处理的格式&#xff0c;写一个完整的预处理示例&#xff0c;并构建一个预测未来 3 天股价涨跌的分类任务 用TabPFN这个模型构建一个预测未来 3 天股价涨跌的分类任务&#xff0c;进行预测并输…...

Java-41 深入浅出 Spring - 声明式事务的支持 事务配置 XML模式 XML+注解模式

点一下关注吧&#xff01;&#xff01;&#xff01;非常感谢&#xff01;&#xff01;持续更新&#xff01;&#xff01;&#xff01; &#x1f680; AI篇持续更新中&#xff01;&#xff08;长期更新&#xff09; 目前2025年06月05日更新到&#xff1a; AI炼丹日志-28 - Aud…...

涂鸦T5AI手搓语音、emoji、otto机器人从入门到实战

“&#x1f916;手搓TuyaAI语音指令 &#x1f60d;秒变表情包大师&#xff0c;让萌系Otto机器人&#x1f525;玩出智能新花样&#xff01;开整&#xff01;” &#x1f916; Otto机器人 → 直接点明主体 手搓TuyaAI语音 → 强调 自主编程/自定义 语音控制&#xff08;TuyaAI…...

工业自动化时代的精准装配革新:迁移科技3D视觉系统如何重塑机器人定位装配

AI3D视觉的工业赋能者 迁移科技成立于2017年&#xff0c;作为行业领先的3D工业相机及视觉系统供应商&#xff0c;累计完成数亿元融资。其核心技术覆盖硬件设计、算法优化及软件集成&#xff0c;通过稳定、易用、高回报的AI3D视觉系统&#xff0c;为汽车、新能源、金属制造等行…...

SpringTask-03.入门案例

一.入门案例 启动类&#xff1a; package com.sky;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCach…...

在WSL2的Ubuntu镜像中安装Docker

Docker官网链接: https://docs.docker.com/engine/install/ubuntu/ 1、运行以下命令卸载所有冲突的软件包&#xff1a; for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done2、设置Docker…...

Angular微前端架构:Module Federation + ngx-build-plus (Webpack)

以下是一个完整的 Angular 微前端示例&#xff0c;其中使用的是 Module Federation 和 npx-build-plus 实现了主应用&#xff08;Shell&#xff09;与子应用&#xff08;Remote&#xff09;的集成。 &#x1f6e0;️ 项目结构 angular-mf/ ├── shell-app/ # 主应用&…...