13 std::string& additionalInfo)
15 assert(in.rows == in.cols);
17 if (in.type() == CV_8UC1)
20 cv::cvtColor(in, grey, CV_BGR2GRAY);
22 cv::threshold(grey, grey, 125, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);
24 std::map<uint32_t, std::vector<cv::Mat> > nbits_innerCodes;
28 int nbits = bitsids.first;
29 std::vector<cv::Mat> innerCodes;
32 if (innerCodes.size() > 0)
34 if (sum(innerCodes[0])[0] != 0)
36 nbits_innerCodes[nbits] = innerCodes;
41 if (nbits_innerCodes.size() == 0)
45 for (
auto bit_innerCodes : nbits_innerCodes)
47 uint32_t nb = bit_innerCodes.first;
48 auto innerCodes = bit_innerCodes.second;
50 for (
int i = 0; i < 4; i++)
71 std::vector<cv::Mat>& innerCodes)
73 int bits_noborder =
static_cast<int>(std::sqrt(total_nbits));
74 int bits_withborder = bits_noborder + 2;
77 cv::Mat nonZeros(bits_withborder, bits_withborder, CV_32SC1);
78 cv::Mat nValues(bits_withborder, bits_withborder, CV_32SC1);
79 nonZeros.setTo(cv::Scalar::all(0));
80 nValues.setTo(cv::Scalar::all(0));
81 for (
int y = 0; y < thres_img.rows; y++)
83 const uchar* ptr = thres_img.ptr<uchar>(y);
84 int my = float(bits_withborder) * float(y) / float(thres_img.rows);
85 for (
int x = 0; x < thres_img.cols; x++)
87 int mx = float(bits_withborder) * float(x) / float(thres_img.cols);
89 nonZeros.at<
int>(my, mx)++;
90 nValues.at<
int>(my, mx)++;
93 cv::Mat binaryCode(bits_withborder, bits_withborder, CV_8UC1);
95 for (
int y = 0; y < bits_withborder; y++)
96 for (
int x = 0; x < bits_withborder; x++)
98 if (nonZeros.at<
int>(y, x) > nValues.at<
int>(y, x) / 2)
99 binaryCode.at<uchar>(y, x) = 1;
101 binaryCode.at<uchar>(y, x) = 0;
105 for (
int y = 0; y < bits_withborder; y++)
107 int inc = bits_withborder - 1;
108 if (y == 0 || y == bits_withborder - 1)
110 for (
int x = 0; x < bits_withborder; x += inc)
111 if (binaryCode.at<uchar>(y, x) != 0)
116 cv::Mat _bits(bits_noborder, bits_noborder, CV_8UC1);
117 for (
int y = 0; y < bits_noborder; y++)
118 for (
int x = 0; x < bits_noborder; x++)
119 _bits.at<uchar>(y, x) = binaryCode.at<uchar>(y + 1, x + 1);
125 innerCodes.push_back(_bits);
136 for (
int i = 0; i < in.rows; i++)
138 for (
int j = 0; j < in.cols; j++)
140 out.at<uchar>(i, j) = in.at<uchar>(in.cols - j - 1, i);