本文整理汇总了Python中pyglui.cygl.utils.draw_polyline函数的典型用法代码示例。如果您正苦于以下问题:Python draw_polyline函数的具体用法?Python draw_polyline怎么用?Python draw_polyline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了draw_polyline函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_circle
def draw_circle(
self,
circle_center,
circle_normal,
circle_radius,
color=RGBA(1.1, 0.2, 0.8),
num_segments=20,
):
vertices = []
vertices.append((0, 0, 0)) # circle center
# create circle vertices in the xy plane
for i in np.linspace(0.0, 2.0 * math.pi, num_segments):
x = math.sin(i)
y = math.cos(i)
z = 0
vertices.append((x, y, z))
glPushMatrix()
glMatrixMode(GL_MODELVIEW)
glLoadMatrixf(
self.get_pupil_transformation_matrix(
circle_normal, circle_center, circle_radius
)
)
glutils.draw_polyline(
(vertices), color=color, line_type=GL_TRIANGLE_FAN
) # circle
glutils.draw_polyline(
[(0, 0, 0), (0, 0, 4)], color=RGBA(0, 0, 0), line_type=GL_LINES
) # normal
glPopMatrix()
示例2: gl_display_cache_bars
def gl_display_cache_bars(self):
"""
"""
padding = 20.
frame_max = len(self.g_pool.timestamps) #last marker is garanteed to be frame max.
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
width,height = self.win_size
h_pad = padding * (frame_max-2)/float(width)
v_pad = padding* 1./(height-2)
gluOrtho(-h_pad, (frame_max-1)+h_pad, -v_pad, 1+v_pad,-1, 1) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
glTranslatef(0,-.02,0)
color = (7.,.1,.2,8.)
draw_polyline(self.gl_display_ranges,color=RGBA(*color),line_type=GL_LINES,thickness=2.)
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
示例3: draw_markers
def draw_markers(img_size,markers, roi=None):
glfont = fontstash.Context()
glfont.add_font('opensans',get_opensans_font_path())
if roi != None:
glfont.set_size((22 * roi[2]) / float(img_size[1]))
else:
glfont.set_size(22)
glfont.set_color_float((0.2,0.5,0.9,1.0))
for m in markers:
#old method using opencv to draw doesn't show the result on screen
"""
centroid = [m['verts'].sum(axis=0)/4.]
origin = m['verts'][0]
hat = np.array([[[0,0],[0,1],[.5,1.25],[1,1],[1,0]]],dtype=np.float32)
hat = cv2.perspectiveTransform(hat,m_marker_to_screen(m))
cv2.polylines(img,np.int0(hat),color = (0,0,255),isClosed=True)
cv2.polylines(img,np.int0(centroid),color = (255,255,0),isClosed=True,thickness=2)
cv2.putText(img,'id: '+str(m['id']),tuple(np.int0(origin)[0,:]),fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.5, color=(255,100,50))
"""
hat = np.array([[[0,0],[0,1],[.5,1.3],[1,1],[1,0],[0,0]]],dtype=np.float32)
hat = cv2.perspectiveTransform(hat,m_marker_to_screen(m))
draw_polyline(hat.reshape((6,2)),1,RGBA(1.0,0,0,1.0))
glfont.draw_text(m['verts'][0][0][0],m['verts'][0][0][1],'id: '+str(m['id']))
示例4: gl_display
def gl_display(self):
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluOrtho2D(
-self.h_pad, (self.frame_count) + self.h_pad, -self.v_pad, 1 + self.v_pad
) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
if self.drag_mode:
color1 = (0.0, 0.8, 0.5, 0.5)
color2 = (0.0, 0.8, 0.5, 1.0)
else:
color1 = (0.25, 0.8, 0.8, 0.5)
color2 = (0.25, 0.8, 0.8, 1.0)
draw_polyline(verts=[(0, 0), (self.current_frame_index, 0)], color=RGBA(*color1))
draw_polyline(verts=[(self.current_frame_index, 0), (self.frame_count, 0)], color=RGBA(0.5, 0.5, 0.5, 0.5))
draw_points([(self.current_frame_index, 0)], color=RGBA(*color1), size=40)
draw_points([(self.current_frame_index, 0)], color=RGBA(*color2), size=10)
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
示例5: gl_display
def gl_display(self):
"""
use gl calls to render
at least:
the published position of the reference
better:
show the detected postion even if not published
"""
if self.active:
draw_points_norm([self.smooth_pos],size=15,color=RGBA(1.,1.,0.,.5))
if self.active and self.detected:
for e in self.candidate_ellipses:
pts = cv2.ellipse2Poly( (int(e[0][0]),int(e[0][1])),
(int(e[1][0]/2),int(e[1][1]/2)),
int(e[-1]),0,360,15)
draw_polyline(pts,color=RGBA(0.,1.,0,1.))
# lets draw an indicator on the autostop count
e = self.candidate_ellipses[3]
pts = cv2.ellipse2Poly( (int(e[0][0]),int(e[0][1])),
(int(e[1][0]/2),int(e[1][1]/2)),
int(e[-1]),0,360,360/self.auto_stop_max)
indicator = [e[0]] + pts[self.auto_stop:].tolist() + [e[0]]
draw_polyline(indicator,color=RGBA(8.,0.1,0.1,.8),line_type=GL_POLYGON)
else:
pass
示例6: gl_display
def gl_display(self):
"""
use gl calls to render
at least:
the published position of the reference
better:
show the detected postion even if not published
"""
# debug mode within world will show green ellipses around detected ellipses
if self.active:
for marker in self.markers:
e = marker["ellipses"][-1] # outermost ellipse
pts = cv2.ellipse2Poly(
(int(e[0][0]), int(e[0][1])),
(int(e[1][0] / 2), int(e[1][1] / 2)),
int(e[-1]),
0,
360,
15,
)
draw_polyline(pts, 1, RGBA(0.0, 1.0, 0.0, 1.0))
if len(self.markers) > 1:
draw_polyline(
pts, 1, RGBA(1.0, 0.0, 0.0, 0.5), line_type=gl.GL_POLYGON
)
示例7: gl_display
def gl_display(self):
"""
This is where we can draw to any gl surface
by default this is the main window, below we change that
"""
# active our window
active_window = glfwGetCurrentContext()
glfwMakeContextCurrent(self.window)
# start drawing things:
gl_utils.clear_gl_screen()
# set coordinate system to be between 0 and 1 of the extents of the window
gl_utils.make_coord_system_norm_based()
# draw the image
draw_gl_texture(self.img)
# make coordinte system identical to the img pixel coordinate system
gl_utils.make_coord_system_pixel_based(self.img.shape)
# draw some points on top of the image
# notice how these show up in our window but not in the main window
draw_points([(200, 400), (600, 400)], color=RGBA(0., 4., .8, .8), size=self.my_var)
draw_polyline([(200, 400), (600, 400)], color=RGBA(0., 4., .8, .8), thickness=3)
# since this is our own window we need to swap buffers in the plugin
glfwSwapBuffers(self.window)
# and finally reactive the main window
glfwMakeContextCurrent(active_window)
示例8: gl_display
def gl_display(self):
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(-self.h_pad, (self.frame_count)+self.h_pad, -self.v_pad, 1+self.v_pad,-1,1) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
color1 = RGBA(.1,.9,.2,.5)
color2 = RGBA(.1,.9,.9,.5)
if self.in_mark != 0 or self.out_mark != self.frame_count:
draw_polyline( [(self.in_mark,0),(self.out_mark,0)],color=color1,thickness=2)
draw_points([(self.in_mark,0),],color=color1,size=10)
draw_points([(self.out_mark,0),],color=color1,size=10)
if self.sections:
for s in self.sections:
if self.sections.index(s) != self.focus:
draw_polyline( [(s[0],0),(s[1],0)],color=RGBA(.1,.9,.9,.2),thickness=2)
for mark in s:
draw_points([(mark,0),],color=color2,size=5)
if self.mid_sections:
for m in self.mid_sections:
draw_points([(m,0),],color=RGBA(.1,.9,.9,.1),size=10)
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
示例9: gl_display
def gl_display(self):
"""
Display marker and surface info inside world screen
"""
if self.mode == "Show markers and frames":
for m in self.markers:
hat = np.array([[[0,0],[0,1],[.5,1.3],[1,1],[1,0],[0,0]]],dtype=np.float32)
hat = cv2.perspectiveTransform(hat,m_marker_to_screen(m))
draw_polyline(hat.reshape((6,2)),color=RGBA(0.1,1.,1.,.5))
for s in self.surfaces:
s.gl_draw_frame(self.img_shape)
for s in self.surfaces:
if self.locate_3d:
s.gl_display_in_window_3d(self.g_pool.image_tex,self.camera_intrinsics)
else:
s.gl_display_in_window(self.g_pool.image_tex)
if self.mode == "Surface edit mode":
for s in self.surfaces:
s.gl_draw_frame(self.img_shape)
s.gl_draw_corners()
示例10: gl_display
def gl_display(self):
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluOrtho2D(-self.h_pad, (self.frame_count)+self.h_pad, -self.v_pad, 1+self.v_pad) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
# if self.drag_mode:
# color1 = (0.,.8,.5,.5)
# color2 = (0.,.8,.5,1.)
# else:
color1 = (1,1,1,0.4)#(.25,.8,.8,.5)
color2 = (1,1,1,1.)#(.25,.8,.8,1.)
thickness = 10.
draw_polyline(verts=[(0,0),(self.current_frame_index,0)],
thickness=thickness,color=RGBA(*color1))
draw_polyline(verts=[(self.current_frame_index,0),(self.frame_count,0)],
thickness=thickness,color=RGBA(*color1))
if not self.drag_mode:
draw_points([(self.current_frame_index,0)],color=RGBA(*color1),size=30)
draw_points([(self.current_frame_index,0)],color=RGBA(*color2),size=20)
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
示例11: draw_legend
def draw_legend(self, label, width, height, scale):
self.glfont.push_state()
self.glfont.set_align_string(v_align="right", h_align="top")
self.glfont.set_size(15.0 * scale)
self.glfont.draw_text(width, 0, label)
legend_height = 13.0 * scale
pad = 10 * scale
self.glfont.draw_text(width / 2, legend_height, "left")
self.glfont.draw_text(width, legend_height, "right")
self.glfont.pop_state()
cygl_utils.draw_polyline(
[(pad, 1.5 * legend_height), (width / 4, 1.5 * legend_height)],
color=COLOR_LEGEND_EYE_LEFT,
line_type=gl.GL_LINES,
thickness=4.0 * scale,
)
cygl_utils.draw_polyline(
[
(width / 2 + pad, 1.5 * legend_height),
(width * 3 / 4, 1.5 * legend_height),
],
color=COLOR_LEGEND_EYE_RIGHT,
line_type=gl.GL_LINES,
thickness=4.0 * scale,
)
示例12: gl_display
def gl_display(self):
for grid_points in self.img_points:
calib_bounds = cv2.convexHull(grid_points)[:,0] #we dont need that extra encapsulation that opencv likes so much
draw_polyline(calib_bounds,1,RGBA(0.,0.,1.,.5),line_type=gl.GL_LINE_LOOP)
if self._window:
self.gl_display_in_window()
示例13: gl_display_in_window_3d
def gl_display_in_window_3d(self,world_tex,camera_intrinsics):
"""
here we map a selected surface onto a seperate window.
"""
K,dist_coef,img_size = camera_intrinsics['camera_matrix'],camera_intrinsics['dist_coefs'],camera_intrinsics['resolution']
if self._window and self.camera_pose_3d is not None:
active_window = glfwGetCurrentContext()
glfwMakeContextCurrent(self._window)
glClearColor(.8,.8,.8,1.)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glClearDepth(1.0)
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
self.trackball.push()
glMatrixMode(GL_MODELVIEW)
draw_coordinate_system(l=self.real_world_size['x'])
glPushMatrix()
glScalef(self.real_world_size['x'],self.real_world_size['y'],1)
draw_polyline([[0,0],[0,1],[1,1],[1,0]],color = RGBA(.5,.3,.1,.5),thickness=3)
glPopMatrix()
# Draw the world window as projected onto the plane using the homography mapping
glPushMatrix()
glScalef(self.real_world_size['x'], self.real_world_size['y'], 1)
# cv uses 3x3 gl uses 4x4 tranformation matricies
m = cvmat_to_glmat(self.m_from_screen)
glMultMatrixf(m)
glTranslatef(0,0,-.01)
world_tex.draw()
draw_polyline([[0,0],[0,1],[1,1],[1,0]],color = RGBA(.5,.3,.6,.5),thickness=3)
glPopMatrix()
# Draw the camera frustum and origin using the 3d tranformation obtained from solvepnp
glPushMatrix()
glMultMatrixf(self.camera_pose_3d.T.flatten())
draw_frustum(img_size, K, 150)
glLineWidth(1)
draw_frustum(img_size, K, .1)
draw_coordinate_system(l=5)
glPopMatrix()
self.trackball.pop()
glfwSwapBuffers(self._window)
glfwMakeContextCurrent(active_window)
if self.window_should_close:
self.close_window()
示例14: draw_polyline
def draw_polyline(self, segment: model.Classified_Segment):
segment_points = segment.world_2d_points(self._canvas_size)
polyline_color = color_from_segment(segment).to_rgba().channels
polyline_thickness = 2
if not segment_points:
return
gl_utils.draw_polyline(
verts=segment_points,
thickness=float(polyline_thickness),
color=gl_utils.RGBA(*polyline_color),
)
self.draw_id(segment=segment, ref_point=segment_points[-1])
示例15: _draw_markers
def _draw_markers(self):
color = pyglui_utils.RGBA(*self.color_secondary, 0.5)
for marker in self.tracker.markers_unfiltered:
hat = np.array(
[[[0, 0], [0, 1], [0.5, 1.3], [1, 1], [1, 0], [0, 0]]], dtype=np.float32
)
hat = cv2.perspectiveTransform(
hat, _get_norm_to_points_trans(marker.verts_px)
)
pyglui_utils.draw_polyline(hat.reshape((6, 2)), color=color)
if (
marker.perimeter >= self.tracker.marker_min_perimeter
and marker.id_confidence > self.tracker.marker_min_confidence
):
pyglui_utils.draw_polyline(
hat.reshape((6, 2)), color=color, line_type=gl.GL_POLYGON
)