PrimitivesDrawerCV.cpp
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 
00036 
00037 
00038 // ****************************************************************************
00039 // Includes
00040 // ****************************************************************************
00041 
00042 #include <new> // for explicitly using correct new/delete operators on VC DSPs
00043 
00044 #include "PrimitivesDrawerCV.h"
00045 
00046 #include "Math/Constants.h"
00047 #include "Structs/Structs.h"
00048 #include "Image/IplImageAdaptor.h"
00049 #include "Image/ByteImage.h"
00050 
00051 
00052 
00053 
00054 // ****************************************************************************
00055 // Functions
00056 // ****************************************************************************
00057 
00058 void PrimitivesDrawerCV::DrawCircle(CByteImage *pImage, const Vec2d &center, double radius, int r, int g, int b, int thickness)
00059 {
00060         IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
00061         cvCircle(pIplImage, cvPoint(int(center.x + 0.5), int(center.y + 0.5)), int(radius + 0.5), CV_RGB(b, g, r), thickness);
00062         cvReleaseImageHeader(&pIplImage);
00063 }
00064 
00065 void PrimitivesDrawerCV::DrawEllipse(CByteImage *pImage, const Ellipse2d &ellipse, int r, int g, int b, int thickness)
00066 {
00067         IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
00068         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);
00069         cvReleaseImageHeader(&pIplImage);
00070 }
00071 
00072 void PrimitivesDrawerCV::DrawLine(CByteImage *pImage, const PointPair2d &line, int r, int g, int b, int thickness)
00073 {
00074         IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
00075         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);
00076         cvReleaseImageHeader(&pIplImage);
00077 }
00078 
00079 void PrimitivesDrawerCV::DrawLine(CByteImage *pImage, const Vec2d &p1, const Vec2d &p2, int r, int g, int b, int thickness)
00080 {
00081         IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
00082         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);
00083         cvReleaseImageHeader(&pIplImage);
00084 }
00085 
00086 void PrimitivesDrawerCV::DrawRegion(CByteImage *pImage, const MyRegion &region, int r, int g, int b, int thickness)
00087 {
00088         IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
00089         cvRectangle(pIplImage, cvPoint(region.min_x, region.min_y), cvPoint(region.max_x, region.max_y), CV_RGB(b, g, r), thickness);
00090         cvReleaseImageHeader(&pIplImage);
00091 }
00092 
00093 void PrimitivesDrawerCV::DrawConvexPolygon(CByteImage *pImage, int *pPoints, int nPoints, int r, int g, int b, int thickness)
00094 {
00095         if (nPoints < 2)
00096         {
00097                 printf("error: at least to points must be provided for PrimitivesDrawerCV::DrawConvexPolygon\n");
00098                 return;
00099         }
00100         
00101         CvPoint *points = new CvPoint[nPoints];
00102         for (int i = 0, index = 0; i < nPoints; i++, index += 2)
00103         {
00104                 points[i].x = pPoints[index];
00105                 points[i].y = pPoints[index + 1];
00106         }
00107 
00108 
00109         IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
00110         if (thickness == -1)
00111                 cvFillConvexPoly(pIplImage, points, nPoints, CV_RGB(b, g, r));
00112         else
00113         {
00114                 for (int i = 0; i < nPoints - 1; i++)
00115                         cvLine(pIplImage, points[i], points[i + 1], CV_RGB(b, g, r), thickness);
00116                         
00117                 if (points[0].x != points[nPoints - 1].x || points[0].y != points[nPoints - 1].y)
00118                         cvLine(pIplImage, points[nPoints - 1], points[0], CV_RGB(b, g, r), thickness);
00119         }
00120         cvReleaseImageHeader(&pIplImage);
00121         
00122         delete [] points;
00123 }
00124 
00125 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)
00126 {
00127         CvFont font;
00128         cvInitFont(&font, CV_FONT_VECTOR0, scale_x, scale_y, 0, thickness);
00129         IplImage *pIplImage = IplImageAdaptor::Adapt(pImage);
00130         cvPutText(pIplImage, pText, cvPoint(int(x + 0.5), int(y + 0.5)), &font, CV_RGB(b, g, r));
00131         cvReleaseImageHeader(&pIplImage);
00132 }


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:58