本文整理汇总了Python中SimpleCV.Image.drawRectangle方法的典型用法代码示例。如果您正苦于以下问题:Python Image.drawRectangle方法的具体用法?Python Image.drawRectangle怎么用?Python Image.drawRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.Image
的用法示例。
在下文中一共展示了Image.drawRectangle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_shapes
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import drawRectangle [as 别名]
def find_shapes(img):
markupImage = Image(img)
bwImage = markupImage.binarize()
blobs = bwImage.findBlobs()
rectangles = []
for b in blobs:
info = b.boundingBox()
x = info[0]
y = info[1]
w = info[2]
h = info[3]
c = find_color(x, y, markupImage)
markupImage.drawRectangle(x, y, w, h)
rectangles.append(Rectangle(*((x, y, w, h) + c)))
max_rectangle = max(rectangles, key=lambda rect: rect.w * rect.h)
#markupImage.drawRectangle(max_rectangle.x, max_rectangle.y, max_rectangle.w, max_rectangle.h, Color.ORANGE)
return rectangles, markupImage
示例2: __call__
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import drawRectangle [as 别名]
def __call__(self, image):
params = util.utf8convert(self.inspection.parameters)
retVal = []
mask = Image((image.width,image.height))
if( params.has_key('w') and params.has_key('h') and params.has_key('x') and params.has_key('y') ): #rectangle
if( params['x'] + params['w'] < image.width and
params['y'] + params['h'] < image.height and
params['y'] >= 0 and
params['x'] >= 0 ):
mask.drawRectangle(params['x'],params['y'],params['w'],params['h'],width=-1,color=Color.WHITE)
mask = mask.applyLayers()
fs = image.findBlobsFromMask(mask)
ff = M.FrameFeature()
if( fs is not None and len(fs) > 0 ):
#fs[-1].draw()
b = fs[-1]
b.__class__ = BlobRegion
c = b.meanColor()
b.mColor = (int(c[0]),int(c[1]),int(c[2]))
ff.setFeature(b) # a little hacky but I am sure that it works
retVal = [ff]
elif( params.has_key('x') and params.has_key('y') and params.has_key('r') ): # circle
if( params['x'] + params['r'] < image.width and
params['y'] + params['r'] < image.height and
params['x'] - params['r'] >= 0 and
params['y'] - params['r'] >= 0 ):
r = params['r']
x = params['x']
y = params['y']
mask.drawCircle((x,y),r,thickness=-1,color=Color.WHITE)
mask = mask.applyLayers()
fs = image.findBlobsFromMask(mask)
ff = M.FrameFeature()
if( fs is not None and len(fs) > 0 ):
#fs[-1].draw()
b = fs[-1]
b.__class__ = BlobRegion
c = b.meanColor()
b.mColor = (int(c[0]),int(c[1]),int(c[2]))
ff.setFeature(b)
retVal = [ff]
elif( params.has_key('contour') ):
contour = params['contour'] # this may bail out
if( len(contour) >= 3 ):
mask.dl().polygon(contour,filled=True,color=Color.WHITE)
mask = mask.applyLayers()
fs = image.findBlobsFromMask(mask)
ff = M.FrameFeature()
if( fs is not None and len(fs) > 0 ):
#fs[-1].draw()
b = fs[-1]
b.__class__ = BlobRegion
c = b.meanColor()
b.mColor = (int(c[0]),int(c[1]),int(c[2]))
ff.setFeature(b)
retVal = [ff]
if( params.has_key("saveFile") ):
image.save(params["saveFile"])
return retVal
示例3: run
# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import drawRectangle [as 别名]
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" )