Close

Stickin it to IT

A project log for DECAL

Decal Evolved-Composite Application Layer for robotics

morningstarMorning.Star 06/24/2017 at 17:450 Comments

I managed to find some decent double-sided tape to experiment with, and it works even better than I expected.

DIY Badge Engineering:


Custom Skin

I had a bit of bother using #TweetyPIE to build the skins with. It uses Python Imaging Library's Transform function which is a pain in the butt to use. For starters I'd need to rewrite it to take a rectangle and produce a polygon, at present it does the opposite.

It also doesnt handle curves or complex polygons, so I wrote a routine to morph one shape into another and used that to custom-fit the design.

It is fairly simple, it scans the shape bitmap line by line and finds the drawn portion, then scales the entire source image line to cover it.

from PIL import Image

srcim1=Image.open('decal_im.png')               # get the source image bitmap
srcmap1=srcim1.load()                           # get the source pixmap into an array
srcim2=Image.open('decal_sh.png')               # get the source shape bitmap
srcmap2=srcim2.load()                           # get the source pixmap into an array
W,H=srcim1.size                                 # get the width and height

dstim=Image.new('RGBA',(W,H),'black')           # make a new image to hold the curved copy
dstmap=dstim.load()                             # get the dest pixmap into an array

for y in range(H):                              # iterate rows
  x1=0.0                                        # reset left edge to left border
  while srcmap2[x1,y][:3]==(0,0,0) and x1<W-1:  # look right for black pixels;
     x1=x1+1                                    # if a black pixel increment left edge
  x2=W-1.0                                      # reset right edge to right border
  while srcmap2[x2,y][:3]==(0,0,0) and x2>=x1:  # look left for black pixels;
    x2=x2-1                                     # if found decrement right edge

  if x1<W-1 and x1<>x2:                         # avoid empty lines
    dw=x2-x1                                    # difference in width between borders and edges
    c=1.0/(W/dw)                                # coefficient of this
    for n in range(W):                          # iterate columns
      dx=(c*n)+x1                               # calculate new position of pixel
      if dx<=W and dx>0:                        # if the coords are valid
        r1,g1,b1,a1=dstmap[dx,y]                # get the pixel at the destination
        r2,g2,b2,a2=srcmap1[n,y]                # get the pixel at the source
        r=r1|r2                                 # binary or them together
        g=g1|g2
        b=b1|b2
        dstmap[dx,dy]=(r,g,b,255)               # write the dest pixel

dstim.save('decal_cmp.png')                     # save the composited image

Discussions