I'm a starter in opencv, and Learning Opencv has is code written in C. I need to convert to C++.
IplImage *imgY = cvCreateImage(imageSize, IPL_DEPTH_8U, 1);
IplImage *imgCr = cvCreateImage(imageSize, IPL_DEPTH_8U, 1);
IplImage *imgCb = cvCreateImage(imageSize, IPL_DEPTH_8U, 1);
IplImage *imgYCrCb = cvCreateImage(imageSize, img->depth, img->nChannels);
cvCvtColor(img,imgYCrCb,CV_BGR2YCrCb);
cvSplit(imgYCrCb, imgY, imgCr, imgCb, 0);
unsigned char *pY, *pCr, *pCb, *pMask;
pY = (unsigned char *)imgY->imageData;
pCr = (unsigned char *)imgCr->imageData;
pCb = (unsigned char *)imgCb->imageData;
pMask = (unsigned char *)mask->imageData;
Refer to:
For example,
IplImage *imgY = cvCreateImage(imageSize, IPL_DEPTH_8U, 1);
becomes
cv::Mat imgY = cv::Mat(imageSize, CV_8UC1);
and
cvCvtColor(img,imgYCrCb,CV_BGR2YCrCb);
becomes
cv::cvtColor(img, imgYCrCb, CV_BGR2YCrCb);
and so on ...
Edit :
Answer to your comment : OpenCV 2 removes the need to manage manually the memory.
So, the code can be rewritten as :
cv::Mat imgYCrCb;
std::vector<cv::mat> yCrCb_channels;
cv::cvtColor(img,imgYCrCb,CV_BGR2YCrCb);
cv::split(imgYCrCb, yCrCb_channels);
unsigned char * pY = (uchar *) yCrCn_channels[1].data;
Advice : read http://www.amazon.com/dp/1849513244/?tag=stackoverfl08-20 , it covers the C++ opencv interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With