Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. //I know IplImage is outdated
  2. IplImage* im = cvLoadImage("1.jpg", 1);
  3. //....
  4. bgr2yuv(im->imageData, dst, im->width, im->height);
  5.  
  6. void bgr2yuv(unsigned char *src, unsigned char *dest, int w, int h)
  7. {
  8. AVFrame *yuvIm = avcodec_alloc_frame();
  9. AVFrame *rgbIm = avcodec_alloc_frame();
  10. avpicture_fill(rgbIm, src, PIX_FMT_BGR24, w, h);
  11. avpicture_fill(yuvIm, dest, PIX_FMT_YUV420P, w, h);
  12. av_register_all();
  13.  
  14. struct SwsContext * imgCtx = sws_getCachedContext(imgCtx,
  15. w, h,(::PixelFormat)PIX_FMT_BGR24,
  16. w, h,(::PixelFormat)PIX_FMT_YUV420P,
  17. SWS_BICUBIC, NULL, NULL, NULL);
  18.  
  19. sws_scale(imgCtx, rgbIm->data, rgbIm->linesize,0, h, yuvIm->data, yuvIm->linesize);
  20. av_free(yuvIm);
  21. av_free(rgbIm);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement