Android的Yuv420sp到ARGB OpenCV中

编程入门 行业动态 更新时间:2024-10-21 11:31:19
本文介绍了Android的Yuv420sp到ARGB OpenCV中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图从previewcallback从手机发送原始图像到电脑。然后,PC将处理图像。我使用OpenCV库做的图像处理。此刻,我只是写在previewcallback函数的字节数组保存到一个文件,并将该文件复制到电脑上,我写了一个简单的程序,文件中第一次读,并保存到memeory,然后直接将数据复制到IplImage.imageData。但是,我总是得到一个垃圾的形象。

我用这个功能我净发现这样做YUV420SP之间的converstion到ARGB。感谢您的帮助。

无效德codeYUV420SP为(int * RGB,字符* yuv420sp,诠释的宽度,高度INT){    INT框架尺寸=宽*高;    对于(INT J = 0,YP = 0; J<高度; J ++){        INT UVP =框架尺寸+(J>→1)*宽度,U = 0,V = 0;        的for(int i = 0; I<宽度;我++,YP ++){            INT Y =(0xFF的及((int)的yuv420sp [YP])) - 16;            如果(γ℃的)Y = 0;            如果((I和1)== 0){                V =(0xFF的&安培; yuv420sp [UVP ++]) - 128;                U =(0xFF的&安培; yuv420sp [UVP ++]) - 128;            }            INT y1192 = 1192 * Y;            INT R =(y1192 + 1634 * V);            INT G =(y1192 - 833 * V - 400 * U);            INT B =(y1192 + 2066 * U);            如果(为r 0)R = 0;否则如果(R> 262143)R = 262143;            如果(克小于0)G = 0;否则如果(g取代; 262143)G = 262143;            如果(二℃,)B = 0;否则如果(B个262143)B = 262143;            RGB [YP] = 0xff000000 | ((为r 6;)及为0xFF0000)| ((g取代;→2)及为0xFF00)| ((B个大于10)及0xff的);        }    }}

解决方案

您可以使用OpenCV4Android转换器:

Imgproc.cvtColor(mYuv,mRgba,Imgproc.COLOR_YUV420sp2RGBA);

I am trying to send a raw image from the previewcallback from the phone to PC. The PC will then process the image. I am use OpenCV library to do the image processing. At the moment i just write a function in previewcallback to save the byte array to a file, and copy the file to pc and I wrote a simple program to first read in the file and save it into memeory and then directly copy the data to the IplImage.imageData. But I always get a garbage image.

I use this function I found on net to do the converstion between YUV420SP to ARGB. Thanks for your help.

void decodeYUV420SP(int* rgb, char* yuv420sp, int width, int height) { int frameSize = width * height; for (int j = 0, yp = 0; j < height; j++) { int uvp = frameSize + (j >> 1) * width, u = 0, v = 0; for (int i = 0; i < width; i++, yp++) { int y = (0xff & ((int) yuv420sp[yp])) - 16; if (y < 0) y = 0; if ((i & 1) == 0) { v = (0xff & yuv420sp[uvp++]) - 128; u = (0xff & yuv420sp[uvp++]) - 128; } int y1192 = 1192 * y; int r = (y1192 + 1634 * v); int g = (y1192 - 833 * v - 400 * u); int b = (y1192 + 2066 * u); if (r < 0) r = 0; else if (r > 262143) r = 262143; if (g < 0) g = 0; else if (g > 262143) g = 262143; if (b < 0) b = 0; else if (b > 262143) b = 262143; rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff); } } }

解决方案

You can use OpenCV4Android converters:

Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420sp2RGBA);

更多推荐

Android的Yuv420sp到ARGB OpenCV中

本文发布于:2023-11-30 20:43:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651419.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Yuv420sp   Android   OpenCV   ARGB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!