當前位置: 首頁>>代碼示例>>Python>>正文


Python Rectangle.width方法代碼示例

本文整理匯總了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)
開發者ID:FRC-Team-955,項目名稱:2014-Vision-Python,代碼行數:62,代碼來源:vision.py

示例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
開發者ID:PriceHardman,項目名稱:think_python,代碼行數:14,代碼來源:15-3_move_copy.py

示例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()
開發者ID:debsir,項目名稱:Learning,代碼行數:26,代碼來源:draw_rectangle.py

示例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))
開發者ID:PriceHardman,項目名稱:think_python,代碼行數:31,代碼來源:15-2_move_rectangle.py


注:本文中的rectangle.Rectangle.width方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。