我有以下两个代码示例,我想知道它们之间有什么区别;我希望它们能产生相同的结果。但是,他们没有。
代码示例1:
IplImage *Image = cvCreateImage(cvSize(640,500),IPL_DEPTH_32F,3);
for(int row=0; row<50; row++ )
{
for(int col=0; col<Image->width; col++ )
{
((double *)(Image->imageData + row*Image->widthStep))[col*Image->nChannels + 0]=175;
((double *)(Image->imageData + row*Image->widthStep))[col*Image->nChannels + 1]=0;
((double *)(Image->imageData + row*Image->widthStep))[col*Image->nChannels + 2]=0;
}
}
cvNamedWindow("A",0);
cvShowImage("A",Image);
cvWaitKey(0);
代码示例2:
IplImage *Image=cvCreateImage(cvSize(640,500),IPL_DEPTH_32F,3);
CvScalar Sca;
Sca.val[0]=175;
Sca.val[1]=0;
Sca.val[2]=0;
for(int row=0; row<50; row++)
{
for(int col=0; col<Image->width; col++)
{
cvSet2D(Image,row,col,Sca);
}
}
cvNamedWindow("A",0);
cvShowImage("A",Image);
cvWaitKey(0);