Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I know IplImage is outdated
- IplImage* im = cvLoadImage("1.jpg", 1);
- //....
- bgr2yuv(im->imageData, dst, im->width, im->height);
- void bgr2yuv(unsigned char *src, unsigned char *dest, int w, int h)
- {
- AVFrame *yuvIm = avcodec_alloc_frame();
- AVFrame *rgbIm = avcodec_alloc_frame();
- avpicture_fill(rgbIm, src, PIX_FMT_BGR24, w, h);
- avpicture_fill(yuvIm, dest, PIX_FMT_YUV420P, w, h);
- av_register_all();
- struct SwsContext * imgCtx = sws_getCachedContext(imgCtx,
- w, h,(::PixelFormat)PIX_FMT_BGR24,
- w, h,(::PixelFormat)PIX_FMT_YUV420P,
- SWS_BICUBIC, NULL, NULL, NULL);
- sws_scale(imgCtx, rgbIm->data, rgbIm->linesize,0, h, yuvIm->data, yuvIm->linesize);
- av_free(yuvIm);
- av_free(rgbIm);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement