def export(self, wid, *largs): fbo = Fbo(size=wid.size, with_stencilbuffer=True) with fbo: ClearColor(1, 1, 1, 1) ClearBuffers() #Scale(1, -1, 1) #Translate(-self.x, -self.y - self.height, 0) fbo.add(wid.canvas) fbo.draw() img = fbo.texture img.save('test.png') fbo.remove(wid.canvas)
def create_image(self): parent = self.parent if parent: canvas_parent_index = parent.canvas.indexof(self.canvas) if canvas_parent_index > -1: parent.canvas.remove(self.canvas) fbo = Fbo(size=self.size, with_stencilbuffer=True) with fbo: ClearColor(0, 0, 0, 0) ClearBuffers() Scale(1, -1, 1) Translate(-self.x, -self.y - self.height, 0) fbo.add(self.canvas) fbo.draw() image = Image.frombytes('RGBA', list(map(int, self.size)), fbo.texture.pixels, 'raw', 'RGBA', 0, 1) fbo.remove(self.canvas) if parent is not None and canvas_parent_index > -1: parent.canvas.insert(canvas_parent_index, self.canvas) return image
def screenshot(widget, filename='output.png', region=None): if widget.parent is not None: canvas_parent_index = widget.parent.canvas.indexof(widget.canvas) widget.parent.canvas.remove(widget.canvas) fbo = Fbo(size=widget.size) with fbo: ClearColor(0, 0, 0, 0) ClearBuffers() Translate(-widget.x, -widget.y, 0) fbo.add(widget.canvas) fbo.draw() fbo.texture.save(filename) fbo.remove(widget.canvas) if widget.parent is not None: widget.parent.canvas.insert(canvas_parent_index, widget.canvas) return True
def screenshot_texture(widget, factory_func): if widget.parent is not None: canvas_parent_index = widget.parent.canvas.indexof(widget.canvas) widget.parent.canvas.remove(widget.canvas) fbo = Fbo(size=widget.size) with fbo: ClearColor(0, 0, 0, 0) ClearBuffers() Translate(-widget.x, -widget.y, 0) fbo.add(widget.canvas) fbo.draw() result = factory_func(fbo.texture) fbo.remove(widget.canvas) if widget.parent is not None: widget.parent.canvas.insert(canvas_parent_index, widget.canvas) return result
def count_it(num): if num == 0: fbo = Fbo(size=self.stencil.size, with_stencilbuffer=True) with fbo: ClearColor(1, 1, 1, 0) ClearBuffers() img2 = self.paintscreen.bg.texture fbo.add(self.stencil.canvas) fbo.draw() img = fbo.texture fbo.remove(self.stencil.canvas) self.remove_widget(self.paintscreen) im = np.frombuffer(img.pixels, np.uint8) data = np.reshape(im, (im.shape[0], 1)).tostring() data2 = str(data) data2 = str.encode(data2) pix = np.frombuffer(data, np.uint8) a = np.empty_like(pix) a[:] = pix texture = Texture.create(size=self.stencil.size) texture.blit_buffer(a, colorfmt='rgba', bufferfmt='ubyte') self.imge = Image(pos=(0, 0), size=self.paintscreen.stencil.size, texture=texture) #self.paintscreen.stencil.add_widget(self.imge) #img2 = self.paintscreen.grid_layout.bg.texture im2 = np.frombuffer(img2.pixels, np.uint8) data = np.reshape(im2, (im2.shape[0], 1)).tostring() data2 = str(data) data2 = str.encode(data2) pix = np.frombuffer(data, np.uint8) a2 = np.empty_like(pix) a2[:] = pix img2 = a2 print(img2.shape) print(img2) img1 = a print(img1.shape) import cv2 #setting alpha=1, beta=1, gamma=0 gives direct overlay of two images # in theory this would give a direct overlay... #img3 = cv2.addWeighted(img1, 1, img2, 1, 0) #print(img3.shape) im = img1.reshape(1200, 1200, 4) # for i in range(0, 1200): # for j in range(0,1200): # points = im[i,j,:] # if (points[3] == 0):#points[0] == 255 & points[1] == 255 & points[2] == 255): # im[i,j,:] = [255,255,255,0] img_2 = img2.reshape((1200, 1200, 4)) for i in range(0, 1200): for j in range(0, 1200): points1 = im[i, j, :] if (points1[3] != 0): img_2[i, j, :] = im[i, j, :] socket_client.send(img_2) while MESSAGE is None: pass if MESSAGE is not None: new_img = MESSAGE else: new_img = img_2 texture = Texture.create(size=(1200, 1200)) texture.blit_buffer(np.reshape(new_img, (1200 * 1200 * 4, )), colorfmt='rgba', bufferfmt='ubyte') self.paintscreen = PaintScreen() self.add_widget(self.paintscreen) self.paintscreen.bg.texture = texture return num -= 1 self.count.text = str(num) Clock.schedule_once(lambda dt: count_it(num), 1)