本文整理汇总了Python中rectangle.Rectangle.width方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.width方法的具体用法?Python Rectangle.width怎么用?Python Rectangle.width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rectangle.Rectangle
的用法示例。
在下文中一共展示了Rectangle.width方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import width [as 别名]
def update(viewAngleHorz):
print "update()"
# Get color image from camera
ret, img = camera.read() # img.shape 640x480 image
# Convert to hsv img
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Keep only green objects
# higher s = less white, higher v = less black
lowerGreen = np.array([70, 70, 180])
upperGreen = np.array([110, 130,255])
filteredGreen = cv2.inRange(hsv, lowerGreen, upperGreen)
# Filter out small objects
filteredGreen = cv2.morphologyEx(filteredGreen, cv2.MORPH_OPEN, np.ones((3, 3)))
# Find all contours, counter is vector of points that are connected to make up a shape
contours, hierarchy = cv2.findContours(filteredGreen, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# Resetting values
foundHotTarget = False;
foundHorzTarget = False
# Parse contours, calculate distance and check if it's the hot target
for shape in contours:
target = Rectangle(*cv2.boundingRect(shape))
# Filter out small contours
if target.getArea() > 300 and target.getArea() < 10000:
# Compensate for horizontal view of the target
target.width = target.width / math.cos(viewAngle * math.PI / 180)
# If the width of the target is greater than its height then it's probably the hot target
if target.width >= target.height * 2.5:
foundHotTarget = True
distance = computeDistance(horizTarget.height, target.height)
if debugMode:
drawRect(img, target)
viewAngle = computeAngle(horizTarget.height, target.height, 228)
print "Distance: ", round(distance), ", Hot Target", viewAngle, viewAngleVert
# If the height of the target is greater than the its width its probably a vert target
if target.height >= target.width * 6:
foundHorzTarget = True
distance = computeDistance(vertTarget.height, target.height)
if debugMode:
drawRect(img, target)
viewAngle = computeAngle(vertTarget.height, target.height, 228)
print "Distance: ", round(distance), ", Vert Target", viewAngle, viewAngleVert
if debugMode:
cv2.imshow("color", img)
cv2.waitKey(10)
cv2.imshow("filtered", filteredGreen)
cv2.waitKey(10)
示例2: move_rectangle
# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import width [as 别名]
def move_rectangle(old_rec, dx, dy):
"""
Takes a rectangle and distances, and returns a new Rectangle object
moved by those coordinates.
"""
new_rec = Rectangle()
new_rec.height = old_rec.height
new_rec.width = old_rec.width
new_rec.corner = Point()
new_rec.corner.x = old_rec.corner.x + dx
new_rec.corner.y = old_rec.corner.y + dy
return new_rec
示例3: draw_rectangle
# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import width [as 别名]
#!/usr/bin/python
from swampy.World import World
from rectangle import Rectangle, Point
def draw_rectangle(Canvas, Rectangle):
bbox = [[Rectangle.corner.x, Rectangle.corner.y],
[Rectangle.corner.x + Rectangle.width,
Rectangle.corner.y + Rectangle.height]]
Canvas.rectangle(bbox, outline="black", width=2, fill="green4")
world = World()
canvas = world.ca(width=500, height=500, background="white")
box = Rectangle()
box.corner = Point()
box.corner.x = 50
box.corner.y = 50
box.width = 100
box.height = 100
draw_rectangle(canvas, box)
world.mainloop()
示例4: move_rectangle
# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import width [as 别名]
# Exercise 15-2.
# Write a function named move_rectangle that takes a Rectangle and two numbers
# named dx and dy. It should change the location of the rectangle by adding dx to the x
# coordinate of corner and adding dy to the y coordinate of corner.
from point import Point
from rectangle import Rectangle
def move_rectangle(rec, dx, dy):
"""Takes a rectangle object and moves it by dx and dy."""
rec.corner.x += dx
rec.corner.y += dy
return None
rec = Rectangle()
rec.corner = Point()
rec.corner.x = 1
rec.corner.y = 2
rec.width = 10
rec.height = 15
dx = 2
dy = 3
print("Before: (x,y) = (%d,%d)" % (rec.corner.x, rec.corner.y))
move_rectangle(rec, dx, dy)
print("After: (x,y) = (%d,%d), (dx,dy) = (%d,%d)" % (rec.corner.x, rec.corner.y, dx, dy))