YUV12 (420) (from) to RGB24, yuv12rgb24

Source: Internet
Author: User

YUV12 (420) (from) to RGB24, yuv12rgb24

Directly Add code


# Include <opencv2/opencv. hpp> # include <stdio. h> # define min (a, B) (a <B )? A: B) # define max (a, B) (a> B )? A: B) /*************************************** * ******************************* // * YUV12 to RGB24 (4) basic Optimizations 3.1 *//********************************** * ***********************************/int yuv420_to_argb888 (const unsigned char * y, const unsigned char * u, const unsigned char * v, int width, int height, unsigned char * rgb) {static const int Precision = 32768; static const int Coefficient_y = (Int) (1.164 * Precision + 0.5); static const int Coefficient_rv = (int) (1.596 * Precision + 0.5); static const int Coefficient_gu = (int) (0.391 * Precision + 0.5); static const int Coefficient_gv = (int) (0.813 * Precision + 0.5); static const int Coefficient_bu = (int) (2.018 * Precision + 0.5 ); static int CoefficientY [256]; static int CoefficientRV [256]; static int CoefficientGU [256]; static int CoefficientG V [256]; static int CoefficientBU [256]; static int _ CoefficientsR [1024]; // static int _ CoefficientsG [1024]; // static int _ CoefficientsB [1024]; static int flag = 1; if (flag) {for (int I = 0; I <256; I ++) {CoefficientY [I] = Coefficient_y * (I-16) + (Precision/2); CoefficientGV [I] =-Coefficient_gv * (I-128); CoefficientBU [I] = Coefficient_bu * (I-128 ); coefficientGU [I] =-Coefficient_gu * (I-128); CoefficientRV [I] = Coefficient_rv * (I-128);} for (int j = 0; j <1024; j ++) {_ CoefficientsR [j] = min (max (j-320, 0), 255); // _ CoefficientsG [j] = min (max (j-320, 0 )), 255); // _ CoefficientsB [j] = min (max (j-320, 0), 255);} flag = 0;} CoefficientY [0] =-593888; coefficientY [1] =-555746; // fixed the bug !! CoefficientY [1] was accidentally changed to a large number when entering this function for the second time. The theoretical value should be-555746int * CoefficientsR = & _ CoefficientsR [320]; // int * CoefficientsG = & _ CoefficientsG [320]; // int * CoefficientsB = & _ CoefficientsB [320]; for (int h = 0; h 
// Compare 3 images histograms together, // the first is divided in half along y to test its other half // Call is: // ch7HistCmp modelImage0 testImage1 testImage2 badImage3 // Note that the model image is split in half. top half (0) makes model. it's then tested // against its lower half (0), testImages 1 and 2 in different lighting and different object 3 // int main (int argc, char ** argv) {IplImage * src [5], * tmp; int I; if (src [0] = cvLoadImage (argv [1], 1) = 0) {// We're re going to split this one in halfprintf ("Error on reading image 1, % s \ n", argv [1]); return (-1 );} // Parse the first image into two image halves divided halfway on yprintf ("Getting size [[% d] [% d] format is [% s] \ n ", src [0]-> width, src [0]-> height, src [0]-> channelSeq); CvSize size = cvGetSize (src [0]); printf ("Get size % d \ n", size. width, size. height); int width = size. width; int height = size. height; int halfheight = height> 1; // RGB888 to YUV420unsigned char * rgb = (unsigned char *) src [0]-> imageData; unsigned char * yuv = (unsigned char *) malloc (width * height + width * height/2); unsigned char * y = yuv; unsigned char * u = & yuv [width * height]; unsigned char * v = & yuv [width * height + width * height/4]; int k = 0; for (int I = 0; I 





Reference: https://msdn.microsoft.com/en-us/library/aa917087.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.