Opencv 兼容OPENCV1.0

	const char* image="1.jpg";
	Ptr<IplImage> img=cvLoadImage(image);   // 转换Mat IplImage.
	if (img.empty())
	{
		return -1;
	}
	Mat img1(img);
Mat img_yuv;
cvtColor(img1,img_yuv,CV_BGR2YCrCb);
vector<Mat> planes;
split(img_yuv,planes);
MatIterator_<uchar> it=planes[0].begin<uchar>(), it_end=planes[0].end<uchar>();
for(; it!=it_end; ++it)
{
	double v=*it*1.7+rand()%21-10;
	*it=saturate_cast<uchar>(v*v/255);      //saturate_cast强制类型转换
}
for(int y=0; y<img_yuv.rows; y++)
{
	uchar *pp=planes[1].ptr<uchar>(y);
	for(int x=0; x<img_yuv.cols; x++)
	{
		pp[x]=saturate_cast<uchar>(pp[x]-128)/2;
		uchar &cc=planes[2].at<uchar>(y,x);
		cc=saturate_cast<uchar>(cc-153);
	}
}
merge(planes,img_yuv);
cvtColor(img_yuv, img1,CV_YCrCb2BGR);

imshow("11",img1);
                                            Opencv 兼容OPENCV1.0_第1张图片

你可能感兴趣的:(Opencv 兼容OPENCV1.0)