| 605 | } |
| 606 | |
| 607 | void DrawShape( // draw a shape on an image |
| 608 | CImage& img, // io |
| 609 | const Shape& shape, // in |
| 610 | unsigned color, // in: rrggbb, default is 0xff0000 (red) |
| 611 | bool dots, // in: true for dots only, default is false |
| 612 | int linewidth) // in: default -1 means automatic |
| 613 | { |
| 614 | const double width = ShapeWidth(shape); |
| 615 | if (linewidth <= 0) |
| 616 | linewidth = width > 700? 3: width > 300? 2: 1; |
| 617 | CvScalar cvcolor(ToCvColor(color)); |
| 618 | int i = 0, j=0; |
| 619 | do // use do and not for loop because some points may be unused |
| 620 | { |
| 621 | while (i < shape.rows && !PointUsed(shape, i)) // skip unused points |
| 622 | i++; |
| 623 | if (i < shape.rows) |
| 624 | { |
| 625 | if (dots) |
| 626 | { |
| 627 | const int ix = cvRound(shape(i, IX)), iy = cvRound(shape(i, IY)); |
| 628 | if (ix >= 0 && ix < img.cols && iy >= 0 && iy < img.rows) |
| 629 | { |
| 630 | img(iy, ix)[0] = (color >> 0) & 0xff; |
| 631 | img(iy, ix)[1] = (color >> 8) & 0xff; |
| 632 | img(iy, ix)[2] = (color >> 16) & 0xff; |
| 633 | } |
| 634 | } |
| 635 | else // lines |
| 636 | { |
| 637 | j = i+1; |
| 638 | while (j < shape.rows && !PointUsed(shape, j)) |
| 639 | j++; |
| 640 | if (j < shape.rows) |
| 641 | cv::line(img, |
| 642 | cv::Point(cvRound(shape(i, IX)), cvRound(shape(i, IY))), |
| 643 | cv::Point(cvRound(shape(j, IX)), cvRound(shape(j, IY))), |
| 644 | cvcolor, linewidth); |
| 645 | } |
| 646 | } |
| 647 | i++; |
| 648 | } |
| 649 | while (i < shape.rows && j < shape.rows); |
| 650 | } |
| 651 | |
| 652 | void ImgPrintf( // printf on image |
| 653 | CImage& img, // io |
no test coverage detected