本文整理汇总了Python中SimpleCV.Image.colorDistance方法的典型用法代码示例。如果您正苦于以下问题:Python Image.colorDistance方法的具体用法?Python Image.colorDistance怎么用?Python Image.colorDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.Image
的用法示例。
在下文中一共展示了Image.colorDistance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trataImagen
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def trataImagen(self):
img = Image(self.rutaImagenReducida)
result = img.colorDistance((self.ajustes.r, self.ajustes.g, self.ajustes.b))
result.save(self.rutaImagenTratada_Fase1)
result = result.invert()
result = result.binarize(float(self.ajustes.umbralBinarizado)).invert()
result.save(self.rutaImagenTratada_Fase2)
示例2: trataImagen
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def trataImagen(self, r, g, b, umbralBinarizado):
inicio = time.time()
img = Image(self.rutaImagenReducida)
result = img.colorDistance((r, g, b)).invert()
result = result.binarize(umbralBinarizado).invert()
result.save(self.rutaImagenTratada)
fin = time.time()
self.tiempoTratamiento = fin - inicio
示例3: findYellowMask
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def findYellowMask(image_file):
original = Image(image_file)
yellow_only = original.colorDistance((232,166,30))
yellow_only = yellow_only*4
mask = yellow_only.invert()
#mask.save("yellow_mask.jpg")
binarizedMask = mask.binarize().invert()
#binarizedMask.save("binarized_mask_yellow.jpg")
return binarizedMask
示例4: dot_blobs
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def dot_blobs(si, image_path):
new_file_path = step_file_path(si, 'dot-blobs')
img = Image(image_path)
new_img = img.colorDistance((160, 255, 160)).invert().binarize((200, 200, 200)).invert().erode(1)
dots = sorted(new_img.findBlobs()[-5:], key=lambda blob: blob.centroid()[1])
for blob in dots:
blob.draw()
new_img.dl().circle(blob.centroid(), 5, Color.RED)
centroids = map(lambda blob: blob.centroid(), dots)
bottom_screws = sorted(centroids[2:4], key=lambda centroid: centroid[0])
shoe_measurements = ShoeMeasurements(si.foot, centroids[0], centroids[1], bottom_screws[0], bottom_screws[1], centroids[4])
new_img = shoe_measurements.draw_on_img(new_img)
new_img.save(new_file_path)
si.step_outputs.append(new_file_path)
return (new_file_path, shoe_measurements)
示例5: find
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def find(self):
new_file_path = self.nfn('dot-blobs')
img = Image(self.img_path)
new_img = img.colorDistance((160, 255, 160)).invert().binarize((200, 200, 200)).invert().erode(1)
for blob in new_img.findBlobs():
print str(blob) + " --> " + str(self.chance_blob_is_an_ellipse(blob))
dots = sorted(new_img.findBlobs()[-5:], key=lambda blob: blob.centroid()[1])
for blob in dots:
blob.draw()
new_img.dl().circle(blob.centroid(), 5, Color.RED)
centroids = map(lambda blob: blob.centroid(), dots)
bottom_screws = sorted(centroids[2:4], key=lambda centroid: centroid[0])
shoe_measurements = ShoeMeasurements(self.shoe.left_or_right, centroids[0], centroids[1], bottom_screws[0], bottom_screws[1], centroids[4])
new_img = shoe_measurements.draw_on_img(new_img)
new_img.save(new_file_path)
return (new_file_path, shoe_measurements)
示例6: detectCenter
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def detectCenter(image_file):
original = Image(image_file)
center_only = original.colorDistance((155,9,49))*8
mask = center_only.invert()
#mask.save("center_mask.jpg")
binarizedMask = mask.binarize().invert()
#binarizedMask.save("binarized_mask_center.jpg")
blobs = original.findBlobsFromMask(binarizedMask)
if blobs == None :
#print "No red found"
return detectGreenLowQuality(image_file)
bestBlob = blobs[-1]
bestBlob.drawMinRect(color=Color.RED,width =10)
bestBlob.image = original
original.save("align.png")
centroidX = bestBlob.minRectX()
centroidY = bestBlob.minRectY()
#Have to find out which part of the screen centroid is in
maxX = original.getNumpy().shape[0]
maxY = original.getNumpy().shape[1]+100
#assume width of 150 pixels
return align_center(maxX,maxY,centroidX,centroidY,80,80)
示例7: detectYellowLowQuality
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def detectYellowLowQuality(image_file):
original = Image(image_file)
yellow_only = original.colorDistance((156,130,76))*2
#yellow_only = yellow_only*4
mask = yellow_only.invert()
#mask.save("yellow_mask.jpg")
binarizedMask = mask.binarize().invert()
#binarizedMask.save("binarized_mask_yellow.jpg")
blobs = original.findBlobsFromMask(binarizedMask)
if blobs == None:
#print "No yellow found"
return -1
blobs[-1].drawMinRect(color=Color.RED,width =10)
blobs.image = original
#original.save("foundBlobs_yellow.jpg")
bestBlob = blobs[-1]
centroidX = bestBlob.minRectX()
centroidY = bestBlob.minRectY()
#Have to find out which part of the screen centroid is in
maxX = original.getNumpy().shape[0]
maxY = original.getNumpy().shape[1]+100
#assume width of 150 pixels
return align_center(maxX,maxY,centroidX,centroidY,50,50)
示例8: dibujar_Textos
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
if paso1 == True:
for marca in marcas:
SCREEN.blit(marca[0], marca[1]) # imagen, rect
if paso1 == False and paso2 == False:
dibujar_Textos('GRACIAS,', font40, COLOR_AZUL_CIELO, SCREEN, 10, 100,'center')
dibujar_Textos('CALIBRACION DE TAPETE FINALIZADA', font40, COLOR_AZUL_CIELO, SCREEN, 10, 150,'center')
if paso2 == True:
img = camara.getImage()
nivel_R = control_RED.valorLevel
nivel_G = control_GREEN.valorLevel
nivel_B = control_BLUE.valorLevel
UMBRAL_BINARIZADO = control_BINARIZE.valorLevel
img = img.colorDistance((nivel_R, nivel_G, nivel_B))
img = img.binarize(UMBRAL_BINARIZADO)
img.save('temp/vistaTapete.png')
imagen_calibracion = pygame.image.load('temp/vistaTapete.png')
SCREEN.blit(imagen_calibracion, (0,0))
# dibujar los contoles deslizables
for control_deslizable in listaControles:
control_deslizable.draw(SCREEN)
# Dibujar Etiquetas(y otros textos)
dibujar_Textos('(R) %0d' %(nivel_R), font20, COLOR_BLANCO_SUCIO, SCREEN, 10, 15, 0)
dibujar_Textos('(G) %0d' %(nivel_G), font20, COLOR_BLANCO_SUCIO, SCREEN, 10, 65, 0)
dibujar_Textos('(B) %0d' %(nivel_B), font20, COLOR_BLANCO_SUCIO, SCREEN, 10, 115, 0)
dibujar_Textos('BINARIZADO %0d' %(UMBRAL_BINARIZADO), font20, COLOR_BLANCO_SUCIO, SCREEN, 10, 160, 0)
示例9: Image
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
import SimpleCV
from SimpleCV import Image
display = SimpleCV.Display()
img = Image("ping/source/image3.jpeg")
# parametre pour image1 : (dilate=2), (stretch(200,255), isCircle(0.2)
# parametre pour image2 : non trouvé
# parametre pour image3 : (dilate=2), (stretch(2,120), isCircle(0.2)
# parametre pour image4 : (dilate=2), (stretch(2,120), isCircle(0.2)
# parametre pour image5 : (dilate=2), (stretch(2,120), isCircle(0.2)
# parametre pour image6 : plante
# parametre pour image7 : non trouvé
dist = img.colorDistance(SimpleCV.Color.ORANGE).dilate(2)
segmented = dist.stretch(2,120).invert()
blobs = segmented.findBlobs()
if blobs:
balles = blobs.filter([b.isCircle(0.2) for b in blobs])
if balles:
for balle in balles:
img.drawCircle((balle.x,balle.y),balle.radius(),SimpleCV.Color.BLUE,3 )
img.show()
示例10: Image
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
from SimpleCV import Image, Color
bluePincels = Image("ex19.jpg") # Open mm.png too :)
# Get a random value for color in a pixel 100,100 of the image
pixel = bluePincels.getPixel(100,100)
print pixel
# Distantiate the color of pixel picked previously
colorDist = bluePincels.colorDistance(pixel)
# Binarize the image and invert the colors to show most of the blue parts of the image
colorDistBin = colorDist.binarize(50).invert()
colorDistBin.show()
示例11: process
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def process(filename):
# Preprocessing
input_img = Image('./images/' + filename)
img = input_img.colorDistance(Color.BLACK).stretch(PARAM_STRETCH_THRESH_LOW, PARAM_STRETCH_THRESH_HIGH).scale(2)
img.save('./processed/' + filename)
# OCR
ocr_bin = shlex.split('./ocr ./processed/' + filename)
process = subprocess.Popen(ocr_bin, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
# Parse output
with open('eng.user-words', 'r') as f:
choices = f.read().strip().split('\n')
lines = out.split('\n')
results = []
confidences = []
ratios = []
flags = []
ignore_count = 0
for ln in lines:
# don't process empty lines
if(len(ln) == 0):
continue
# ignore 1st x lines of heading eg. FAIRPRICE XTRA
if(ignore_count<HEADING_LINES_COUNT):
ignore_count+=1
continue
# line in format "confidence || line"
ocr_line = ln.split('||')
conf, item_and_price = ocr_line[0], ocr_line[1].split(' ')
# assume price is last word in line
item, price = ' '.join(item_and_price[:-1]).strip(), item_and_price[-1].strip()
# Use fuzzy string matching to correct result
predicted, ratio = FProcess.extractOne(item, choices)
if ratio >= FLAG_CRITERIA_FUZZY and float(conf) >= FLAG_CRITERIA_OCR:
output_line = predicted
flag = ''
else:
output_line = item
flag = 'Flag'
results.append(output_line + ' ' + price)
confidences.append(conf)
ratios.append(str(ratio))
flags.append(flag)
# Write results with flags for manual checking
zipped = zip(results, confidences, ratios, flags)
mapped = map(lambda tup: ' || '.join(tup), zipped)
outfile = './results/' + filename + '.txt'
with open(outfile, 'w') as f:
f.write('\n'.join(mapped))
return zipped
示例12:
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
# encoding: utf-8
__author__ = 'yonka'
import SimpleCV
from SimpleCV import Image
Image.colorDistance()
示例13: Image
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
#import the modules
import time
import SimpleCV
from SimpleCV import Image
from SimpleCV import Color
hay_alguien = Image("me.jpg")
win = hay_alguien.show()
time.sleep(3)
win.quit()
extraccion_color = hay_alguien.colorDistance(Color.BLACK)
win = extraccion_color.show()
time.sleep(3)
win.quit()
me = hay_alguien - extraccion_color
win = me.show()
time.sleep(3)
win.quit()
print('resultados primera comparacion:')
R = me.meanColor()[2]
print('R: ' + str(R))
G = me.meanColor()[1]
print('G: ' + str(G))
B = me.meanColor()[0]
print('B: ' + str(B))
cam = SimpleCV.Camera()
示例14: Image
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
from SimpleCV import Image, Color
import time
yellowTool = Image('yellowtool.png')
yellowDist = yellowTool.colorDistance((223, 191, 29))
yellowDist.show()
time.sleep(3)
yellowDistBin = yellowDist.binarize(50).invert()
yellowDistBin.show()
time.sleep(3)
onlyYellow = yellowTool - yellowDistBin
onlyYellow.show()
time.sleep(3)
示例15: detectGreenLowQuality
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import colorDistance [as 别名]
def detectGreenLowQuality(image_file):
original = Image(image_file)
#binarizedYellowMask = findYellowMask(image_file)
#subtractedMask = original - binarizedYellowMask
#subtractedMask.save("subtractedMask.jpg")
#green_only = subtractedMask.colorDistance((94,116,33))
#green_only = subtractedMask.colorDistance((50,116,45))
green_only = original.colorDistance((0,70,6))
green_only = green_only*6
mask = green_only.invert()
#mask.save("green_mask.jpg")
binarizedMask = mask.binarize().invert()
#binarizedMask.save("binarized_mask_green.jpg")
blobs = original.findBlobsFromMask(binarizedMask)
if blobs == None:
#print "No green found"
return detectYellowLowQuality(image_file)
blobs.image = original
#Assume best blob is the largest blob
bestBlob = blobs[-1]
bestBlob.drawMinRect(color=Color.RED,width =10)
#original.save("foundBlobs_green.jpg")
'''
#blobs[-1].drawRect(color=Color.RED,width =10)
coordinates = bestBlob.minRect()
#Find the center point
centroidX = bestBlob.minRectX()
centroidY = bestBlob.minRectY()
minLeftY = 0
minRightY = 0
#Find the bottom left and bottom right coordinates
for coordinate in coordinates:
if coordinate[0] < centroidX and coordinate[1] > minLeftY:
bottomLeft = coordinate
minLeftY = coordinate[1]
elif coordinate[0] > centroidX and coordinate[1] > minRightY:
bottomRight = coordinate
minRightY = coordinate[1]
'''
centroidX = bestBlob.minRectX()
centroidY = bestBlob.minRectY()
#Have to find out which part of the screen centroid is in
maxX = original.getNumpy().shape[0]
maxY = original.getNumpy().shape[1]+100
#assume width of 150 pixels
return align_center(maxX,maxY,centroidX,centroidY,50,50)