本文整理汇总了Python中SimpleCV.Image.findBlobsFromMask方法的典型用法代码示例。如果您正苦于以下问题:Python Image.findBlobsFromMask方法的具体用法?Python Image.findBlobsFromMask怎么用?Python Image.findBlobsFromMask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.Image
的用法示例。
在下文中一共展示了Image.findBlobsFromMask方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detectYellowLowQuality
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import findBlobsFromMask [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)
示例2: detectCenter
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import findBlobsFromMask [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)
示例3: detectChargingStation
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import findBlobsFromMask [as 别名]
def detectChargingStation(image_file):
debug = False
myColor1 = (8,33,64)
myColor2 = (70,80,100)
original = Image(image_file)
only_station = onlyBlueColor(original, myColor1)
#Different findBlobs
maskMean = original.hueDistance(color=(200,160,150))
mask = only_station.hueDistance(color=myColor1).binarize()
meanColor = (round(((maskMean.meanColor()[0]+maskMean.meanColor()[1]+maskMean.meanColor()[2])/3) * 10000)/10000)
blobs = original.findBlobsFromMask(mask, minsize=400)
if(meanColor > 190):
return 6
#print "Number of blobs found" , len(blobs)
try:
blobs.image = original
except Exception:
only_station = onlyBlueColor(original, myColor2)
mask = only_station.hueDistance(color=myColor2).binarize()
blobs = original.findBlobsFromMask(mask, minsize=400)
blobs.image = original
station_blob = chooseBestBlobCosine(blobs)
station_blob.drawMinRect(color=Color.RED)
centroidX = station_blob.minRectX()
centroidY = station_blob.minRectY()
#Have to find out which part of the screen centroid is in
maxX = original.getNumpy().shape[0]
maxY = original.getNumpy().shape[1]+100
if(debug):
centroidLayer = DrawingLayer((maxX,maxY))
centroidLayer.line((0,(1/3.0)*maxY),(maxX, (1/3.0)*maxY), color=Color.GREEN, width=2)
centroidLayer.line((0,(2/3.0)*maxY),(maxX, (2/3.0)*maxY), color=Color.GREEN, width=2)
centroidLayer.circle((int(centroidX), int(centroidY)), color=Color.GREEN, radius=5, filled=True)
original.addDrawingLayer(centroidLayer)
original.applyLayers()
mask.save("binarizeMask.png")
original.save("blobs.png")
only_station.save("blueFilter.png")
#print "Coordinates of centroid are "+str(centroidX)+", "+str(centroidY)
#print "Coordinates of max are "+str(maxX)+", "+str(maxY)
#if(station_blob.width() * station_blob.height() < 4000):
# return 2
blobArea = station_blob.width() * station_blob.height()
if(blobArea < 10000):
return 2
return chargingStationLocation_New(maxX,maxY,centroidX,centroidY,200, station_blob.width() / float(station_blob.height()), blobArea)
示例4: detectGreenLowQuality
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import findBlobsFromMask [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)