SDraw.cc
Go to the documentation of this file.
00001 
00007 #include <blort/Recognizer3D/SDraw.hh>
00008 #include <ros/ros.h>
00009 
00010 namespace P 
00011 {
00012 
00013 void SDraw::DrawLine(IplImage *img, double x1, double y1, double x2, double y2, CvScalar c, int thickness)
00014 {
00015   if(x1+.5 > 0 && x1+.5 < img->height &&
00016      y1+.5 > 0 && y1+.5 < img->width &&
00017      x2+.5 > 0 && x2+.5 < img->height &&
00018      y2+.5 > 0 && y2+.5 < img->width)
00019     {
00020         cvLine(img,cvPoint((int)(x1+.5), (int)(y1+.5)), cvPoint((int)(x2+.5), (int)(y2+.5)), c, thickness);
00021     } else
00022     {
00023         //ROS_WARN("Line parameters out of scope!!");
00024     }
00025 }
00026 
00027 
00028 void SDraw::DrawCross(IplImage *img, double x, double y, CvScalar c, int thickness)
00029 {
00030   cvLine(img,cvPoint((int)(x+.5)-2, (int)(y+.5)-2), cvPoint((int)(x+.5)+2, (int)(y+.5)+2),c,thickness);
00031   cvLine(img,cvPoint((int)(x+.5)-2, (int)(y+.5)+2), cvPoint((int)(x+.5)+2, (int)(y+.5)-2),c,thickness);
00032 }
00033 
00034 
00035 void SDraw::DrawTriangle(IplImage *img, double x1, double y1, double x2, double y2, double x3, double y3, CvScalar c, int thickness)
00036 {
00037   cvLine(img,cvPoint((int)(x1+.5), (int)(y1+.5)), cvPoint((int)(x2+.5), (int)(y2+.5)),c, thickness);
00038   cvLine(img,cvPoint((int)(x2+.5), (int)(y2+.5)), cvPoint((int)(x3+.5), (int)(y3+.5)),c, thickness);
00039   cvLine(img,cvPoint((int)(x3+.5), (int)(y3+.5)), cvPoint((int)(x1+.5), (int)(y1+.5)),c, thickness);
00040 }
00041 
00042 void SDraw::DrawRectangle(IplImage *img, double x1, double y1, double x2, double y2, CvScalar c, int thickness)
00043 {
00044   cvRectangle( img, cvPoint((int)(x1+.5), (int)(y1+.5)), cvPoint((int)(x2+.5), (int)(y2+.5)), c,
00045               thickness);
00046 
00047   /*cvLine(img,cvPoint((int)(x1+.5), (int)(y1+.5)), cvPoint((int)(x2+.5), (int)(y1+.5)),c, thickness);
00048   cvLine(img,cvPoint((int)(x2+.5), (int)(y1+.5)), cvPoint((int)(x2+.5), (int)(y2+.5)),c, thickness);
00049   cvLine(img,cvPoint((int)(x2+.5), (int)(y2+.5)), cvPoint((int)(x1+.5), (int)(y2+.5)),c, thickness);
00050   cvLine(img,cvPoint((int)(x1+.5), (int)(y2+.5)), cvPoint((int)(x1+.5), (int)(y1+.5)),c, thickness);*/
00051 }
00052 
00053 
00054 void SDraw::DrawPoly(IplImage *img, P::Array<Vector2> &vs,CvScalar c, int thickness)
00055 {
00056   unsigned s= vs.Size();
00057   for (unsigned j=0; j<s; j++){
00058     DrawLine(img, vs[j].x, vs[j].y, vs[j+1<s?j+1:0].x, vs[j+1<s?j+1:0].y, c,thickness);
00059   }
00060 }
00061 
00062 
00063 void SDraw::DrawFillPoly(IplImage *img, P::Array<Vector2> &vs,CvScalar c)
00064 {
00065   CvPoint *pts[1];
00066   int npts[1];
00067   pts[0] = (CvPoint*)cvAlloc(vs.Size()*sizeof(pts[0][0]));
00068   npts[0]=vs.Size();
00069 
00070   for (unsigned i=0; i<vs.Size(); i++){
00071     pts[0][i].x=(int)(vs[i].x+.5);
00072     pts[0][i].y=(int)(vs[i].y+.5);
00073   }
00074 
00075   cvFillPoly(img, pts, npts, 1, c);
00076 
00077   //cvFillConvexPoly( img, pts, vs.Size(), c);
00078   cvFree(&pts[0]);
00079 }
00080 
00081 
00082 void SDraw::DrawSIFT(IplImage *img, double x, double y, double l, double o, CvScalar c, int thickness)
00083 {
00084   P::Vector2 p, r[4];
00085 
00086   //scale descriptor (box)
00087   r[0] = P::Vector2(-l,-l);
00088   r[1] = P::Vector2(+l,-l);
00089   r[2] = P::Vector2(+l,+l);
00090   r[3] = P::Vector2(-l,+l);
00091   p = P::Vector2(l,0);
00092 
00093   //rotate box and set position
00094   for (unsigned i=0; i<4; i++){
00095     r[i] = P::Rotate(r[i],-o);
00096     r[i] = P::Vector2(r[i].x+x, r[i].y+y);
00097   }
00098 
00099   p = P::Rotate(p,-o);
00100   p = P::Vector2(p.x+x, p.y+y);
00101 
00102   //draw
00103   for (unsigned i=0; i<4; i++)
00104     cvLine(img,cvPoint((int)(r[i].x+.5), (int)(r[i].y+.5)), cvPoint((int)(r[i<3?i+1:0].x+.5), (int)(r[i<3?i+1:0].y+.5)),c, thickness);
00105   
00106 
00107   cvLine(img,cvPoint((int)(x+.5), (int)(y+.5)), cvPoint((int)(p.x+.5), (int)(p.y+.5)),c, thickness);
00108 
00109   //...or draw circle
00110   //cvCircle( img, cvPoint((int)(x+.5),(int)(y+.5)), l, c, thickness);
00111 }
00112 
00113 void SDraw::DrawCircle(IplImage *img, double x, double y, double r, 
00114                        CvScalar c, int thickness)
00115 {
00116   cvCircle( img, cvPoint((int)(x+.5),(int)(y+.5)), r, c, thickness);
00117 }
00118 
00119 void SDraw::DrawEllipse(IplImage *img, double x, double y, double a, double b, 
00120                         double angle, CvScalar c, int thickness)
00121 {
00122   cvEllipse(img, cvPoint((int)(x+.5),(int)(y+.5)), cvSize((int)(a+.5),(int)(b+.5)),
00123                   angle, 0, 360,  c, thickness, CV_AA, 0);
00124 }
00125 
00126 void SDraw::DrawArc(IplImage *img, double x, double y, double r, double start_angle,
00127              double angular_span, CvScalar c, int thickness)
00128 {
00129   cvEllipse(img, cvPoint((int)(x+.5),(int)(y+.5)), cvSize((int)(r+.5),(int)(r+.5)),
00130             0, (int)(-start_angle*180/M_PI+.5), 
00131             (int)((-start_angle-angular_span)*180/M_PI+.5), c, thickness, CV_AA, 0);
00132 }
00133 
00134 void SDraw::WriteText(IplImage *img, const char* text, double x, double y, CvScalar c)
00135 {
00136   CvFont font;
00137   cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, 1.1, 1.2, 0, 1, CV_AA );
00138   cvPutText( img, text, cvPoint((int)(x+.5),(int)(y+.5)), &font, c);
00139 }
00140 
00141 
00142 }


blort
Author(s): Thomas Mörwald , Michael Zillich , Andreas Richtsfeld , Johann Prankl , Markus Vincze , Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:12