如何使用opencv提取下面这幅图片的十字线中心坐标

图片说明

图片说明原图是这样的,已经做过处理

 #include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
using namespace std;
using namespace cv;
Mat img,gray,bw;
vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
int threshval=50;
Rect r;
Rect maxrect,brect;
int idx,n;
int main() {
    cvNamedWindow("img",1);
    img=imread("cross.jpg",1);
    cvtColor(img,gray,CV_BGR2GRAY);
    bw=threshval>128?(gray<threshval):(gray>threshval);
    findContours(bw,contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);
    if (!contours.empty()&&!hierarchy.empty()) {
        idx=0;
        n=0;
        for (;idx>=0;idx=hierarchy[idx][0]) {
            n++;
            if (1==n) {
                maxrect=boundingRect(Mat(contours[idx]));
            } else {
                brect=boundingRect(Mat(contours[idx]));
                CvRect mr(maxrect),br(brect);
                maxrect=cvMaxRect(&mr,&br);
            }
        }
        circle(img,Point(maxrect.x+maxrect.width/2,maxrect.y+maxrect.height/2),2,Scalar(0,0,255));
    }
    imshow("img",img);
    waitKey(0);
    cvDestroyWindow("img");
    return 0;
}