Bootstrap

opencv 使用Mat 矩阵进行图像的降采样,像素的访问方式

Mat  halfSizeImage(Mat  im)   
{
	unsigned int i,j;  
	int w = im.cols/2;  
	int h = im.rows/2;   
	Mat imnew = cvCreateMat(h, w, CV_8UC1);
	imnew.step = im.step/2;
	for ( j = 0; j < h; j++)   
		for ( i = 0; i < w; i++) 
			((float *)(imnew.ptr<float>(0,0) + imnew.step/sizeof(float) *(j)))[(i)]
		=((float *)(im.ptr<float>(0,0) + im.step/sizeof(float) *(2*j)))[(2*i)] ; 
			/*((float *)((float*)imnew.data + imnew.step/sizeof(float) *(j)))[(i)]
		=((float *)((float*)im.data + im.step/sizeof(float) *(2*j)))[(2*i)] ;  */
		
		return imnew;  
}
注释内为第二种方式
;