00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef DRAW_H
00025 #define DRAW_H
00026
00034 #include "Alvar.h"
00035 #include "Util.h"
00036 #include "Camera.h"
00037 #include "Line.h"
00038 #include <sstream>
00039
00040 namespace alvar {
00041
00048 template<class PointType>
00049 void inline DrawBB(IplImage *image, const std::vector<PointType>& points, CvScalar color, std::string label="")
00050 {
00051 if (points.size() < 2) {
00052 return;
00053 }
00054 PointType minimum = PointType(image->width, image->height);
00055 PointType maximum = PointType(0, 0);
00056 for (int i = 0; i < (int)points.size(); ++i) {
00057 PointType current = points.at(i);
00058 if (current.x < minimum.x) minimum.x = current.x;
00059 if (current.x > maximum.x) maximum.x = current.x;
00060 if (current.y < minimum.y) minimum.y = current.y;
00061 if (current.y > maximum.y) maximum.y = current.y;
00062 }
00063 cvLine(image, cvPoint((int)minimum.x,(int)minimum.y), cvPoint((int)maximum.x,(int)minimum.y), color);
00064 cvLine(image, cvPoint((int)maximum.x,(int)minimum.y), cvPoint((int)maximum.x,(int)maximum.y), color);
00065 cvLine(image, cvPoint((int)maximum.x,(int)maximum.y), cvPoint((int)minimum.x,(int)maximum.y), color);
00066 cvLine(image, cvPoint((int)minimum.x,(int)maximum.y), cvPoint((int)minimum.x,(int)minimum.y), color);
00067 if (!label.empty()) {
00068 CvFont font;
00069 cvInitFont(&font, 0, 0.5, 0.5, 0);
00070 cvPutText(image, label.c_str(), cvPoint((int)minimum.x+1,(int)minimum.y+2), &font, CV_RGB(255,255,0));
00071 }
00072 }
00073
00079 void ALVAR_EXPORT DrawPoints(IplImage *image, const std::vector<CvPoint>& points, CvScalar color);
00080
00087 template<class PointType>
00088 void inline DrawLines(IplImage *image, const std::vector<PointType>& points, CvScalar color, bool loop=true)
00089 {
00090 for(unsigned i = 1; i < points.size(); ++i)
00091 cvLine(image, cvPoint((int)points[i-1].x,(int)points[i-1].y), cvPoint((int)points[i].x,(int)points[i].y), color);
00092 if (loop) {
00093 cvLine(image, cvPoint((int)points[points.size()-1].x,(int)points[points.size()-1].y), cvPoint((int)points[0].x,(int)points[0].y), color);
00094 }
00095 }
00096
00102 void ALVAR_EXPORT DrawLine(IplImage* image, const Line line, CvScalar color = CV_RGB(0,255,0));
00103
00109 void ALVAR_EXPORT DrawPoints(IplImage* image, const CvSeq* contour, CvScalar color = CV_RGB(255,0,0));
00110
00111
00118 void ALVAR_EXPORT DrawCircles(IplImage* image, const CvSeq* contour, int radius, CvScalar color = CV_RGB(255,0,0));
00119
00125 void ALVAR_EXPORT DrawLines(IplImage* image, const CvSeq* contour, CvScalar color = CV_RGB(255,0,0));
00126
00133 template<class PointType>
00134 void inline DrawPoints(IplImage *image, const std::vector<PointType>& points, CvScalar color, int radius=1)
00135 {
00136 for(unsigned i = 0; i < points.size(); ++i)
00137 cvCircle(image, cvPoint((int)points[i].x,(int)points[i].y), radius, color);
00138 }
00139
00147 void ALVAR_EXPORT DrawCVEllipse(IplImage* image, CvBox2D& ellipse, CvScalar color, bool fill=false, double par=0);
00148
00157 void ALVAR_EXPORT BuildHideTexture(IplImage *image, IplImage *hide_texture,
00158 Camera *cam, double gl_modelview[16],
00159 PointDouble topleft, PointDouble botright);
00160
00169 void ALVAR_EXPORT DrawTexture(IplImage *image, IplImage *texture,
00170 Camera *cam, double gl_modelview[16],
00171 PointDouble topleft, PointDouble botright);
00172
00173 }
00174
00175 #endif