def draw(self, ctx): # Draw surfaces. ctx.save() ctx.move_to(0, 0) ctx.set_source_surface(self._rgb_surface) ctx.paint() ctx.translate(640, 0) ctx.set_source_surface(self._depth_surface) ctx.paint() ctx.restore() # Coordinate system. ctx.set_line_width(1) ctx.set_source_rgb(1.0, 1.0, 1.0) ctx.move_to(640 + 30, 470) ctx.line_to(640 + 10, 470) ctx.line_to(640 + 10, 450) ctx.stroke() ctx.select_font_face('Sans') ctx.set_font_size(12) ctx.move_to(640 + 3, 450) ctx.show_text('y') ctx.stroke() ctx.move_to(640 + 30, 477) ctx.show_text('x') ctx.stroke() # Trace lines. if self._x >= 0 and self._y >= 0: ctx.set_source_rgb(1.0, 0.0, 0.0) ctx.set_line_width(1) ctx.move_to(0, self._y) ctx.line_to(1280, self._y) ctx.stroke() ctx.move_to(self._x, 0) ctx.line_to(self._x, 480) ctx.stroke() ctx.move_to(self._x + 640, 0) ctx.line_to(self._x + 640, 480) ctx.stroke() # Tell about center_depth. depth = self._depth[self._y, self._x] distance = kinect.z_to_cm(depth) if distance != kinect.UNDEF_DISTANCE: text = "(%d, %d) - distance: %0.0f cm (depth = %d)" \ % (self._x, self._y, distance, depth) else: text = "(%d, %d)" % (self._x, self._y) ctx.set_font_size(16) ctx.move_to(950, 475) ctx.set_source_rgb(1, 1, 1) ctx.show_text(text) ctx.stroke() # Draw detected feet in detection zone. ctx.set_line_width(2) ctx.set_source_rgb(1, 0, 0) for obstacle in self._obstacles: raw_data = obstacle[-1] x, y, _ = raw_data[0] ctx.move_to(640 + x, y) for x, y, _ in raw_data[1:]: ctx.line_to(640 + x, y) ctx.stroke() # Tell if images are not from a present device. if not self._found_kinect: ctx.set_font_size(20) ctx.move_to(20, 20) ctx.set_source_rgb(0.0, 0.0, 1.0) ctx.show_text("No Kinect detected, using static picture from disk") ctx.stroke()
def draw(self, ctx): # Coordinate system. ctx.set_line_width(1) ctx.set_source_rgb(0.0, 0.0, 0.0) ctx.move_to(30, 470) ctx.line_to(10, 470) ctx.line_to(10, 450) ctx.stroke() ctx.select_font_face('Sans') ctx.set_font_size(12) ctx.move_to(3, 450) ctx.show_text('z') ctx.stroke() ctx.move_to(30, 477) ctx.show_text('x') ctx.stroke() # Kinect detection cone. ctx.set_line_width(.5) ctx.set_source_rgb(0.0, 0.0, 0.0) ctx.move_to(320, 479) ctx.line_to(0, 0) ctx.stroke() ctx.move_to(320, 479) ctx.line_to(640, 0) ctx.stroke() # Gaming zone. ctx.set_line_width(2) ctx.set_source_rgb(0.0, 0.0, 1.0) ctx.rectangle(80, 0, 480, 360) ctx.stroke() # Current cursor depth. z = kinect.z_to_cm(self._z) if z >= 50.0 and z != kinect.UNDEF_DISTANCE: # Draw line. ctx.set_line_width(1) ctx.set_source_rgb(1.0, 0.0, 0.0) y = self.z_to_pixel(z) ctx.move_to(0, y) ctx.line_to(640, y) ctx.stroke() x = self.x_to_pixel(self._x, z) ctx.move_to(x, y - 5) ctx.line_to(x, y - 10) ctx.stroke() ctx.move_to(x, y + 5) ctx.line_to(x, y + 10) ctx.stroke() # Add distance info. ctx.set_line_width(0.5) ctx.move_to(60, y) ctx.line_to(60, 480) ctx.stroke() ctx.set_font_size(16) ctx.move_to(50, 440) ctx.show_text('z') ctx.stroke() ctx.move_to(500, 440) ctx.show_text('x = %2.2f m' % ( kinect.x_to_cm(self._x, z) / 100.0)) ctx.stroke() ctx.move_to(500, 460) ctx.show_text('y = %2.2f m' % ( kinect.y_to_cm(self._y, z) / 100.0)) ctx.stroke() ctx.move_to(500, 480) ctx.show_text('z = %2.2f m' % (z / 100.0)) ctx.stroke() # Detected feet. ctx.set_line_width(2) ctx.set_source_rgb(0.5, 0, 0) for obstacle in self._obstacles: px, py, pw, ph, z, raw_data = obstacle #print px, py, pw, z x = self.x_to_pixel(px, z) y = self.z_to_pixel(z) w = self.x_to_pixel(pw, z) - x ctx.set_line_width(2) ctx.set_source_rgb(0.0, 1.0, 0.0) ctx.rectangle(x, y, w, 1) ctx.stroke()
def draw(self, ctx): # Coordinate system. ctx.set_line_width(1) ctx.set_source_rgb(0.0, 0.0, 0.0) ctx.move_to(30, 470) ctx.line_to(10, 470) ctx.line_to(10, 450) ctx.stroke() ctx.select_font_face("Sans") ctx.set_font_size(12) ctx.move_to(3, 450) ctx.show_text("z") ctx.stroke() ctx.move_to(30, 477) ctx.show_text("x") ctx.stroke() # Kinect detection cone. ctx.set_line_width(0.5) ctx.set_source_rgb(0.0, 0.0, 0.0) ctx.move_to(320, 479) ctx.line_to(0, 0) ctx.stroke() ctx.move_to(320, 479) ctx.line_to(640, 0) ctx.stroke() # Gaming zone. ctx.set_line_width(2) ctx.set_source_rgb(0.0, 0.0, 1.0) x0, z0, x1, z1 = GAMING_AREA # Centimeters px = self.x_to_pixel(x0) py = self.z_to_pixel(z1) pw = self.x_to_pixel(x1) - px ph = self.z_to_pixel(z0) - py ctx.rectangle(px, py, pw, ph) ctx.stroke() # Current cursor depth. z = kinect.z_to_cm(self._z) if z0 < z < z1: # Draw line. ctx.set_line_width(1) ctx.set_source_rgb(1.0, 0.0, 0.0) py = self.z_to_pixel(z) ctx.move_to(0, py) ctx.line_to(640, py) ctx.stroke() x = -kinect.x_to_cm(self._x, z) px = self.x_to_pixel(x) ctx.move_to(px, py - 5) ctx.line_to(px, py - 10) ctx.stroke() ctx.move_to(px, py + 5) ctx.line_to(px, py + 10) ctx.stroke() # Add distance info. ctx.set_line_width(0.5) ctx.move_to(60, py) ctx.line_to(60, 480) ctx.stroke() ctx.set_font_size(16) ctx.move_to(50, 440) ctx.show_text("z") ctx.stroke() ctx.move_to(500, 440) ctx.show_text("x = %2.2f m" % (kinect.x_to_cm(self._x, z) / 100.0)) ctx.stroke() ctx.move_to(500, 460) ctx.show_text("y = %2.2f m" % (kinect.y_to_cm(self._y, z) / 100.0)) ctx.stroke() ctx.move_to(500, 480) ctx.show_text("z = %2.2f m" % (z / 100.0)) ctx.stroke() # Detected feet. ctx.set_line_width(2) ctx.set_source_rgb(0.5, 0, 0) for obstacle in self._obstacles: x, y, w, h, z, raw_data = obstacle # Obstacle box. px = self.x_to_pixel(-x - w) py = self.z_to_pixel(y) pw = self.x_to_pixel(-x) - px ph = self.z_to_pixel(y + h) - py ctx.rectangle(px, py, pw, ph) ctx.set_line_width(2) ctx.set_source_rgb(0.0, 0.5, 0.0) ctx.stroke() # Raw data from Kinect. px, _, z = raw_data[0] x = self.x_to_pixel(-kinect.x_to_cm(px, z)) y = self.z_to_pixel(z) ctx.move_to(x, y) for px, _, z in raw_data[1:]: x = self.x_to_pixel(-kinect.x_to_cm(px, z)) y = self.z_to_pixel(z) ctx.line_to(x, y) ctx.set_line_width(0.5) ctx.set_source_rgb(0.7, 0.0, 0.0) ctx.stroke()