nv12zhuanrgb zhuan hsv



void NV21_T_RGB(unsigned int width , unsigned int height , unsigned char *yuyv)// , unsigned char *rgb
{
const int nv_start = width * height ;
// test_rgb = calloc(width*height*3, 1);
    u32  i, j, index = 0, rgb_index = 0;
    u8 y, u, v;
    char r, g, b;
int nv_index = 0;
    for(i = 0; i <  height ; i++)
    {
        for(j = 0; j < width; j++){
            //nv_index = (rgb_index / 2 - width / 2 * ((i + 1) / 2)) * 2;
            nv_index = i / 2  * width + j - j % 2;


            y = yuyv[rgb_index];
            u = yuyv[nv_start + nv_index ];
            v = yuyv[nv_start + nv_index + 1];


            r = y + (140 * (v-128))/100 ;  //r
            g = y - (34 * (u-128))/100 - (71 * (v-128))/100 ; //g
            b = y + (177 * (u-128))/100 ; //b
            if(r > 255)   r = 255;
            if(g > 255)   g = 255;
            if(b > 255)   b = 255;
            if(r < 0)     r = 0;
            if(g < 0)     g = 0;
            if(b < 0)     b = 0;


            index = rgb_index % width + (height - i - 1) * width;
            test_rgb[index*3+0] = b;
            test_rgb[index*3+1] = g;
            test_rgb[index*3+2] = r;
   min = MIN( r, MIN( g, b ));
   max = MAX( r, MAX( g, b ));
   hsv_v[i*width+j]= max;// *v = max; // v
   delta = max - min;
  if( max != 0 )
  s[i*width+j] = delta * 255 / max;// *s = delta / max;   // s
  else {
  s[i*width+j] = 0; // *s = 0;
  h[i*width+j] = -1; //*h = -1;
  return;
  }
  if( r == max )
  h[i*width+j] =( 60 * ( g - b ) * 255 / 360 / delta )*255/360;//*h = ( g - b ) / delta;     // between yellow & magenta
  else if( g == max )
  h[i*width+j] =( 120 +60 * ( b - r )* 255 / 360 / delta )*255/360;// *h = 2 + ( b - r ) / delta; // between cyan & yellow
  else
  h[i*width+j] = (240 +60 * ( r - g ) / delta ) *255/360;//*h = 4 + ( r - g ) / delta; // between magenta & cyan


  if( h[i*width+j] <0)// if( *h < 0 )
 h[i*width+j] =h[i*width+j]*255/360 + 255; //*h += 360;
            rgb_index++;
        }
    }
}


int v4l_get_capture_data(struct v4l2_buffer *buf)
{
unsigned char picture_bianbei1_uv[540*1920]={0};
unsigned char picture_bianbei1_y[1080*1920*3/2]={0};

memset(buf, 0, sizeof(struct v4l2_buffer));
buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf->memory = V4L2_MEMORY_MMAP;
if (ioctl(camera_fd, VIDIOC_DQBUF, buf) < 0) {
err_msg("VIDIOC_DQBUF failed\n");
return -1;

if(open_camera == camera_5640)
{
memcpy(pic_track_5640,  cap_buffers[buf->index].start, cap_buffers[buf->index].length-2560);

if(Cap_Uart2_FK.dianzibianbei==1)
{
fujie_data.xiangyuan_hor=1920;
fujie_data.xiangyuan_ver=1080;
fujie_data.enc_horpixeel=1920;
fujie_data.enc_verpixeel=1088;
memcpy(pic_track_5640_pai,pic_track_5640,sizeof(pic_track_5640));
if(test_flag==0)
{
NV21_T_RGB(1920,1080,pic_track_5640_pai);
// process_image_5640(pic_track_5640,1920*1080*3/2);
// process_image_5640(test_rgb ,1920*1080*3);
// process_image_56401("z.yuv" , pic_track_5640 ,1920*1080*3/2);
// process_image_56401("c.yuv" , test_rgb ,1920*1080*3);
// process_image_56401("h.yuv" , h , 1920*1080);
// process_image_56401("s.yuv" , s , 1920*1080);
// process_image_56401("v.yuv" , hsv_v , 1920*1080);


for(k=0;k<255;k++)
{
for(m=0;m<1080;m++)
{
for(n=0;n<1920;n++)
{
if(h[m*1920+n]==k)
ek[k]++;
}
}
}


for (Y = 0; Y < 256; Y++)
{
Sum = Sum + ek[Y];
if (Sum >= Amount * 50 / 100)
{
printf("Y=%d\n",Y);
break;
//return Y;
}
}
for(m=0;m<1080;m++)
{
for(n=0;n<1920;n++)
{
if(h[m*1920+n]>Y)
h[m*1920+n]=255;
else
h[m*1920+n]=0;
}
}
printf("1111111111111\n");
// process_image_5640(test_rgb ,1920*1080*3);
// process_image_56401("z.yuv" , pic_track_5640 ,1920*1080*3/2);
// process_image_56401("c.yuv" , test_rgb ,1920*1080*3);
// process_image_56401("h.yuv" , h , 1920*1080);
// process_image_56401("s.yuv" , s , 1920*1080);
// process_image_56401("v.yuv" , hsv_v , 1920*1080);
test_flag=1;
}
}

你可能感兴趣的:(imx6q)