34 for(
unsigned i = 0; i < points.size(); ++i)
35 cvLine(image, cvPoint(points[i].
x,points[i].
y), cvPoint(points[i].x,points[i].y), color);
42 p1.x = int(line.
c.x); p1.y = int(line.
c.y);
43 p2.x = int(line.
c.x+line.
s.x*len); p2.y = int(line.
c.y+line.
s.y*len);
44 cvLine(image, p1, p2, color);
46 p1.x = int(line.
c.x); p1.y = int(line.
c.y);
47 p2.x = int(line.
c.x-line.
s.x*len); p2.y = int(line.
c.y-line.
s.y*len);
48 cvLine(image, p1, p2, color);
53 for(
int i = 0; i < contour->total; ++i)
55 CvPoint* pt = (CvPoint*)cvGetSeqElem( contour, i);
56 cvLine(image, cvPoint(pt->x, pt->y), cvPoint(pt->x, pt->y), color);
62 for(
int i = 0; i < contour->total; ++i)
64 CvPoint* pt = (CvPoint*)cvGetSeqElem( contour, i);
65 cvCircle(image, cvPoint(pt->x, pt->y), radius, color);
71 if(contour->total >= 2)
73 for(
int i = 0; i < contour->total; ++i)
75 CvPoint* pt1 = (CvPoint*)cvGetSeqElem( contour, i);
76 CvPoint* pt2 = (CvPoint*)cvGetSeqElem( contour, (i+1)%(contour->total));
77 cvLine(image, cvPoint(pt1->x, pt1->y), cvPoint(pt2->x, pt2->y), color);
85 center.x =
static_cast<int>(ellipse.center.x);
86 center.y =
static_cast<int>(ellipse.center.y);
92 cvEllipse(image, center, cvSize(static_cast<int>(par+ellipse.size.width/2), static_cast<int>(par+ellipse.size.height/2)), -ellipse.angle, 0, 360, color, type);
99 assert(image->origin == 0);
103 double width = abs(botright.x - topleft.x);
104 double height = abs(botright.y - topleft.y);
113 unsigned char pixels[8][3];
114 unsigned char color[3]={0,0,0};
117 double ox,oy,ya,yb,xc,xd,offset;
118 double sizex = width/4, size2x=width/2;
119 double sizey = height/4, size2y=height/2;
127 double l2r=2*width*kx;
128 double l2s=2*height*ky;
132 double xstep=2*objx/hide_texture->width,ystep=2*objy/hide_texture->height;
133 for(i=0;i<hide_texture->width;i++){
135 offset = fmod((objx-ox), size2x);
139 xc = objx+size2x-offset;
140 offset = fmod((objx+ox), size2x);
144 xd = -objx-size2x+offset;
146 for(j=0;j<hide_texture->height;j++){
148 offset = fmod((objy-oy), size2y);
152 ya = objy+size2y-offset;
153 offset = fmod((oy+objy), size2y);
157 yb = -objy-size2y+offset;
160 double points3d[4][3] = {
166 double points2d[4][2];
167 CvMat points3d_mat, points2d_mat;
168 cvInitMatHeader(&points3d_mat, 4, 3, CV_64F, points3d);
169 cvInitMatHeader(&points2d_mat, 4, 2, CV_64F, points2d);
170 cam->
ProjectPoints(&points3d_mat, gl_modelview, &points2d_mat);
171 int kuvanx4 = (int)
Limit(points2d[0][0], 0, image->width-1);
int kuvany4 = (int)
Limit(points2d[0][1], 0, image->height-1);
172 int kuvanx5 = (int)
Limit(points2d[1][0], 0, image->width-1);
int kuvany5 = (int)
Limit(points2d[1][1], 0, image->height-1);
173 int kuvanx6 = (int)
Limit(points2d[2][0], 0, image->width-1);
int kuvany6 = (int)
Limit(points2d[2][1], 0, image->height-1);
174 int kuvanx7 = (int)
Limit(points2d[3][0], 0, image->width-1);
int kuvany7 = (int)
Limit(points2d[3][1], 0, image->height-1);
176 pixels[4][0] = (
unsigned char)cvGet2D(image, kuvany4, kuvanx4).val[0];
177 pixels[4][1] = (
unsigned char)cvGet2D(image, kuvany4, kuvanx4).val[1];
178 pixels[4][2] = (
unsigned char)cvGet2D(image, kuvany4, kuvanx4).val[2];
179 pixels[5][0] = (
unsigned char)cvGet2D(image, kuvany5, kuvanx5).val[0];
180 pixels[5][1] = (
unsigned char)cvGet2D(image, kuvany5, kuvanx5).val[1];
181 pixels[5][2] = (
unsigned char)cvGet2D(image, kuvany5, kuvanx5).val[2];
182 pixels[6][0] = (
unsigned char)cvGet2D(image, kuvany6, kuvanx6).val[0];
183 pixels[6][1] = (
unsigned char)cvGet2D(image, kuvany6, kuvanx6).val[1];
184 pixels[6][2] = (
unsigned char)cvGet2D(image, kuvany6, kuvanx6).val[2];
185 pixels[7][0] = (
unsigned char)cvGet2D(image, kuvany7, kuvanx7).val[0];
186 pixels[7][1] = (
unsigned char)cvGet2D(image, kuvany7, kuvanx7).val[1];
187 pixels[7][2] = (
unsigned char)cvGet2D(image, kuvany7, kuvanx7).val[2];
192 if((i<w)|(j<w)|(i>hide_texture->width-w)|(j>hide_texture->width-w))
194 else if ((i<2*w)|(j<2*w)|(i>hide_texture->width-2*w)|(j>hide_texture->width-2*w))
196 else if ((i<3*w)|(j<3*w)|(i>hide_texture->width-3*w)|(j>hide_texture->width-3*w))
198 else if ((i<4*w)|(j<4*w)|(i>hide_texture->width-4*w)|(j>hide_texture->width-4*w))
203 cvSet2D(hide_texture, j, i, cvScalar(
204 (((lr-r)*pixels[7][0] + r*pixels[6][0]+ s* pixels[4][0] + (ls-s)* pixels[5][0])/l2r),
205 (((lr-r)*pixels[7][1] + r*pixels[6][1]+ s* pixels[4][1] + (ls-s)* pixels[5][1])/l2r),
206 (((lr-r)*pixels[7][2] + r*pixels[6][2]+ s* pixels[4][2] + (ls-s)* pixels[5][2])/l2r),
217 assert(image->origin == 0);
218 double width = abs(botright.x - topleft.x);
219 double height = abs(botright.y - topleft.y);
220 double objx = width/2;
221 double objy = height/2;
224 double points3d[4][3] = {
230 double points2d[4][2];
231 CvMat points3d_mat, points2d_mat;
232 cvInitMatHeader(&points3d_mat, 4, 3, CV_64F, points3d);
233 cvInitMatHeader(&points2d_mat, 4, 2, CV_64F, points2d);
234 cam->
ProjectPoints(&points3d_mat, gl_modelview, &points2d_mat);
238 CvMat map_mat = cvMat(3, 3, CV_64F, map);
239 CvPoint2D32f src[4] = {
241 { 0, float(texture->height-1) },
242 { float(texture->width-1), float(texture->height-1) },
243 { float(texture->width-1), 0 },
245 CvPoint2D32f dst[4] = {
246 { float(points2d[0][0]), float(points2d[0][1]) },
247 { float(points2d[1][0]), float(points2d[1][1]) },
248 { float(points2d[2][0]), float(points2d[2][1]) },
249 { float(points2d[3][0]), float(points2d[3][1]) },
251 cvGetPerspectiveTransform(src, dst, &map_mat);
252 IplImage *img = cvCloneImage(image);
253 IplImage *img2 = cvCloneImage(image);
254 IplImage *mask = cvCreateImage(cvSize(image->width, image->height), 8, 1);
255 IplImage *mask2 = cvCreateImage(cvSize(image->width, image->height), 8, 1);
260 for (
int j=0; j<texture->height; j++) {
261 for (
int i=0; i<texture->width; i++) {
262 CvScalar
s = cvGet2D(texture, j, i);
263 cvSet2D(img, j, i, s);
264 if ((i>0) && (j>0) && (i<(texture->width-1)) && (j<(texture->height-1)))
265 cvSet2D(mask, j, i, cvScalar(1));
268 cvWarpPerspective(img, img2, &map_mat);
269 cvWarpPerspective(mask, mask2, &map_mat, 0);
271 cvCopy(img2, image, mask2);
273 cvReleaseImage(&img);
274 cvReleaseImage(&img2);
275 cvReleaseImage(&mask);
276 cvReleaseImage(&mask2);
void ALVAR_EXPORT DrawCircles(IplImage *image, const CvSeq *contour, int radius, CvScalar color=CV_RGB(255, 0, 0))
Draws circles to the contour points that are obtained by Labeling class.
PointDouble s
Direction vector.
This file implements a collection of functions that are used to visualize lines, contours and corners...
void ALVAR_EXPORT DrawTexture(IplImage *image, IplImage *texture, Camera *cam, double gl_modelview[16], PointDouble topleft, PointDouble botright)
Draws the texture generated by BuildHideTexture to given video frame. For better performance, use OpenGL instead. See SampleMarkerHide.cpp for example implementation.
TFSIMD_FORCE_INLINE const tfScalar & y() const
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Struct representing a line. The line is parametrized by its center and direction vector.
void ProjectPoints(std::vector< CvPoint3D64f > &pw, Pose *pose, std::vector< CvPoint2D64f > &pi) const
Project points.
void ALVAR_EXPORT DrawLine(IplImage *image, const Line line, CvScalar color=CV_RGB(0, 255, 0))
Draws a line.
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & w() const
ALVAR_EXPORT Point< CvPoint2D64f > PointDouble
The default double point type.
void ALVAR_EXPORT BuildHideTexture(IplImage *image, IplImage *hide_texture, Camera *cam, double gl_modelview[16], PointDouble topleft, PointDouble botright)
This function is used to construct a texture image which is needed to hide a marker from the original...
void DrawPoints(IplImage *image, const vector< CvPoint > &points, CvScalar color)
void DrawLines(IplImage *image, const std::vector< PointType > &points, CvScalar color, bool loop=true)
Draws lines between consecutive points stored in vector (polyline).
void ALVAR_EXPORT DrawCVEllipse(IplImage *image, CvBox2D &ellipse, CvScalar color, bool fill=false, double par=0)
Draws OpenCV ellipse.
double ALVAR_EXPORT Limit(double val, double min_val, double max_val)
Limits a number to between two values.
PointDouble c
Line center.