void PintarFeatures(IplImage& vx,IplImage& vy,IplImage& windowBackground,CvPoint2D32f frame1_features[],int number_of_features,float optical_flow_feature_error[],char optical_flow_found_feature[]) { for(int i = 0; i < number_of_features; i++) { int line_thickness=1; CvScalar line_color = CV_RGB(0,255,0); CvPoint p,q; p.x = (int) frame1_features[i].x; p.y = (int) frame1_features[i].y; q.x =p.x+ cvGetReal2D(&vx, p.y,p.x); q.y =p.y + cvGetReal2D(&vy, p.y,p.x); PaintPoint(p,q,windowBackground,line_thickness,line_color,1); } }
void PintarLK(IplImage& vx,IplImage& vy,IplImage& windowBackground) { int step=5; for(int i = 0; i < vx.height; i+=step) { for(int j=0;j<vx.width;j+=step) { int line_thickness = line_thickness = 1; CvScalar line_color = CV_RGB(255,0,0); CvPoint p,q; p.x = j; p.y = i; q.x =j + cvGetReal2D(&vx, i, j); q.y =i + cvGetReal2D(&vy, i, j); if(p.x!=q.x || p.y!=q.y) PaintPoint(p,q,windowBackground,line_thickness,line_color,4); } } }
bool PintarPiramide(IplImage& windowBackground,LKPiramidResults& data,int minDistance,int maxDistance) { int count=0; /* For fun (and debugging :)), let's draw the flow field. */ for(int i = 0; i < data.count; i++) { if ( data.optical_flow_found_feature[i] == 0 ) continue; int line_thickness = 1; /* CV_RGB(red, green, blue) is the red, green, and blue components * of the color you want, each out of 255. */ CvScalar line_color = CV_RGB(0,0,255); /* Let's make the flow field look nice with arrows. */ /* The arrows will be a bit too short for a nice visualization because of the high framerate * (ie: there's not much motion between the frames). So let's lengthen them by a factor of 3. */ CvPoint p,q; p.x = (int)data.frameA_features[i].x; p.y = (int)data.frameA_features[i].y; q.x = (int)data.frameB_features[i].x; q.y = (int)data.frameB_features[i].y; float distancia=sqrt(pow(float(data.frameA_features[i].x-data.frameB_features[i].x),2)+pow(float(data.frameA_features[i].y-data.frameB_features[i].y),2)); if(distancia>minDistance &&distancia<maxDistance) { PaintPoint(p,q,windowBackground,line_thickness,line_color,2); count++; } } return count>0; }
void TopographyFileRenderer::Paint(Canvas &canvas, const WindowProjection &projection) { if (file.IsEmpty()) return; fixed map_scale = projection.GetMapScale(); if (!file.IsVisible(map_scale)) return; UpdateVisibleShapes(projection); if (visible_shapes.empty()) return; // TODO code: only draw inside screen! // this will save time with rendering pixmaps especially // we already do an outer visibility test, but may need a test // in screen coords #ifdef ENABLE_OPENGL pen.Set(); brush.Set(); #else shape_renderer.Configure(&pen, &brush); #endif // get drawing info #ifdef ENABLE_OPENGL const unsigned level = file.GetThinningLevel(map_scale); const unsigned min_distance = file.GetMinimumPointDistance(level) / Layout::Scale(1); #ifndef HAVE_GLES float opengl_matrix[16]; glGetFloatv(GL_MODELVIEW_MATRIX, opengl_matrix); #endif glPushMatrix(); fixed angle = projection.GetScreenAngle().Degrees(); fixed scale = projection.GetScale(); const RasterPoint &screen_origin = projection.GetScreenOrigin(); #ifdef HAVE_GLES #ifdef FIXED_MATH GLfixed fixed_angle = angle.as_glfixed(); GLfixed fixed_scale = scale.as_glfixed_scale(); #else GLfixed fixed_angle = angle * (1<<16); GLfixed fixed_scale = scale * (1LL<<32); #endif glTranslatex((int)screen_origin.x << 16, (int)screen_origin.y << 16, 0); glRotatex(fixed_angle, 0, 0, -(1<<16)); glScalex(fixed_scale, fixed_scale, 1<<16); #else glTranslatef(screen_origin.x, screen_origin.y, 0.); glRotatef((GLfloat)angle, 0., 0., -1.); glScalef((GLfloat)scale, (GLfloat)scale, 1.); #endif #else // !ENABLE_OPENGL const GeoClip clip(projection.GetScreenBounds().Scale(fixed(1.1))); AllocatedArray<GeoPoint> geo_points; int iskip = file.GetSkipSteps(map_scale); #endif for (auto it = visible_shapes.begin(), end = visible_shapes.end(); it != end; ++it) { const XShape &shape = **it; if (!projection.GetScreenBounds().Overlaps(shape.get_bounds())) continue; #ifdef ENABLE_OPENGL const ShapePoint *points = shape.get_points(); const ShapePoint translation = shape.shape_translation(projection.GetGeoLocation()); glPushMatrix(); #ifdef HAVE_GLES glTranslatex(translation.x, translation.y, 0); #else glTranslatef(translation.x, translation.y, 0.); #endif #else // !ENABLE_OPENGL const unsigned short *lines = shape.get_lines(); const unsigned short *end_lines = lines + shape.get_number_of_lines(); const GeoPoint *points = shape.get_points(); #endif switch (shape.get_type()) { case MS_SHAPE_NULL: break; case MS_SHAPE_POINT: #ifdef ENABLE_OPENGL #ifdef HAVE_GLES PaintPoint(canvas, projection, shape, NULL); #else PaintPoint(canvas, projection, shape, opengl_matrix); #endif #else // !ENABLE_OPENGL PaintPoint(canvas, projection, lines, end_lines, points); #endif break; case MS_SHAPE_LINE: { #ifdef ENABLE_OPENGL #ifdef HAVE_GLES glVertexPointer(2, GL_FIXED, 0, &points[0].x); #else glVertexPointer(2, GL_INT, 0, &points[0].x); #endif const GLushort *indices, *count; if (level == 0 || (indices = shape.get_indices(level, min_distance, count)) == NULL) { count = shape.get_lines(); const GLushort *end_count = count + shape.get_number_of_lines(); for (int offset = 0; count < end_count; offset += *count++) glDrawArrays(GL_LINE_STRIP, offset, *count); } else { const GLushort *end_count = count + shape.get_number_of_lines(); for (; count < end_count; indices += *count++) glDrawElements(GL_LINE_STRIP, *count, GL_UNSIGNED_SHORT, indices); } #else // !ENABLE_OPENGL for (; lines < end_lines; ++lines) { unsigned msize = *lines; shape_renderer.Begin(msize); const GeoPoint *end = points + msize - 1; for (; points < end; ++points) shape_renderer.AddPointIfDistant(projection.GeoToScreen(*points)); // make sure we always draw the last point shape_renderer.AddPoint(projection.GeoToScreen(*points)); shape_renderer.FinishPolyline(canvas); } #endif } break; case MS_SHAPE_POLYGON: #ifdef ENABLE_OPENGL { const GLushort *index_count; const GLushort *triangles = shape.get_indices(level, min_distance, index_count); #ifdef HAVE_GLES glVertexPointer(2, GL_FIXED, 0, &points[0].x); #else glVertexPointer(2, GL_INT, 0, &points[0].x); #endif glDrawElements(GL_TRIANGLE_STRIP, *index_count, GL_UNSIGNED_SHORT, triangles); } #else // !ENABLE_OPENGL for (; lines < end_lines; ++lines) { unsigned msize = *lines / iskip; /* copy all polygon points into the geo_points array and clip them, to avoid integer overflows (as RasterPoint may store only 16 bit integers on some platforms) */ geo_points.GrowDiscard(msize * 3); for (unsigned i = 0; i < msize; ++i) geo_points[i] = points[i * iskip]; msize = clip.ClipPolygon(geo_points.begin(), geo_points.begin(), msize); if (msize < 3) continue; shape_renderer.Begin(msize); for (unsigned i = 0; i < msize; ++i) { GeoPoint g = geo_points[i]; shape_renderer.AddPointIfDistant(projection.GeoToScreen(g)); } shape_renderer.FinishPolygon(canvas); } #endif break; } #ifdef ENABLE_OPENGL glPopMatrix(); #endif } #ifdef ENABLE_OPENGL glPopMatrix(); #else shape_renderer.Commit(); #endif }