a complete program that shows how to do it. you have several errors, 1) incorrect pixel access(http://www.comp.leeds.ac.uk/vision/opencv/iplimage.html). 2) blur loop is wrong,you are always getting data from top left 3x3 corner. if pixel access is correct, you should get a constant image in dst.
another thing is you would also need to take care of channel information, the program bypass that by reading in a single channel image. otherwise you would need to do the blur for each channel
#include <opencv2/opencv.hpp>
int main(int argc, char* argv[])
{
IplImage* img = cvLoadImage("c:/data/2.jpg",0);
IplImage* dst = cvCloneImage(img);
int height,width,step,channels;
int height2,width2,step2,channels2;
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
uchar* data = (uchar *)img->imageData;
height2 = dst->height; // row
width2 = dst->width; // col
step2 = dst->widthStep; // size of aligned image row in bytes
channels2 = dst->nChannels;
uchar* dstData = (uchar *)dst->imageData;
int total = 0;
int i,j,x,y,tx,ty;
//blur
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int ksize=3;
total=0;
for (x = -ksize/2; x <=ksize/2; x++)
for (y = -ksize/2; y <=ksize/2; y++)
{
tx=i+x;
ty=j+y;
if(tx>=0&&tx<height && ty>=0 && ty<width)
{
total+=data[tx*step+ty];
}
}
dstData[i*step+j] = total/ksize/ksize;
}
}
cvShowImage("img",img);
cvShowImage("dst",dst);
cvWaitKey(0);
}