资源简介
友善之臂4412通过USB摄像头采集YUYV422格式图像,转码成RGB显示在800*480分辨率触摸屏上
代码片段和文件信息
#include
#include
#include
#include
#include /* getopt_long() */
#include /* low-level i/o */
#include
#include
#include
#include
#include
#include
#include
#include /* for videodev2.h */
#include
#include “camera.h“
#include “videodev2_samsung.h“
void Camera::DecodeYUV420SP(unsigned int* rgbBuf unsigned char* yuv420sp int width int height) {
int frameSize = width * height;
int i = 0 y = 0;
int uvp = 0 u = 0 v = 0;
int y1192 = 0 r = 0 g = 0 b = 0;
unsigned int xrgb8888;
int xrgb8888Index = 0;
for (int j = 0 yp = 0; j < height; j++) {
uvp = frameSize + (j >> 1) * width;
u = 0;
v = 0;
for (i = 0; i < width; i++ yp++) {
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;
}
y1192 = 1192 * y;
r = (y1192 + 1634 * u);
g = (y1192 - 833 * u - 400 * v);
b = (y1192 + 2066 * v);
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;
r = (unsigned char)(r >> 10);
g = (unsigned char)(g >> 10);
b = (unsigned char)(b >> 10);
xrgb8888 = (unsigned int)((r << 16) | (g << 8) | b);
rgbBuf[xrgb8888Index++] = xrgb8888;
}
}
}
//YUYV(yuv422)转RGB
void Camera:: video_yuyv_to_rgb24(unsigned char *yuv unsigned char *rgb unsigned int width unsigned int height)
{
unsigned int in out;
int y0 u y1 v;
unsigned int pixel24;
unsigned char *pixel = (unsigned char *)&pixel24;
unsigned int size = width*height*2;
for (in = 0 out = 0; in < size; in += 4 out += 8)
{
y0 = yuv[in+0];
u = yuv[in+1];
y1 = yuv[in+2];
v = yuv[in+3];
sign3 = true;
pixel24 = yuvtorgb(y0 u v);
rgb[out+0] = pixel[0]; //for QT
rgb[out+1] = pixel[1];
rgb[out+2] = pixel[2];
//rgb[out+0] = pixel[2]; //for iplimage
//rgb[out+1] = pixel[1];
//rgb[out+2] = pixel[0];
//sign3 = true;
pixel24 = yuvtorgb(y1 u v);
rgb[out+4] = pixel[0];
rgb[out+5] = pixel[1];
rgb[out+6] = pixel[2];
//rgb[out+3] = pixel[2];
//rgb[out+4] = pixel[1];
//rgb[out+5] = pixel[0];
}
//return 0;
}
int Camera:: yuvtorgb(int y int u int v)
{
unsigned int pixel24 = 0;
unsigned char *pixel = (unsigned char *)&pixel24;
int r g b;
static long int ruv guv buv;
if (sign3)
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-10-24 12:53 Camera\
文件 12982 2017-07-12 17:40 Camera\Camera.cpp
文件 1535 2017-07-12 17:40 Camera\camera.h
文件 3152 2017-07-11 21:54 Camera\Fb.cpp
文件 756 2017-07-11 21:54 Camera\Fb.h
文件 1085 2017-07-12 12:46 Camera\main.cpp
文件 574 2017-07-11 21:54 Camera\Makefile
文件 21041 2017-07-11 21:54 Camera\videodev2_samsung.h
- 上一篇:用ARM做的电子琴ARM
- 下一篇:管家婆项目文档讲义含源代码
评论
共有 条评论