Use the following code for creating a MxM rectangle with center at x,y. Points a,b can be used as the anchor points for the rectangle in the rect function of OpenCV
Point a;
Point b;
//MxM rectangle
a.x = x - M/2;
a.y = y - M/2;
b.x = x + M/2;
b.y = y + M/2;