def addText(fileName, text): image = Image(fileName) draw = DrawingLayer((IMAGE_WIDTH, IMAGE_HEIGHT)) draw.rectangle((8, 8), (121, 18), filled=True, color=Color.YELLOW) draw.setFontSize(20) draw.text(text, (10, 9), color=Color.BLUE) image.addDrawingLayer(draw) image.save(fileName)
def _WriteText(self, disp, img, txt, color): if (disp is not None): txt = ' ' + txt + ' ' img = img.adaptiveScale(disp.resolution) layer = DrawingLayer((img.width, img.height)) layer.setFontSize(60) layer.ezViewText(txt, (20, 20), fgcolor=color) img.addDrawingLayer(layer) img.applyLayers() img.save(disp)
def _WriteText(self, disp, img, txt,color): if(disp is not None): txt = ' ' + txt + ' ' img = img.adaptiveScale(disp.resolution) layer = DrawingLayer((img.width,img.height)) layer.setFontSize(60) layer.ezViewText(txt,(20,20),fgcolor=color) img.addDrawingLayer(layer) img.applyLayers() img.save(disp)
def loop(): try: json = get_jsonparsed_data(quakeURL) setRGB(0, 128, 64) setRGB(0, 255, 0) # Read distance value from Ultrasonic # distant = ultrasonicRead(ultrasonic_ranger) # button_state=digitalRead(button) # flushLCD('+++ ' + str(distant) + ':' + str(trigger)) analogWrite(led, 255) # count down for photo ! flushLCD('SMILE!') beep(0.01) time.sleep(1) beep(0.02) time.sleep(1) beep(0.1) time.sleep(1) frame = myCamera.getImage() flushLCD('processing ...') ts = time.time() now = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d-%H%M%S') photo = '/home/pi/tmp/' + now + '.jpg' # NOTE MUST use absolute path here! psize = frame.width * frame.height print "Photo Size: " + photo + " " + str(psize) + " w:" + str( frame.width) + " h: " + str(frame.height) myDL = DrawingLayer((frame.width, frame.height)) myDL.setFontSize(80) myDL.text("Quake report from " + json["Ort"] + " with Strength of " + json["LastStrengthString"] + " at: " + json["LastOccured"], (10, 10), color=Color.RED) frame.addDrawingLayer(myDL) frame.applyLayers() frame.save(photo) analogWrite(led, 0) beep(0.05) time.sleep(0.3) beep(0.2) time.sleep(1) # wait save complete ... status = twitterText1 + ' ' + hashtag + ' ' + twitterText2 + ' ' + json[ "Ort"] + ' @:' + now + ' ' + twitterText3 + ' ' + json["Name"] # tweet ... api.update_with_media(photo, status=status) logLCD('TWEETed!') except TypeError: print "Type Error" except IOError: print "IO Error"
def loop(): try: json=get_jsonparsed_data(quakeURL) setRGB(0,128,64) setRGB(0,255,0) # Read distance value from Ultrasonic # distant = ultrasonicRead(ultrasonic_ranger) # button_state=digitalRead(button) # flushLCD('+++ ' + str(distant) + ':' + str(trigger)) analogWrite(led,255) # count down for photo ! flushLCD('SMILE!') beep (0.01) time.sleep (1) beep (0.02) time.sleep(1) beep (0.1) time.sleep (1) frame=myCamera.getImage() flushLCD('processing ...') ts = time.time() now = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d-%H%M%S') photo='/home/pi/tmp/' + now + '.jpg' # NOTE MUST use absolute path here! psize=frame.width*frame.height print "Photo Size: " + photo + " " + str(psize) + " w:" + str(frame.width) + " h: " + str(frame.height) myDL=DrawingLayer((frame.width,frame.height)) myDL.setFontSize(80) myDL.text("Quake report from " + json["Ort"] + " with Strength of " + json["LastStrengthString"] + " at: " + json["LastOccured"] ,(10,10),color=Color.RED) frame.addDrawingLayer(myDL) frame.applyLayers() frame.save(photo) analogWrite(led,0) beep (0.05) time.sleep(0.3) beep(0.2) time.sleep(1) # wait save complete ... status = twitterText1 + ' ' + hashtag + ' ' + twitterText2 + ' ' + json["Ort"] + ' @:' + now + ' ' + twitterText3 + ' ' + json["Name"] # tweet ... api.update_with_media(photo, status=status) logLCD('TWEETed!') except TypeError: print "Type Error" except IOError: print "IO Error"
def encuentraYDibujaAngulos(self, img): """ Ademas de dibujar la estructura de los huesos del brazo devuelve los angulos de dichos huesos con la horizontal """ # Pinto ejes de coordenadas img.dl().line((20, img.height - 20), (20, img.height - 60), Color.RED, width=5) img.dl().line((20, img.height - 20), (60, img.height - 20), Color.RED, width=5) textLayer = DrawingLayer((img.width, img.height)) textLayer.setFontSize(20) textLayer.text("90 grados", (20, img.height - 80), Color.RED) textLayer.text("0 grados", (70, img.height - 20), Color.RED) img.addDrawingLayer(textLayer) angulosHuesos = [] if self.articulaciones != []: self.articulaciones = aux.ordenaListaPorDistanciaApunto( self.articulaciones, [0, 480]) puntoInicial = self.articulaciones.pop() img.dl().circle(puntoInicial, 10, Color.BLUE, width=5) numAngulo = 1 while self.articulaciones != []: p = self.articulaciones.pop() img.dl().line(puntoInicial, p, Color.BLUE, width=5) img.dl().circle(p, 10, Color.BLUE, width=5) textLayer = DrawingLayer((img.width, img.height)) textLayer.setFontSize(24) textLayer.text(str(numAngulo), (p[0], p[1]), Color.RED) img.addDrawingLayer(textLayer) numAngulo += 1 img.applyLayers() angulosHuesos.append( aux.anguloLineaEntreDosPuntos(p, puntoInicial)) puntoInicial = p if len(angulosHuesos) == 3: return angulosHuesos else: return []
def encuentraYDibujaAngulos(self, img): """ Ademas de dibujar la estructura de los huesos del brazo devuelve los angulos de dichos huesos con la horizontal """ # Pinto ejes de coordenadas img.dl().line((20, img.height - 20), (20, img.height - 60), Color.RED, width=5) img.dl().line((20, img.height - 20), (60, img.height - 20), Color.RED, width=5) textLayer = DrawingLayer((img.width, img.height)) textLayer.setFontSize(20) textLayer.text("90 grados", (20, img.height - 80), Color.RED) textLayer.text("0 grados", (70, img.height - 20), Color.RED) img.addDrawingLayer(textLayer) angulosHuesos = [] if self.articulaciones != []: self.articulaciones = aux.ordenaListaPorDistanciaApunto(self.articulaciones, [0,480]) puntoInicial = self.articulaciones.pop() img.dl().circle(puntoInicial, 10, Color.BLUE, width=5) numAngulo = 1 while self.articulaciones != []: p = self.articulaciones.pop() img.dl().line(puntoInicial, p, Color.BLUE, width=5) img.dl().circle(p, 10, Color.BLUE, width=5) textLayer = DrawingLayer((img.width, img.height)) textLayer.setFontSize(24) textLayer.text(str(numAngulo), (p[0] , p[1] ), Color.RED) img.addDrawingLayer(textLayer) numAngulo += 1 img.applyLayers() angulosHuesos.append(aux.anguloLineaEntreDosPuntos(p, puntoInicial)) puntoInicial = p if len(angulosHuesos) == 3: return angulosHuesos else: return []
def get_bounding_box(keyword, url, filename): # get the image img = Image(url) # resize the image so things aren't so slow, if necessary w, h = img.size() if w > 1200 or h > 1200: maxdim = max(w, h) ratio = math.ceil(maxdim/800.0) print " resizing..." img = img.resize(w=int(w/ratio), h=int(h/ratio)) else: ratio = 1 # get the canvas disp = Display((800, 800)) # text overlay textlayer = DrawingLayer(img.size()) textlayer.setFontSize(30) cx, cy = 10, 10 for xoff in range(-2, 3): for yoff in range(-2, 3): textlayer.text(keyword, (cx + xoff, cy + yoff), color=Color.BLACK) textlayer.text(keyword, (cx, cy), color=Color.WHITE) # two points to declare a bounding box point1 = None point2 = None while disp.isNotDone(): cursor = (disp.mouseX, disp.mouseY) if disp.leftButtonUp: if point1 and point2: point1 = None point2 = None if point1: point2 = disp.leftButtonUpPosition() else: point1 = disp.leftButtonUpPosition() bb = None if point1 and point2: bb = disp.pointsToBoundingBox(point1, point2) elif point1 and not point2: bb = disp.pointsToBoundingBox(point1, cursor) img.clearLayers() drawlayer = DrawingLayer(img.size()) if bb: drawlayer.rectangle((bb[0], bb[1]), (bb[2], bb[3]), color=Color.RED) # keyboard commands if pygame.key.get_pressed()[pygame.K_s]: # skip for now raise Skip() elif pygame.key.get_pressed()[pygame.K_b]: # mark it as an invalid picture raise BadImage() elif pygame.key.get_pressed()[pygame.K_RETURN]: if point1 and point2: bb = disp.pointsToBoundingBox(scale(ratio, point1), scale(ratio, point2)) return bb elif not point1 and not point2: bb = disp.pointsToBoundingBox((0, 0), (w, h)) return bb drawlayer.line((cursor[0], 0), (cursor[0], img.height), color=Color.BLUE) drawlayer.line((0, cursor[1]), (img.width, cursor[1]), color=Color.BLUE) #drawlayer.circle(cursor, 2, color=Color.BLUE, filled=True) img.addDrawingLayer(textlayer) img.addDrawingLayer(drawlayer) img.save(disp)
from SimpleCV import Image,Display,DrawingLayer,Color from time import sleep myDisplay = Display() raspberryImage = Image("test.jpg") myDrawingLayer = DrawingLayer((raspberryImage.width, raspberryImage.height)) myDrawingLayer.rectangle((50,20),(250,60),filled=True) myDrawingLayer.setFontSize(45) myDrawingLayer.text("Raspberries!",(50,20),color=Color.WHITE) raspberryImage.addDrawingLayer(myDrawingLayer) raspberryImage.applyLayers() raspberryImage.save(myDisplay) while not myDisplay.isDone(): sleep(0.1)
def loop(): while True: try: setRGB(0,128,64) setRGB(0,255,0) # Read distance value from Ultrasonic distant = ultrasonicRead(ultrasonic_ranger) button_state=digitalRead(button) if (distant <= trigger) and (button_state): # print 'Alarm ', distant,'cm', 'trigger', trigger flushLCD('+++ ' + str(distant) + ':' + str(trigger)) analogWrite(led,255) # count down for photo ! flushLCD('SMILE!') beep (0.01) time.sleep (1) beep (0.02) time.sleep(1) beep (0.1) time.sleep (1) frame=myCamera.getImage() flushLCD('processing ...') faces=frame.findHaarFeatures('face') if faces: print str(len(faces)) + " faces" fct=0 ts = time.time() now = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d-%H%M%S') for face in faces: fct+=1 print "face " + str(fct) + " at: " + str(face.coordinates()) myFace=face.crop() # tweet all faces ... photo='/home/pi/tmp/' + now + 'F-' + str(fct) + '.jpg' # NOTE MUST use absolute path here! psize=myFace.width*myFace.height if psize>20000: #looks like smaller images are thrash print "Photo Size: " + photo + " " + str(psize) myDL=DrawingLayer((myFace.width,myFace.height)) myDL.setFontSize(25) myDL.text("I am " + str(distant) + " cm next to a PiCam!",(myFace.width/2 - 140,10),color=Color.WHITE) myFace.addDrawingLayer(myDL) myFace.applyLayers() myFace.save(photo) beep (0.05) time.sleep(0.3) beep(0.2) time.sleep(1) # wait save complete ... status = 'Look Ma, I did the #lnf16 @ #FHburgenland just now: ' + now # tweet ... api.update_with_media(photo, status=status) logLCD('TWEETed!') else: print "Face skipped too small: " + str(psize) logLCD("Face " + str(fct) + " skipped too small: " + str(psize)) # print 'Sleep before next watch cycle ...' else: logLCD('NO faces detected!') else: # print 'No Alarm ', distant,'cm' , 'trigger', trigger flushLCD('--- ' + str(distant) + ':' + str(trigger)) analogWrite(led,0) time.sleep(1) except TypeError: print "Error" except IOError: print "Error"
def loop(): while True: try: setRGB(0, 128, 64) setRGB(0, 255, 0) # Read distance value from Ultrasonic distant = ultrasonicRead(ultrasonic_ranger) button_state = digitalRead(button) if (distant <= trigger) and (button_state): # print 'Alarm ', distant,'cm', 'trigger', trigger flushLCD('+++ ' + str(distant) + ':' + str(trigger)) analogWrite(led, 255) # count down for photo ! flushLCD('SMILE!') beep(0.01) time.sleep(1) beep(0.02) time.sleep(1) beep(0.1) time.sleep(1) frame = myCamera.getImage() flushLCD('processing ...') faces = frame.findHaarFeatures('face') if faces: print str(len(faces)) + " faces" fct = 0 ts = time.time() now = datetime.datetime.fromtimestamp(ts).strftime( '%Y%m%d-%H%M%S') for face in faces: fct += 1 print "face " + str(fct) + " at: " + str( face.coordinates()) myFace = face.crop() # tweet all faces ... photo = '/home/pi/tmp/' + now + 'F-' + str( fct) + '.jpg' # NOTE MUST use absolute path here! psize = myFace.width * myFace.height if psize > 20000: #looks like smaller images are thrash print "Photo Size: " + photo + " " + str(psize) myDL = DrawingLayer((myFace.width, myFace.height)) myDL.setFontSize(25) myDL.text("I am " + str(distant) + " cm next to a PiCam!", (myFace.width / 2 - 140, 10), color=Color.WHITE) myFace.addDrawingLayer(myDL) myFace.applyLayers() myFace.save(photo) beep(0.05) time.sleep(0.3) beep(0.2) time.sleep(1) # wait save complete ... status = 'Look Ma, I did the #lnf16 @ #FHburgenland just now: ' + now # tweet ... api.update_with_media(photo, status=status) logLCD('TWEETed!') else: print "Face skipped too small: " + str(psize) logLCD("Face " + str(fct) + " skipped too small: " + str(psize)) # print 'Sleep before next watch cycle ...' else: logLCD('NO faces detected!') else: # print 'No Alarm ', distant,'cm' , 'trigger', trigger flushLCD('--- ' + str(distant) + ':' + str(trigger)) analogWrite(led, 0) time.sleep(1) except TypeError: print "Error" except IOError: print "Error"
# This example modified based on examples by Matt Richardson and Shawn Wallace "Getting Started with Raspberry Pi" from SimpleCV import Camera,Display, DrawingLayer, Color from time import sleep myCamera = Camera(prop_set={'width':320,'height':240}) myDisplay = Display(resolution=(320,240)) myDrawingLayer = DrawingLayer((320,240)) while not myDisplay.isDone(): frame = myCamera.getImage() faces = frame.findHaarFeatures('face') if faces: for face in faces: print "Face at: " + str(face.coordinates()) myDrawingLayer.setFontSize(80) myDrawingLayer.rectangle((18,148),(250,60),filled=True) myDrawingLayer.text("Toadman",(20,150),color=Color.GREEN) frame.addDrawingLayer(myDrawingLayer) frame.applyLayers() frame.save(myDisplay) else: print "No faces detected." frame.save(myDisplay) sleep(.1)
img = util.tomaFoto("objeto.jpg", brillo = 55) #img = Image("lineaDe4.jpg") #img.live() # El truco esta en buscar el color azul del tablero en lugar de ir directamente a por las fichas img_tratada = img.binarize() #img_tratada.live() blobGrande = img_tratada.findBlobs().sortArea()[-1] if blobGrande: i_prima = blobGrande.length() / FACTOR_CONVERSION_PIXEL_A_MM d = (ALTURA_OBJETO * DISTANCIA_FOCAL / i_prima) / 10 textLayer = DrawingLayer((img.width,img.height)) textLayer.setFontSize(36) textLayer.text("Distancia = " + str(d) + " centimetros", (10,10), color=Color.RED) blobGrande.draw(width = 5, color = Color.RED) img.addDrawingLayer(img_tratada.dl()) img.addDrawingLayer(textLayer) img.show() util.pausa() else: print "No se han encontrado Blobs"