Ask Your Question

Revision history [back]

If cross size is constant (in your example 27X27) you can try template matching :

int main(void) {
Mat img = imread("croix.png", IMREAD_GRAYSCALE);
Mat cross(27, 27, CV_8UC1, Scalar(1));
Mat black(9, 9, CV_8UC1, Scalar(0));
Mat result;
black.copyTo(cross(Rect(0, 0, 9, 9)));
black.copyTo(cross(Rect(18, 0, 9, 9)));
black.copyTo(cross(Rect(0, 18, 9, 9)));
black.copyTo(cross(Rect(18, 18, 9, 9)));
Mat crossF, imgF;
img.convertTo(imgF, CV_32F);
cross.convertTo(crossF, CV_32F);
matchTemplate(imgF, crossF, result, CV_TM_CCORR_NORMED);

Mat plus = result>0.9;
img = imread("croix.png", IMREAD_COLOR);
img(Rect(cross.cols/2, cross.rows / 2,plus.cols,plus.rows)).setTo(Vec3b(0, 0, 255), plus);
imshow("plus", img);
waitKey(0);

small red dot means cross correlation > 0.9 image description For full image you have to zoom image in post image description

If cross size is constant (in your example 27X27) you can try template matching :

int main(void) {
Mat img = imread("croix.png", IMREAD_GRAYSCALE);
Mat cross(27, 27, CV_8UC1, Scalar(1));
Mat black(9, 9, CV_8UC1, Scalar(0));
Mat result;
black.copyTo(cross(Rect(0, 0, 9, 9)));
black.copyTo(cross(Rect(18, 0, 9, 9)));
black.copyTo(cross(Rect(0, 18, 9, 9)));
black.copyTo(cross(Rect(18, 18, 9, 9)));
Mat crossF, imgF;
img.convertTo(imgF, CV_32F);
cross.convertTo(crossF, CV_32F);
matchTemplate(imgF, crossF, result, CV_TM_CCORR_NORMED);

Mat plus = result>0.9;
Mat mask;
dilate(plus, mask, cross);
img = imread("croix.png", IMREAD_COLOR);
img(Rect(cross.cols/2, cross.rows / 2,plus.cols,plus.rows)).setTo(Vec3b(0, 0, 255), plus);
0), mask);
imshow("plus", img);
waitKey(0);

small red dot means cross correlation > 0.9 image description For full image you have to zoom image in post image descriptionResult :

image description

If cross size is constant (in your example 27X27) you can try template matching :

int main(void) {
Mat img = imread("croix.png", IMREAD_GRAYSCALE);
Mat cross(27, 27, CV_8UC1, Scalar(1));
Mat black(9, 9, CV_8UC1, Scalar(0));
Mat result;
black.copyTo(cross(Rect(0, 0, 9, 9)));
black.copyTo(cross(Rect(18, 0, 9, 9)));
black.copyTo(cross(Rect(0, 18, 9, 9)));
black.copyTo(cross(Rect(18, 18, 9, 9)));
Mat crossF, imgF;
img.convertTo(imgF, CV_32F);
cross.convertTo(crossF, CV_32F);
matchTemplate(imgF, crossF, result, CV_TM_CCORR_NORMED);

Mat plus = result>0.9;
result>0.92;// why 0.92? try and test
Mat mask;
dilate(plus, mask, cross);
img = imread("croix.png", IMREAD_COLOR);
img(Rect(cross.cols/2, cross.rows / 2,plus.cols,plus.rows)).setTo(Vec3b(0, 0, 0), mask);
imshow("plus", img);
waitKey(0);

Result :

image descriptionimage description