00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <new>
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
00056
00057
00058 void PrimitivesDrawerCV::DrawCircle(CByteImage *pImage, const Vec2d ¢er, 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 ®ion, 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 }