def findEntity(self, image, which, orig): # Work around OpenCV crash on some nearly black images nonZero = cv.CountNonZero(image.getGrayscaleMatrix()) if nonZero < 10: return Entity() size = self.Sizes[which] blobmaker = BlobMaker() blobs = blobmaker.extractFromBinary(image, image, minsize=size[0], maxsize=size[2]) if blobs is None: return Entity() entityblob = None mindiff = 9999 for blob in blobs: diff = self.sizeMatch(blob, which) if diff >= 0 and diff < mindiff: entityblob = blob mindiff = diff if entityblob is None: return Entity() notBall = which != 'ball' entity = Entity.fromFeature(entityblob, notBall, notBall, orig.getBitmap(), self.threshold._diff) return entity
def findEntity(self, image, which): # Work around OpenCV crash on some nearly black images nonZero = cv.CountNonZero(image.getGrayscaleMatrix()) if nonZero < 10: return Entity() size = self.Sizes[which] blobmaker = BlobMaker() blobs = blobmaker.extractFromBinary(image, image, minsize=size[0], maxsize=size[1]) if blobs is None: return Entity() entityblob = None for blob in blobs: if self.sizeMatch(blob, which): entityblob = blob break if entityblob is None: return Entity() isBall = which != 'ball' entity = Entity.fromFeature(entityblob, isBall, isBall) return entity
def findEntity(self, image, which): # Work around OpenCV crash on some nearly black images nonZero = cv.CountNonZero(image.getGrayscaleMatrix()) if nonZero < 10: return Entity() size = self.Sizes[which] blobmaker = BlobMaker() blobs = blobmaker.extractFromBinary(image, image, minsize=size[0], maxsize=size[1]) if blobs is None: return Entity() if len(blobs) == 0: return Entity() entityblob = None # sort the blobs by area ( to chose the largest blob that fits) blobs = sorted(blobs, key = lambda bl: bl.area() , reverse=True); #if (len(blobs)> 1): print which, blobs #for blob in blobs: # if self.sizeMatch(blob, which): # entityblob = blob # break #if entityblob is None: # return Entity() # size match is actually already done in blobmaker, just take the largest blob entityblob = blobs[0]; isBall = which != 'ball' entity = Entity.fromFeature(entityblob, isBall, isBall) return entity