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