c++ - How to get reference to YUV components after cvCvColor? -
i'm trying convert bgr yuv cvcvtcolor method , reference each component. source image (iplimage1) has next parameters:
convert , components after conversion:
iplimage* yuvimage = cvcreateimage(cvsize(1620, 1220), 8, 3); cvcvtcolor(iplimage1, yuvimage, cv_bgr2ycrcb); yptr = yuvimage->imagedata; uptr = yptr + height*width; vptr = uptr + height*width/4; i have method converts yuv rgb , saves file. when create yuv components manually (i create bluish image) works , when open image it's blue. but, when create yuv components using method above black image. think maybe reference yuv components wrongly
yptr = yuvimage->imagedata; uptr = yptr + height*width; vptr = uptr + height*width/4; what problem?
if must utilize iplimage (e.g. in legacy code, or c) utilize cvsplit
iplimage* iplimage1 = something; iplimage* ycrcbimage = cvcreateimage(cvsize(1620, 1220), 8, 3); cvcvtcolor(iplimage1, ycrcbimage, cv_bgr2ycrcb); iplimage* yimage = cvcreateimage(cvsize(1620, 1220), 8, 1); iplimage* crimage = cvcreateimage(cvsize(1620, 1220), 8, 1); iplimage* cbimage = cvcreateimage(cvsize(1620, 1220), 8, 1); cvsplit(ycrcbimage, yimage, crimage , cbimage, 0); the modern approach avoid legacy api , utilize mats:
cv::mat matimage1(iplimage1); cv::mat ycrcb_image; cv::cvtcolor(matimage1, ycrcb_image, cv_bgr2ycrcb); // extract y, cr , cb channels separate mats std::vector<cv::mat> planes(3); cv::split(ycrcb_image, planes); // have y image in planes[0], // cr image in planes[1], // , cb image in planes[2] cv::mat y = planes[0]; // if want c++ opencv color-scheme
No comments:
Post a Comment