def processQuote(src): try: img = Image(src) text = img.binarize().readText() except Exception as e: print e print '###' else: cleantext = cleanText(text) translated = trans.translate(cleantext, langpair) if translated: img.drawText(translated, 0, 0, color=Color.BLACK, fontsize=24) print lan1 + ": " + cleantext print lan2 + ": " + translated.encode('utf-8') print '###' img.show()
def activaCamara(): """ Se activa la camara para detectar movimiento utilizando el algormitmo running segmentation de SimpleCV""" global proximo screenLength = resolucion[0] min_blob_size = screenLength * 0.15 max_blob_size = screenLength * 0.75 ahora = datetime.datetime.now() img = util.tomaFoto(filename,brillo,resolucion,modoExposicion) rs.addImage(img) diffImg = rs.getSegmentedImage(False) if diffImg is not None: blobs = diffImg.dilate(3).findBlobs() if blobs is not None : print screenLength, min_blob_size, blobs[-1].length(), max_blob_size if blobs[-1].length() > min_blob_size and blobs[-1].length() < max_blob_size : print "El sensor ha detectado algo relevante" mensaje = 'Alerta ' + str(ahora) + ".jpg" imagen = Image (filename) os.chdir(RUTA_BASE_LOCAL_ALERTAS) blobs.image = imagen blobs[-1].draw(width=5, color=Color.GREEN) imagen.drawText(str(ahora), x= 20, y =10, fontsize=25) imagen.save(str(ahora)+'.jpg') os.chdir(RUTA_BASE_LOCAL) destinatarios = ['*****@*****.**', '*****@*****.**'] mensaje = 'Alerta de la alarma, visita https://www.dropbox.com para ver las fotos' mandaMensaje(mensaje, destinatarios) # --------------------------------------------- # Foto a intervalos regulares # --------------------------------------------- if ahora > proximo : print "tomada foto de cada hora" camara.tomaFoto(str(ahora) + ".jpg", brillo=50,resolucion=(640,480),preview=False,modoExposicion='auto') proximo = datetime.datetime.now() + periodo
def Run(cmdPipe): steadyStateFPS = 10 desiredBuffer = 60*60 #1 minute * 60 seconds numberOfFrames = steadyStateFPS*desiredBuffer; fmt = '%Y-%m-%d %H:%M:%S' disp = Display() filelist = [] frameCounter = 101 sleepTime = .1 while disp.isNotDone(): # check command if cmdPipe.poll(): cmd = cmdPipe.recv() if cmd=='shutdown': print('player', 0, "Shutting down.") break if frameCounter > 100 or len(filelist) == 0: frameCounter = 0 filelist = glob("images/*.jpg") if len(filelist)>numberOfFrames: sleepTime = 1.0/steadyStateFPS print("player", 0, "number of frames in buffer="+str(len(filelist))+" desired="+str(numberOfFrames)+" setting sleeptime to "+str(sleepTime)) else: sleepTime = (1.0/steadyStateFPS)+.01 print("player", 0, "number of frames in buffer="+str(len(filelist))+" desired="+str(numberOfFrames)+" setting sleeptime to "+str(sleepTime)) filename = filelist.pop(0) img = Image(filename) matchObj = re.search(r'[0-9- :]+', filename) d1_ts = time.mktime(datetime.strptime(matchObj.group(), fmt).timetuple()) d2_ts = time.mktime(datetime.utcnow().timetuple()) offset = int(d1_ts-d2_ts)/60 img.drawText(str(offset), x=600, y=470) img.save(disp) os.remove(filename) frameCounter = frameCounter+1 time.sleep(sleepTime)
def run(self): cam_mode=self.cam_mode wsh = self.wsh js = self.js wsh2 = self.wsh2 d = "n" c2 = self.c2 c = self.c sqx = self.sqx sqy = self.sqy x = 0 y = 0 stat="live cam" if cam_mode == 3: img1 = c2.getImage() if cam_mode==1: img1 = c.getImage() time.sleep(1) with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img2 = Image('imagesmall.jpg') time.sleep(.5) img1 = img1.sideBySide(img2) img1 = img1.scale(544,288) time.sleep(.5) if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') self.img1 = img1 blobs = img1.findBlobs() if blobs : ##blobs.draw() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) blobx1 = blobs[-1].x bloby1 = blobs[-1].y print blobx1 print bloby1 img1.drawText("ogp: live cam", 10, 10, fontsize=50) img1.drawText(str(blobx1), blobx1, 250, color=(255,255,255), fontsize=20) img1.drawText(str(bloby1), 10, bloby1, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) sqx2=sqx+20 sqy2=sqy+20 time.sleep(.5) wsh.write_message(wsh2, "live") else: wsh.write_message(wsh2, "live")
def run(self): wsh = self.wsh ## c = self.c js = self.js wsh2 = self.wsh2 acu = int(1) acd = int(1) acl = int(1) acr = int(1) irpic = pinoir2(js) img1 = Image('imagesmall.jpg') blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx1 = blobs[-1].x acy1 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) d = 'r' ms = 50 s.write('4') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx2 = blobs[-1].x acy2 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) d = 'd' ms = 50 s.write('9') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx3 = blobs[-1].x acy3 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) d = 'l' ms = 50 s.write('2') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx4 = blobs[-1].x acy4 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx4), 100, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy4), 100, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) d = 'u' ms = 50 s.write('6') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) acx5 = blobs[-1].x acy5 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx4), 100, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy4), 100, 75, color=(255,255,255), fontsize=20) img1.drawText(str(acx5), 130, 50, color=(255,255,255), fontsize=20) img1.drawText(str(acy5), 130, 75, color=(255,255,255), fontsize=20) img1.save(js.framebuffer) cal1 = acx1 - acx2 cal2 = acy2 - acy3 cal3 = acx3 - acx4 cal4 = acy4 = acy5 time.sleep(2) wsh.write_message(wsh2, "x_" + str(cal1) + "_" + str(cal2) + "_" + str(cal3)+ "_" + str(cal4) )
def run(self): wsh = self.wsh ## c = self.c js = self.js wsh2 = self.wsh2 acu = int(1) acd = int(1) acl = int(1) acr = int(1) irpic = pinoir2(js) img1 = Image('imagesmall.jpg') blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx1 = blobs[-1].x acy1 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) d = 'r' ms = 50 s.write('4') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx2 = blobs[-1].x acy2 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) d = 'd' ms = 50 s.write('9') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx3 = blobs[-1].x acy3 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) d = 'l' ms = 50 s.write('2') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx4 = blobs[-1].x acy4 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx4), 100, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy4), 100, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) d = 'u' ms = 50 s.write('6') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() time.sleep(1) img1 = c.getImage() blobs = img1.findBlobs() img1.drawCircle((blobs[-1].x, blobs[-1].y), 30, color=(255, 255, 255)) img1.drawCircle((blobs[-1].centroid()), 10, color=(255, 100, 100)) acx5 = blobs[-1].x acy5 = blobs[-1].y img1.drawText("ogp: autocalibrating", 10, 10, fontsize=50) img1.drawText(str(acx1), 10, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy1), 10, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx2), 40, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy2), 40, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx3), 70, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy3), 70, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx4), 100, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy4), 100, 75, color=(255, 255, 255), fontsize=20) img1.drawText(str(acx5), 130, 50, color=(255, 255, 255), fontsize=20) img1.drawText(str(acy5), 130, 75, color=(255, 255, 255), fontsize=20) img1.save(js.framebuffer) cal1 = acx1 - acx2 cal2 = acy2 - acy3 cal3 = acx3 - acx4 cal4 = acy4 = acy5 time.sleep(2) wsh.write_message( wsh2, "x_" + str(cal1) + "_" + str(cal2) + "_" + str(cal3) + "_" + str(cal4))
def run(self): cam_mode=self.cam_mode wsh = self.wsh js = self.js wsh2 = self.wsh2 d = "n" acu = int(1) acd = int(1) acl = int(1) acr = int(1) c2=self.c2 c=self.c sqx=self.sqx sqy=self.sqy x=0 y=0 stat="centering" if cam_mode == 3: img1 = c2.getImage() if cam_mode==1: img1 = c.getImage() ## with picamera.PiCamera() as camera: ## camera.resolution = (544, 288) ## camera.capture('imagesmall.jpg') ## img1 = Image('imagesmall.jpg') if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') self.img1 = img1 blobs = img1.findBlobs() if blobs : ##blobs.draw() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) blobx1 = blobs[-1].x bloby1 = blobs[-1].y print blobx1 print bloby1 print "sensor" s.write('n') time.sleep(1) position = "altaz_ " + str(s.readline()) wsh.write_message(wsh2, str(position)) img1.drawText("ogp: chasing", 10, 5, fontsize=40) img1.drawText(str(blobx1), blobx1, 250, color=(255,255,255), fontsize=20) img1.drawText(str(bloby1), 10, bloby1, color=(255,255,255), fontsize=20) img1.drawText(str(position), 10, 50, color=(255,255,255), fontsize=25) sqx2=sqx+20 sqy2=sqy+20 img1.drawRectangle(sqx,sqy,20,20,color=(100,100,255)) img1.save(js.framebuffer) if blobx1 > sqx2: d = 'r' s.write('s') time.sleep(.5) wsh.write_message(wsh2, "g_"+ str(d)) if blobx1 < sqx: d = 'l' s.write('q') time.sleep(.5) wsh.write_message(wsh2, "g_"+ str(d)) if bloby1 > sqy2: d = 'd' s.write('a') time.sleep(.5) wsh.write_message(wsh2, "g_"+ str(d)) if bloby1 < sqy: d = 'u' s.write('w') time.sleep(.5) wsh.write_message(wsh2, "g_"+ str(d)) time.sleep(.5) wsh.write_message(wsh2, "c") else: wsh.write_message(wsh2, "c" ) wsh.write_message(wsh2, "CAPTURE" )
def run(self): cam_mode=self.cam_mode s.write('s') wsh = self.wsh js = self.js wsh2 = self.wsh2 ms = 50 d = "n" acu = int(1) acd = int(1) acl = int(1) acr = int(1) c2=self.c2 sqx=self.sqx sqy=self.sqy x=0 y=0 stat="centering" if cam_mode == 3: img1 = c2.getImage() if cam_mode==1: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') self.img1 = img1 blobs = img1.findBlobs() if blobs : ##blobs.draw() img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,255)) img1.drawCircle((blobs[-1].centroid()),10,color=(255,100,100)) blobx1 = blobs[-1].x bloby1 = blobs[-1].y print blobx1 print bloby1 img1.drawText("ogp: centering", 10, 10, fontsize=50) img1.drawText(str(blobx1), 10, 200, color=(255,255,255), fontsize=50) ##img1.drawText(str(bloby1), 50, 200, color=(255,255,255), fontsize=50) img1.drawText(str(bloby1), 10, 250, color=(255,255,255), fontsize=50) img1.save(js.framebuffer) sqx2=sqx+20 sqy2=sqy+20 if blobx1 > sqx2: d = '_r' s.write('4') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() wsh.write_message(wsh2, "g_"+ str(d)) if blobx1 < sqx: d = 'l' s.write('2') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() wsh.write_message(wsh2, "g_"+ str(d)) if bloby1 > sqy2: d = 'd' s.write('9') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() wsh.write_message(wsh2, "g_"+ str(d)) if bloby1 < sqy: d = 'u' s.write('6') mov = acx(s, d, ms, acu, acd, acl, acr) mov.run() wsh.write_message(wsh2, "g_"+ str(d)) wsh.write_message(wsh2, "c") else: wsh.write_message(wsh2, "c_" + "null" )
if __name__ == '__main__': cam = Camera(0) img = Image() samples = 0 coordinates = redCoords = (0,0) text = " " while True: img = cam.getImage() # Make image black and white tmp = findRedDot(img) if (tmp != None): coordinates= (coordinates[0]+tmp[0][0], coordinates[1]+tmp[0][1]) samples+=1 if samples == 10: samples = 0 coordinates = (coordinates[0]/10, coordinates[1]/10) text = str(coordinates) redCoords = coordinates coordinates = (0,0) redcircle = DrawingLayer((img.width, img.height)) redcircle.circle(redCoords, 5, filled=True, color=(0,255,0)) #add circle point 10,10, radius 10. img.addDrawingLayer(redcircle) img.applyLayers() img.drawText(text) img.show()
# -*- coding: utf-8 -*- from SimpleCV import Display, Image, Color import time img = Image("img-ex3.png") display = Display() img.drawText("Hello World", 50, 50, Color.RED, 50) img.save(display) time.sleep(5) exit()
(pt1, pt2) = line1.end_points #pega os pontos finais da linha if line1.angle() > 18 and line1.angle( ) < 28: #varre linhas entre com angulo de 18 a 28(angulos para linhas da estrada à esquerda) imgBy.dl().line(pt1, pt2, Color.BLUE, width=3) #desenha linha m = math.tan(math.radians(line1.angle( ))) #calcula coeficinte angular da reta, através do angulo da mesma x2_temp = calculaX(m, Y, pt1) #calcula x na reta if x2 > x2_temp: #verifica se é o maior x à esquerda x2 = x2_temp #salva o maior x if line1.angle() > -28 and line1.angle( ) < -18: #varre linhas entre com angulo de 18 a 28(angulos para linhas da estrada à direita) imgBy.dl().line(pt1, pt2, Color.BLUE, width=3) #desenha linha m = math.tan(math.radians(line1.angle( ))) #calcula coeficinte angular da reta, através do angulo da mesma x1_temp = calculaX(m, Y, pt1) #calcula x na reta if x1 < x1_temp: #verifica se é o maior x à direita x1 = x1_temp #salva o maior x #desenha linha entre os pontos da estrada img.dl().line((x1, Y), (x2, Y), Color.RED, width=3) distancia = x2 - x1 #calcula distância print "DISTANCIA: ", distancia #imprime no console text = "DISTANCIA: " + str( math.ceil(distancia)) #formata string par imprimir na imagem img.drawText(text, 120, 220, color=(0, 0, 255), fontsize=32) #imprime valor na imagem img.show() #Exibe imagem
except: conn.rollback() #insert new color values: try: x.execute("""INSERT INTO color_log VALUES (%s,%s,%s,%s)""", (datetime, red, green, blue)) conn.commit() except: conn.rollback() conn.close() #End servier connection colorStr = "(" + str(red) + "," + str(green) + "," + str(blue) + ")" #Draw the average color on the image img.drawText(colorStr, x=10, y=height - 20, color=(255, 0, 0), fontsize=25) #print(color); #print('Displaying image. Press return to exit.'); img.show() #raw_input(); try: print('---*Image Captured*---') print('Captured Color: (' + str(red) + ',' + str(green) + ',' + str(blue) + ')') print('Color difference: (' + str(oldRed - red) + ',' + str(oldGreen - green) + ',' + str(oldBlue - blue) + ')') print('Daily Color Avg: (' + str(avgRed) + ',' + str(avgGreen) + ',' + str(avgBlue) + ')') print('') except: pass
def histo(self): ## this def is the "light meter" part--- cam_mode = self.cam_mode ## the pic gets cataloged if true --- js = self.js w = self.w cent = 0 rgb1 = 0 c2 = self.c2 wsh = self.wsh wsh2 = self.wsh2 i=0 brightpixels=0 darkpixels=0 blobs = 0 if cam_mode == 3: ## sort out the confusing cam modes img1 = c2.getImage() time.sleep(.25) if cam_mode==1: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') if cam_mode==2: with picamera.PiCamera() as camera: camera.resolution = (544, 288) camera.capture('imagesmall.jpg') img1 = Image('imagesmall.jpg') blobs = img1.findBlobs() time.sleep(0.5) if blobs: ##find the blob centroid and cut it out 20x20 crop1 = blobs[-1].x crop2 = blobs[-1].y crop3 = crop1 - 10 crop4 = crop2 - 10 thumbnail = img1.crop(crop3,crop4,20,20) img2 = thumbnail hist = img2.histogram(20) ## split the thumb into 20 levels of darkness brightpixels = hist[10] ## 10 is where the darkest of the light pixels accumulate print brightpixels ##while i < 20: ##old code for if you want to split the histogram in two ##if (i < 10): ##darkpixels = darkpixels + hist[i] ##self.darkpixels = darkpixels ##print hist[i] ##else: ##brightpixels = brightpixels + hist[i] ##self.brightpixels = brightpixels ##print hist[i] ##i = i + 1 if (brightpixels<400): ## heres where it decides to catalog the pic or not... wsh.write_message(wsh2, "histo_" + str(darkpixels) + "_" + str(brightpixels)) print "blob" x = self.x y = self.y p = self.p p = p + 1 thumb1 = "/var/www/html/images/thumbs/thumb" thumb3 = ".png" thumbpath = thumb1 + str(p) + thumb3 print thumbpath thumbnail.save(thumbpath) img1.drawText("blob = True", 10, 35, color=(255,255,255),fontsize=30) img1.drawText("search_mode", 10, 5, color=(0,0,255),fontsize=40) img1.drawText("blob centroid", blobs[-1].x,blobs[-1].y, color=(255,255,255),fontsize=20) img1.drawCircle((blobs[-1].x,blobs[-1].y),30,color=(255,255,0)) img1.drawCircle((blobs[0].centroid()),10,color=(255,255,255)) print blobs[-1].meanColor() rgb1 = blobs[-1].meanColor() cent = blobs[-1].centroid() pth1 = "/var/www/html/images/image" pth3 = ".png" pth = pth1 + str(p) + pth3 print pth img1.save(pth) time.sleep(0.5) self.p = p mySet.add((p,x,y,w,cent,rgb1)) self.mySet = mySet wshx = str(self.x) wshy = str(self.y) centroidx = int(cent[0]) centroidy=int(cent[1]) rcolor=rgb1[0] gcolor=rgb1[1] bcolor=rgb1[2] rcolor=int(rcolor) gcolor=int(gcolor) bcolor=int(bcolor) wsh.write_message(wsh2, "rgb_" + str(rcolor)+"_"+str(gcolor)+"_"+str(bcolor)) wsh.write_message(wsh2, "x_" + str(centroidx)+"_"+str(centroidy)) img1.save(js.framebuffer) time.sleep(0.5) wsh.write_message(wsh2, "d_" + wshx + "_" + wshy + "_" + str(p) ) else: print "senosor dark" print darkpixels,'_', brightpixels blobs = 0 wsh.write_message(wsh2, "histo_" + str(darkpixels) + "_" + str(brightpixels)) else: wshx = str(self.x) wshy = str(self.y) wsh.write_message(wsh2, wshx + " " + wshy + "dark") img1.save(js.framebuffer) print "no blob"