1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 
5 /*
6  * MIT License
7  *
8  * Copyright (c) 2018 Pedro Diamel Marrero Fernández
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in all
18  * copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26  * SOFTWARE.
27  */
28 
29 #include "precomp.hpp"
30 #include "charts.hpp"
31 
32 namespace cv
33 {
34 namespace mcc
35 {
CChart()36 CChart::CChart()
37     : perimetro(0), area(0), large_side(0)
38 {
39 }
40 
~CChart()41 CChart::~CChart()
42 {
43 }
44 
45 void CChart::
setCorners(std::vector<cv::Point2f> p)46     setCorners(std::vector<cv::Point2f> p)
47 {
48     cv::Point v1, v2;
49     if (p.empty())
50         return;
51 
52     // copy
53     corners = p;
54 
55     // Sort the corners in anti-clockwise order
56     polyanticlockwise(corners);
57 
58     // Properties
59     area = cv::contourArea(corners);
60     perimetro = perimeter(corners);
61     center = mace_center(corners);
62 
63     v1 = corners[2] - corners[0];
64     v2 = corners[3] - corners[1];
65     large_side = std::max(cv::norm(v1), cv::norm(v2));
66 }
67 
68 //////////////////////////////////////////////////////////////////////////////////////////////
69 
70 CChartDraw::
CChartDraw(CChart & pChart,InputOutputArray image)71     CChartDraw(CChart &pChart, InputOutputArray image)
72     : m_pChart(pChart), m_image(image.getMat())
73 {
74 }
75 
76 void CChartDraw::
drawContour(cv::Scalar color) const77     drawContour(cv::Scalar color /*= CV_RGB(0, 250, 0)*/) const
78 {
79 
80     //Draw lines
81     int thickness = 2;
82     cv::line(m_image, (m_pChart).corners[0], (m_pChart).corners[1], color, thickness, LINE_AA);
83     cv::line(m_image, (m_pChart).corners[1], (m_pChart).corners[2], color, thickness, LINE_AA);
84     cv::line(m_image, (m_pChart).corners[2], (m_pChart).corners[3], color, thickness, LINE_AA);
85     cv::line(m_image, (m_pChart).corners[3], (m_pChart).corners[0], color, thickness, LINE_AA);
86 }
87 
88 void CChartDraw::
drawCenter(cv::Scalar color) const89     drawCenter(cv::Scalar color /*= CV_RGB(0, 0, 255)*/) const
90 {
91     int radius = 3;
92     int thickness = 2;
93     cv::circle(m_image, (m_pChart).center, radius, color, thickness);
94 }
95 } // namespace mcc
96 } // namespace cv
97