forked from vencejo/Alarma-Visual-Avanzada
/
midiendoDistancias.py
39 lines (27 loc) · 996 Bytes
/
midiendoDistancias.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from SimpleCV import Image , Display, Color, ColorCurve,DrawingLayer
import picamera
import utilidades as util
#import numpy as np
ALTURA_OBJETO = 85 #mm
DISTANCIA_FOCAL = 3.6 #mm
FACTOR_CONVERSION_PIXEL_A_MM = 295
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"