PrimitivesDrawerCV.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 
36 
37 
38 // ****************************************************************************
39 // Includes
40 // ****************************************************************************
41 
42 #include <new> // for explicitly using correct new/delete operators on VC DSPs
43 
44 #include "PrimitivesDrawerCV.h"
45 
46 #include "Math/Constants.h"
47 #include "Structs/Structs.h"
48 #include "Image/IplImageAdaptor.h"
49 #include "Image/ByteImage.h"
50 
51 
52 
53 
54 // ****************************************************************************
55 // Functions
56 // ****************************************************************************
57 
58 void PrimitivesDrawerCV::DrawCircle(CByteImage *pImage, const Vec2d &center, double radius, int r, int g, int b, int thickness)
59 {
60  IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
61  cvCircle(pIplImage, cvPoint(int(center.x + 0.5), int(center.y + 0.5)), int(radius + 0.5), CV_RGB(b, g, r), thickness);
62  cvReleaseImageHeader(&pIplImage);
63 }
64 
65 void PrimitivesDrawerCV::DrawEllipse(CByteImage *pImage, const Ellipse2d &ellipse, int r, int g, int b, int thickness)
66 {
67  IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
68  cvEllipse(pIplImage, cvPoint(int(ellipse.center.x + 0.5), int(ellipse.center.y + 0.5)), cvSize(int(ellipse.radius_x + 0.5), int(ellipse.radius_y + 0.5)), -ellipse.angle * FLOAT_RAD2DEG, 0.0, 360.0, CV_RGB(b, g, r), thickness);
69  cvReleaseImageHeader(&pIplImage);
70 }
71 
72 void PrimitivesDrawerCV::DrawLine(CByteImage *pImage, const PointPair2d &line, int r, int g, int b, int thickness)
73 {
74  IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
75  cvLine(pIplImage, cvPoint(int(line.p1.x + 0.5), int(line.p1.y + 0.5)), cvPoint(int(line.p2.x + 0.5), int(line.p2.y + 0.5)), CV_RGB(b, g, r), thickness);
76  cvReleaseImageHeader(&pIplImage);
77 }
78 
79 void PrimitivesDrawerCV::DrawLine(CByteImage *pImage, const Vec2d &p1, const Vec2d &p2, int r, int g, int b, int thickness)
80 {
81  IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
82  cvLine(pIplImage, cvPoint(int(p1.x + 0.5), int(p1.y + 0.5)), cvPoint(int(p2.x + 0.5), int(p2.y + 0.5)), CV_RGB(b, g, r), thickness);
83  cvReleaseImageHeader(&pIplImage);
84 }
85 
86 void PrimitivesDrawerCV::DrawRegion(CByteImage *pImage, const MyRegion &region, int r, int g, int b, int thickness)
87 {
88  IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
89  cvRectangle(pIplImage, cvPoint(region.min_x, region.min_y), cvPoint(region.max_x, region.max_y), CV_RGB(b, g, r), thickness);
90  cvReleaseImageHeader(&pIplImage);
91 }
92 
93 void PrimitivesDrawerCV::DrawConvexPolygon(CByteImage *pImage, int *pPoints, int nPoints, int r, int g, int b, int thickness)
94 {
95  if (nPoints < 2)
96  {
97  printf("error: at least to points must be provided for PrimitivesDrawerCV::DrawConvexPolygon\n");
98  return;
99  }
100 
101  CvPoint *points = new CvPoint[nPoints];
102  for (int i = 0, index = 0; i < nPoints; i++, index += 2)
103  {
104  points[i].x = pPoints[index];
105  points[i].y = pPoints[index + 1];
106  }
107 
108 
109  IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
110  if (thickness == -1)
111  cvFillConvexPoly(pIplImage, points, nPoints, CV_RGB(b, g, r));
112  else
113  {
114  for (int i = 0; i < nPoints - 1; i++)
115  cvLine(pIplImage, points[i], points[i + 1], CV_RGB(b, g, r), thickness);
116 
117  if (points[0].x != points[nPoints - 1].x || points[0].y != points[nPoints - 1].y)
118  cvLine(pIplImage, points[nPoints - 1], points[0], CV_RGB(b, g, r), thickness);
119  }
120  cvReleaseImageHeader(&pIplImage);
121 
122  delete [] points;
123 }
124 
125 void PrimitivesDrawerCV::PutText(CByteImage *pImage, const char *pText, double x, double y, double scale_x, double scale_y, int r, int g, int b, int thickness)
126 {
127  CvFont font;
128  cvInitFont(&font, CV_FONT_VECTOR0, scale_x, scale_y, 0, thickness);
129  IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
130  cvPutText(pIplImage, pText, cvPoint(int(x + 0.5), int(y + 0.5)), &font, CV_RGB(b, g, r));
131  cvReleaseImageHeader(&pIplImage);
132 }
GLubyte g
Definition: glext.h:5166
void DrawEllipse(CByteImage *pImage, const Ellipse2d &ellipse, int r=255, int g=255, int b=255, int thickness=1)
Deprecated.
int min_x
Definition: Structs.h:333
Vec2d center
The center of the ellipse.
Definition: Structs.h:142
void DrawCircle(CByteImage *pImage, const Vec2d &mid_point, double radius, int r=255, int g=255, int b=255, int thickness=1)
Deprecated.
float y
Definition: Math2d.h:84
void PutText(CByteImage *pImage, const char *pText, double x, double y, double scale_x, double scale_y, int r=255, int g=255, int b=255, int thickness=1)
Draws text into a CByteImage.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
void DrawConvexPolygon(CByteImage *pImage, int *pPoints, int nPoints, int r=255, int g=255, int b=255, int thickness=1)
Draws a polygon into a CByteImage.
GLsizei const GLfloat * points
Definition: glext.h:4388
float angle
The rotiation angle of the ellipse, given in radians.
Definition: Structs.h:161
void DrawRegion(CByteImage *pImage, const MyRegion &region, int r=255, int g=255, int b=255, int thickness=1)
Deprecated.
float radius_y
The radius in vertical direction of the ellipse (vertical refers to when angle = 0).
Definition: Structs.h:152
GLenum GLint x
Definition: glext.h:3125
float x
Definition: Math2d.h:84
GLuint index
Definition: glext.h:3500
Vec2d p1
Definition: Structs.h:73
int min_y
Definition: Structs.h:334
#define FLOAT_RAD2DEG
Definition: Constants.h:51
Data structure for the representation of a 2D ellipse.
Definition: Structs.h:137
GLubyte GLubyte b
Definition: glext.h:5166
int max_x
Definition: Structs.h:335
float radius_x
The radius in horizontal direction of the ellipse (horizontal refers to when angle = 0)...
Definition: Structs.h:147
Vec2d p2
Definition: Structs.h:74
GLdouble GLdouble GLdouble r
Definition: glext.h:3227
GLenum GLint GLint y
Definition: glext.h:3125
Data structure for the representation of a 2D vector.
Definition: Math2d.h:82
IplImage * Adapt(const CByteImage *pImage, bool bAllocateMemory=false)
Converts a CByteImage to an IplImage.
int max_y
Definition: Structs.h:336
void DrawLine(CByteImage *pImage, const PointPair2d &line, int r=255, int g=255, int b=255, int thickness=1)
Deprecated.


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28