source: level2/competencies/FacET/src/components.cpp @ 234

Revision 74, 2.8 KB checked in by nik, 11 years ago (diff)

FacET import

Line 
1/* $Id: components.cpp 5 2009-03-12 22:30:56Z mw $
2 * +-------------------------------------------------------------------+
3 * | This file contains parts of code from the application created for |
4 * | the Master thesis supervised by Marek Wnuk (Wroclaw University of |
5 * | Technology):  "Wykorzystanie systemu wizyjnego do rozpoznawania   |
6 * | emocji czlowieka" ("Vision system in human emotions recognition") |
7 * | by Marcin Namysl in June 2008.                                    |
8 * +-------------------------------------------------------------------+
9 *
10 * \author Marek Wnuk
11 * \date 2009.02.26
12 * \version 1.00.00
13 */
14
15/*
16    FacET is a library for detecting and parameterising face components.
17    Copyright (C) 2009  Marek Wnuk <marek.wnuk@pwr.wroc.pl>
18
19    This program is free software: you can redistribute it and/or modify
20    it under the terms of the GNU General Public License as published by
21    the Free Software Foundation, either version 3 of the License, or
22    (at your option) any later version.
23
24    This program is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27    GNU General Public License for more details.
28
29    You should have received a copy of the GNU General Public License
30    along with this program.  If not, see <http://www.gnu.org/licenses/>.
31*/
32
33/*! \file components.cpp
34 *
35 * File contains auxiliary functions for equation of straight-line through
36 * two points, calculation of \link ::calcTwoLinesAngle angle between two
37 * lines\endlink, \link ::pointsDistance distance between two points\endlink
38 * and rad/deg conversion.
39 *
40 */
41
42#include "facet.h"
43
44#ifndef M_PI
45# define M_PI           3.14159265358979323846  // pi for windows
46#endif // M_PI
47
48void drawStrLine(CvPoint p1, CvPoint p2, double &a, double &b)
49{
50  a=(p2.y-p1.y)/(p2.x-p1.x);
51  b=p1.y-a*p1.x;
52}
53
54void drawStrLine(CvPoint p1,CvPoint p2,
55                     double &A, double &B, double &C)
56{
57  float dx = p2.x-p1.x;
58  float dy = p2.y-p1.y;
59  float M = sqrt(dx*dx + dy*dy); // distance between two points
60  A=-dy/M;
61  B=dx/M;
62  C=-A*p1.x-B*p1.y;
63}
64
65double calcAngleOX(double A, double B)
66{
67  return atan2(-A,B);
68}
69
70double calcTwoLinesAngle(double A1, double B1, double A2, double B2)
71{
72  //return atan2((A1*B2-A2*B1),(A1*A2+B1*B2));
73  //return (((A1>0 && A2>0)) || ((A1<0) && (A2<0))) ?
74  //atan(A1)-atan(A2) : atan(A1)+atan(A2);
75  return acos((A1*A2 + B1*B2)/(sqrt(A1*A1+B1*B1)*sqrt(A2*A2+B2*B2)));
76}
77
78double calcTwoLinesAngle(double a1, double a2)
79{
80  return atan2(a1-a2, 1+a1*a2);
81}
82
83
84double rad2deg(double rad)
85{
86  return rad*180/M_PI;
87}
88
89double deg2rad(double deg)
90{
91  return deg*M_PI/180;
92}
93
94double pointsDistance(CvPoint p1, CvPoint p2)
95{
96  double dx = p2.x - p1.x;
97  double dy = p2.y - p1.y;
98  return sqrt(dx*dx+dy*dy);
99}
Note: See TracBrowser for help on using the repository browser.