本文整理汇总了Python中SimpleCV.Display.pointsToBoundingBox方法的典型用法代码示例。如果您正苦于以下问题:Python Display.pointsToBoundingBox方法的具体用法?Python Display.pointsToBoundingBox怎么用?Python Display.pointsToBoundingBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.Display
的用法示例。
在下文中一共展示了Display.pointsToBoundingBox方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: track
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import pointsToBoundingBox [as 别名]
#.........这里部分代码省略.........
[sp.sin(mobile.roll), sp.cos(mobile.roll)]]) # Coordinate transform matrix
if useBasemap:
# Warning this really slows down the computation
m = Basemap(width=img.width, height=img.height, projection='aeqd',
lat_0=sp.rad2deg(mobile.pitch), lon_0=sp.rad2deg(mobile.yaw), rsphere = radius)
# Get an image from camera
if not isPaused:
img = cam.getImage()
img = img.resize(int(scaleFactor*img.width), int(scaleFactor*img.height))
if display:
# Pause image when right button is pressed
dwn = disp.rightButtonDownPosition()
if dwn is not None:
isPaused = not(isPaused)
dwn = None
if display:
# Create a layer to enable user to make a selection of the target
selectionLayer = DrawingLayer((img.width, img.height))
if img:
if display:
# Create a new layer to host information retrieved from video
layer = DrawingLayer((img.width, img.height))
# Selection is a rectangle drawn while holding mouse left button down
if disp.leftButtonDown:
corner1 = (disp.mouseX, disp.mouseY)
selectionInProgress = True
if selectionInProgress:
corner2 = (disp.mouseX, disp.mouseY)
bb = disp.pointsToBoundingBox(corner1, corner2)# Display the temporary selection
if disp.leftButtonUp: # User has finished is selection
selectionInProgress = False
selection = img.crop(bb[0], bb[1], bb[2], bb[3])
if selection != None:
# The 3 main colors in the area selected are considered.
# Note that the selection should be included in the target and not contain background
try:
selection.save('../ObjectTracking/'+ 'kite_detail_tmp.jpg')
img0 = Image("kite_detail_tmp.jpg") # For unknown reason I have to reload the image...
pal = img0.getPalette(bins = 2, hue = False)
except: # getPalette is sometimes bugging and raising LinalgError because matrix not positive definite
pal = pal
wasTargetFoundInPreviousFrame = False
previous_coord_px = (bb[0] + bb[2]/2, bb[1] + bb[3]/2)
if corner1 != corner2:
selectionLayer.rectangle((bb[0], bb[1]), (bb[2], bb[3]), width = 5, color = Color.YELLOW)
# If the target was already found, we can save computation time by
# reducing the Region Of Interest around predicted position
if wasTargetFoundInPreviousFrame:
ROITopLeftCorner = (max(0, previous_coord_px[0]-maxRelativeMotionPerFrame/2*width), \
max(0, previous_coord_px[1] -height*maxRelativeMotionPerFrame/2))
ROI = img.crop(ROITopLeftCorner[0], ROITopLeftCorner[1], \
maxRelativeMotionPerFrame*width, maxRelativeMotionPerFrame*height, \
centered = False)
if display :
# Draw the rectangle corresponding to the ROI on the complete image
layer.rectangle((previous_coord_px[0]-maxRelativeMotionPerFrame/2*width, \
previous_coord_px[1]-maxRelativeMotionPerFrame/2*height), \
(maxRelativeMotionPerFrame*width, maxRelativeMotionPerFrame*height), \
color = Color.GREEN, width = 2)
示例2: get_bounding_box
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import pointsToBoundingBox [as 别名]
def get_bounding_box(keyword, url, filename):
# get the image
img = Image(url)
# resize the image so things aren't so slow, if necessary
w, h = img.size()
if w > 1200 or h > 1200:
maxdim = max(w, h)
ratio = math.ceil(maxdim/800.0)
print " resizing..."
img = img.resize(w=int(w/ratio), h=int(h/ratio))
else:
ratio = 1
# get the canvas
disp = Display((800, 800))
# text overlay
textlayer = DrawingLayer(img.size())
textlayer.setFontSize(30)
cx, cy = 10, 10
for xoff in range(-2, 3):
for yoff in range(-2, 3):
textlayer.text(keyword, (cx + xoff, cy + yoff), color=Color.BLACK)
textlayer.text(keyword, (cx, cy), color=Color.WHITE)
# two points to declare a bounding box
point1 = None
point2 = None
while disp.isNotDone():
cursor = (disp.mouseX, disp.mouseY)
if disp.leftButtonUp:
if point1 and point2:
point1 = None
point2 = None
if point1:
point2 = disp.leftButtonUpPosition()
else:
point1 = disp.leftButtonUpPosition()
bb = None
if point1 and point2:
bb = disp.pointsToBoundingBox(point1, point2)
elif point1 and not point2:
bb = disp.pointsToBoundingBox(point1, cursor)
img.clearLayers()
drawlayer = DrawingLayer(img.size())
if bb:
drawlayer.rectangle((bb[0], bb[1]), (bb[2], bb[3]), color=Color.RED)
# keyboard commands
if pygame.key.get_pressed()[pygame.K_s]:
# skip for now
raise Skip()
elif pygame.key.get_pressed()[pygame.K_b]:
# mark it as an invalid picture
raise BadImage()
elif pygame.key.get_pressed()[pygame.K_RETURN]:
if point1 and point2:
bb = disp.pointsToBoundingBox(scale(ratio, point1), scale(ratio, point2))
return bb
elif not point1 and not point2:
bb = disp.pointsToBoundingBox((0, 0), (w, h))
return bb
drawlayer.line((cursor[0], 0), (cursor[0], img.height), color=Color.BLUE)
drawlayer.line((0, cursor[1]), (img.width, cursor[1]), color=Color.BLUE)
#drawlayer.circle(cursor, 2, color=Color.BLUE, filled=True)
img.addDrawingLayer(textlayer)
img.addDrawingLayer(drawlayer)
img.save(disp)
示例3: Display
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import pointsToBoundingBox [as 别名]
from SimpleCV import Display, Camera, Image, DrawingLayer, VirtualCamera
disp = Display((600,800))
#cam = Camera()
cam = VirtualCamera('/media/bat/DATA/Baptiste/Nautilab/kite_project/zenith-wind-power-read-only/KiteControl-Qt/videos/kiteTest.avi','video')
isPaused = False
updateSelection = False
while(disp.isNotDone()):
if not isPaused:
img_flip = cam.getImage().flipHorizontal()
img = img_flip.edges(150, 100).dilate()
if disp.rightButtonDown:
isPaused = not(isPaused)
selectionLayer = DrawingLayer((img.width, img.height))
if disp.leftButtonDown:
corner1 = (disp.mouseX, disp.mouseY)
updateSelection = True
if updateSelection:
corner2 = (disp.mouseX, disp.mouseY)
bb = disp.pointsToBoundingBox(corner1, corner2)
if disp.leftButtonUp:
updateSelection = False
if corner1!=corner2:
selectionLayer.rectangle((bb[0],bb[1]),(bb[2],bb[3]))
img.addDrawingLayer(selectionLayer)
img.save(disp)
img.removeDrawingLayer(0)