54 #ifndef _XF_OCV_REF_HPP_
55 #define _XF_OCV_REF_HPP_
66 if ((maxval > t1[2]) && (maxval > t2[1]) && (maxval > t2[2]) && (maxval > t2[3]) && (maxval > m1[0]) &&
67 (maxval > m1[1]) && (maxval > m1[3]) && (maxval > m1[4]) && (maxval > b1[1]) && (maxval > b1[2]) &&
68 (maxval > b1[3]) && (maxval > b2[2]))
83 for (j = 0; j < src.cols; j++) {
85 for (k = 0; k < 5; k++) {
88 for (k = 0; k < 5; k++) {
91 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
93 m1[k] = src.at<
NMSTYPE>(ii, jj);
97 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
99 b1[k] = src.at<
NMSTYPE>(ii, jj);
103 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
105 b2[k] = src.at<
NMSTYPE>(ii, jj);
109 }
else if ((j >= 2) && (j < src.cols - 2)) {
110 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
113 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
116 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
117 m1[k] = src.at<
NMSTYPE>(ii, jj);
119 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
120 b1[k] = src.at<
NMSTYPE>(ii, jj);
122 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
123 b2[k] = src.at<
NMSTYPE>(ii, jj);
125 }
else if (j >= src.cols - 2) {
126 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
129 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
132 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
134 m1[k] = src.at<
NMSTYPE>(ii, jj);
138 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
140 b1[k] = src.at<
NMSTYPE>(ii, jj);
144 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
146 b2[k] = src.at<
NMSTYPE>(ii, jj);
152 dst.at<uchar>(i, j) =
result ? 255 : 0;
156 for (j = 0; j < src.cols; j++) {
158 for (k = 0; k < 5; k++) {
161 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
163 t2[k] = src.at<
NMSTYPE>(ii, jj);
167 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
169 m1[k] = src.at<
NMSTYPE>(ii, jj);
173 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
175 b1[k] = src.at<
NMSTYPE>(ii, jj);
179 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
181 b2[k] = src.at<
NMSTYPE>(ii, jj);
185 }
else if ((j >= 2) && (j < src.cols - 2)) {
186 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
189 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
190 t2[k] = src.at<
NMSTYPE>(ii, jj);
192 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
193 m1[k] = src.at<
NMSTYPE>(ii, jj);
195 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
196 b1[k] = src.at<
NMSTYPE>(ii, jj);
198 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
199 b2[k] = src.at<
NMSTYPE>(ii, jj);
201 }
else if (j >= src.cols - 2) {
202 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
205 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
208 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
210 m1[k] = src.at<
NMSTYPE>(ii, jj);
214 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
216 b1[k] = src.at<
NMSTYPE>(ii, jj);
220 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
222 b2[k] = src.at<
NMSTYPE>(ii, jj);
228 dst.at<uchar>(i, j) =
result ? 255 : 0;
231 for (i = 2; i < src.rows - 2; i++) {
232 for (j = 0; j < src.cols; j++) {
234 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
236 t1[k] = src.at<
NMSTYPE>(ii, jj);
240 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
242 t2[k] = src.at<
NMSTYPE>(ii, jj);
246 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
248 m1[k] = src.at<
NMSTYPE>(ii, jj);
252 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
254 b1[k] = src.at<
NMSTYPE>(ii, jj);
258 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
260 b2[k] = src.at<
NMSTYPE>(ii, jj);
264 }
else if ((j >= 2) && (j < src.cols - 2)) {
265 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
266 t1[k] = src.at<
NMSTYPE>(ii, jj);
268 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
269 t2[k] = src.at<
NMSTYPE>(ii, jj);
271 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
272 m1[k] = src.at<
NMSTYPE>(ii, jj);
274 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
275 b1[k] = src.at<
NMSTYPE>(ii, jj);
277 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
278 b2[k] = src.at<
NMSTYPE>(ii, jj);
280 }
else if (j >= src.cols - 2) {
281 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
283 t1[k] = src.at<
NMSTYPE>(ii, jj);
287 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
289 t2[k] = src.at<
NMSTYPE>(ii, jj);
293 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
295 m1[k] = src.at<
NMSTYPE>(ii, jj);
299 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
301 b1[k] = src.at<
NMSTYPE>(ii, jj);
305 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
307 b2[k] = src.at<
NMSTYPE>(ii, jj);
314 dst.at<uchar>(i, j) =
result ? 255 : 0;
319 for (j = 0; j < src.cols; j++) {
321 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
323 t1[k] = src.at<
NMSTYPE>(ii, jj);
327 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
329 t2[k] = src.at<
NMSTYPE>(ii, jj);
333 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
335 m1[k] = src.at<
NMSTYPE>(ii, jj);
339 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
341 b1[k] = src.at<
NMSTYPE>(ii, jj);
345 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
348 }
else if ((j >= 2) && (j < src.cols - 2)) {
349 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
350 t1[k] = src.at<
NMSTYPE>(ii, jj);
352 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
353 t2[k] = src.at<
NMSTYPE>(ii, jj);
355 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
356 m1[k] = src.at<
NMSTYPE>(ii, jj);
358 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
359 b1[k] = src.at<
NMSTYPE>(ii, jj);
361 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
364 }
else if (j >= src.cols - 2) {
365 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
367 t1[k] = src.at<
NMSTYPE>(ii, jj);
371 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
373 t2[k] = src.at<
NMSTYPE>(ii, jj);
377 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
379 m1[k] = src.at<
NMSTYPE>(ii, jj);
383 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
385 b1[k] = src.at<
NMSTYPE>(ii, jj);
389 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
394 dst.at<uchar>(i, j) =
result ? 255 : 0;
398 for (j = 0; j < src.cols; j++) {
400 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
402 t1[k] = src.at<
NMSTYPE>(ii, jj);
406 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
408 t2[k] = src.at<
NMSTYPE>(ii, jj);
412 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
414 m1[k] = src.at<
NMSTYPE>(ii, jj);
418 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
421 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
424 }
else if ((j >= 2) && (j < src.cols - 2)) {
425 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
426 t1[k] = src.at<
NMSTYPE>(ii, jj);
428 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
429 t2[k] = src.at<
NMSTYPE>(ii, jj);
431 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
432 m1[k] = src.at<
NMSTYPE>(ii, jj);
434 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
437 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
440 }
else if (j >= src.cols - 2) {
441 for (k = 0, ii = i - 2, jj = j - 2; k < 5; k++, jj++) {
443 t1[k] = src.at<
NMSTYPE>(ii, jj);
447 for (k = 0, ii = i - 1, jj = j - 2; k < 5; k++, jj++) {
449 t2[k] = src.at<
NMSTYPE>(ii, jj);
453 for (k = 0, ii = i, jj = j - 2; k < 5; k++, jj++) {
455 m1[k] = src.at<
NMSTYPE>(ii, jj);
459 for (k = 0, ii = i + 1, jj = j - 2; k < 5; k++, jj++) {
462 for (k = 0, ii = i + 2, jj = j - 2; k < 5; k++, jj++) {
467 dst.at<uchar>(i, j) =
result ? 255 : 0;
474 if (m1 > t1 && m1 > m0 && m1 > m2 && m1 > b1) Max =
true;
488 for (j = 0; j < src.cols; j++) {
495 m2 = src.at<
NMSTYPE>(i, j + 1);
497 b1 = src.at<
NMSTYPE>(i + 1, j);
498 b2 = src.at<
NMSTYPE>(i + 1, j + 1);
499 }
else if ((j > 0) && (j < src.cols - 1)) {
503 m0 = src.at<
NMSTYPE>(i, j - 1);
505 m2 = src.at<
NMSTYPE>(i, j + 1);
506 b0 = src.at<
NMSTYPE>(i + 1, j - 1);
507 b1 = src.at<
NMSTYPE>(i + 1, j);
508 b2 = src.at<
NMSTYPE>(i + 1, j + 1);
509 }
else if (j == src.cols - 1) {
513 m0 = src.at<
NMSTYPE>(i, j - 1);
516 b0 = src.at<
NMSTYPE>(i + 1, j - 1);
517 b1 = src.at<
NMSTYPE>(i + 1, j);
521 dst.at<uchar>(i, j) =
result ? 255 : 0;
523 for (i = 1; i < src.rows - 1; i++) {
524 for (j = 0; j < src.cols; j++) {
527 t1 = src.at<
NMSTYPE>(i - 1, j);
528 t2 = src.at<
NMSTYPE>(i - 1, j + 1);
531 m2 = src.at<
NMSTYPE>(i, j + 1);
533 b1 = src.at<
NMSTYPE>(i + 1, j);
534 b2 = src.at<
NMSTYPE>(i + 1, j + 1);
535 }
else if ((j > 0) && (j < src.cols - 1)) {
536 t0 = src.at<
NMSTYPE>(i - 1, j - 1);
537 t1 = src.at<
NMSTYPE>(i - 1, j);
538 t2 = src.at<
NMSTYPE>(i - 1, j + 1);
539 m0 = src.at<
NMSTYPE>(i, j - 1);
541 m2 = src.at<
NMSTYPE>(i, j + 1);
542 b0 = src.at<
NMSTYPE>(i + 1, j - 1);
543 b1 = src.at<
NMSTYPE>(i + 1, j);
544 b2 = src.at<
NMSTYPE>(i + 1, j + 1);
545 }
else if (j == src.cols - 1) {
546 t0 = src.at<
NMSTYPE>(i - 1, j - 1);
547 t1 = src.at<
NMSTYPE>(i - 1, j);
549 m0 = src.at<
NMSTYPE>(i, j - 1);
552 b0 = src.at<
NMSTYPE>(i + 1, j - 1);
553 b1 = src.at<
NMSTYPE>(i + 1, j);
557 dst.at<uchar>(i, j) =
result ? 255 : 0;
562 for (j = 1; j < src.cols - 1; j++) {
563 t0 = src.at<
NMSTYPE>(i - 1, j - 1);
564 t1 = src.at<
NMSTYPE>(i - 1, j);
565 t2 = src.at<
NMSTYPE>(i - 1, j + 1);
566 m0 = src.at<
NMSTYPE>(i, j - 1);
568 m2 = src.at<
NMSTYPE>(i, j + 1);
573 dst.at<uchar>(i, j) =
result ? 255 : 0;
577 void ocv_ref(cv::Mat img_gray, cv::Mat& ocv_out_img,
float Th) {
578 cv::Mat gradx, grady;
579 cv::Mat gradx2, grady2, gradxy;
580 cv::Mat gradx2g, grady2g, gradxyg;
581 cv::Mat x2y2, xy, mtrace;
582 cv::Mat dst, ocvthresh_img;
586 cv::Sobel(img_gray, gradx, CV_32FC1, 1, 0,
FILTER_WIDTH, 1, 0, cv::BORDER_CONSTANT);
587 cv::Sobel(img_gray, grady, CV_32FC1, 0, 1,
FILTER_WIDTH, 1, 0, cv::BORDER_CONSTANT);
589 pow(gradx, 2.0, gradx2);
590 pow(grady, 2.0, grady2);
591 multiply(gradx, grady, gradxy);
597 multiply(gradx2g, grady2g, x2y2);
598 multiply(gradxyg, gradxyg, xy);
599 pow((gradx2g + grady2g), 2.0, mtrace);
602 dst.create(img_gray.rows, img_gray.cols, CV_32FC1);
603 ocvthresh_img.create(img_gray.rows, img_gray.cols, dst.depth());
606 for (
int j = 0; j < img_gray.rows; j++) {
607 for (
int i = 0; i < img_gray.cols; i++) {
608 float v1 = x2y2.at<
float>(j, i);
609 float v2 = xy.at<
float>(j, i);
610 float v3 = mtrace.at<
float>(j, i);
611 float temp1 = (v1 - v2) - (0.04 * v3);
612 dst.at<
float>(j, i) = temp1;
614 if (temp1 > 0.0) sum += temp1;
620 for (
int i = 0; i < img_gray.rows; i++) {
621 for (
int j = 0; j < img_gray.cols; j++) {
622 float pix = dst.at<
NMSTYPE>(i, j);
624 ocvthresh_img.at<
NMSTYPE>(i, j) = pix;
626 ocvthresh_img.at<
NMSTYPE>(i, j) = 0;
650 ocvthresh_img.~Mat();
bool OCVFindMaximum2(NMSTYPE *t1, NMSTYPE *t2, NMSTYPE *m1, NMSTYPE *b1, NMSTYPE *b2)
void OCVMaxSuppression2(cv::Mat &src, cv::Mat &dst)
void ocv_ref(cv::Mat img_gray, cv::Mat &ocv_out_img, float Th)
bool OCVFindMaximum1(NMSTYPE t0, NMSTYPE t1, NMSTYPE t2, NMSTYPE m0, NMSTYPE m1, NMSTYPE m2, NMSTYPE b0, NMSTYPE b1, NMSTYPE b2)
void OCVMaxSuppression1(cv::Mat &src, cv::Mat &dst)