Independently from the programming language, that's simple math: the center of the rectangle is halfway its top-left and bottom-right points
xc = (xtl + xbr) / 2;
yc = (xtl + xbr) / 2;
or if you have the rectangle width and heigh,
xc = xtl + w / 2;
yc = ytl + h / 2;