当前位置: 首页>>代码示例>>Python>>正文


Python Rectangle.getArea方法代码示例

本文整理汇总了Python中rectangle.Rectangle.getArea方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.getArea方法的具体用法?Python Rectangle.getArea怎么用?Python Rectangle.getArea使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rectangle.Rectangle的用法示例。


在下文中一共展示了Rectangle.getArea方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import getArea [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: update

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import getArea [as 别名]
def update(prefSideLeft, isDebug):
	logging.debug("update() {} {}".format(isDebug, imgNameIndex))

	# 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, countours 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 foundHotTarget
	global foundHotTarget
	foundHotTarget = 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:

			# 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 = inPrefSide(target.x + (target.width / 2), prefSideLeft)

				if isDebug:
					drawRect(img, target)
					viewAngle = computeAngle(horizTarget.height, target.height, distanceFromTarget)
					logging.debug("Hot Target: " + str(foundHotTarget) + ", New Angle: " + str(viewAngle))

	# Save img so we can analyze it
	if isDebug:
		saveImg(img)
开发者ID:FRC-Team-955,项目名称:AerialAssist,代码行数:46,代码来源:vision.py

示例3: main

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import getArea [as 别名]
def main(x0, y0, x1, y1):
    rect = Rectangle(int(x0), int(y0), int(x1), int(y1))
    msg = 'For the rectangle with corners located at ('
    msg += str(x0) + ', ' + str(y0) + ') and ('
    msg += str(x1) + ', ' + str(y1) + '):\n'
    print(msg)
    msg = 'The length is ' + str(rect.getLength())
    msg += ' and the height is ' + str(rect.getHeight()) + '.'
    print(msg)
    msg = 'The area is ' + str(rect.getArea()) + '.'
    print(msg)
开发者ID:cpatrick,项目名称:cython-cmake-example,代码行数:13,代码来源:rectangle_props.py

示例4: RectangleTest

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import getArea [as 别名]
class RectangleTest(TestCase):

    def setUp(self):
        self.rectangle = Rectangle(1, 2, 3, 4)

    def test_getLength(self):
        assert_equal(self.rectangle.getLength(), 2)

    def test_getHeight(self):
        assert_equal(self.rectangle.getHeight(), 2)

    def test_getArea(self):
        assert_equal(self.rectangle.getArea(), 4)

    def test_move(self):
        self.rectangle.move(4, 8)
        self.test_getLength()
        self.test_getHeight()
        self.test_getArea()
开发者ID:cpatrick,项目名称:cython-cmake-example,代码行数:21,代码来源:rectangle_test.py

示例5: Rectangle

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import getArea [as 别名]
from rectangle import Rectangle
r = Rectangle(1, 2, 3, 4)
print r
print "Original area:", r.getArea()
r.move(1,2)
print r
print "Area is invariante under rigid motions:", r.getArea()
r += Rectangle(0,0,1,1)
print r
print "Now the aread is:", r.getArea()
r.setsize(3)
print r.getsize()
开发者ID:imsejae,项目名称:pyclaw,代码行数:14,代码来源:ustri.py

示例6: update

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import getArea [as 别名]
def update(table, viewAngleHorz, deltaTime) :
    theta, dist = 0.0, 0.0
    #print "update()"

#    while True :
    ret, img = camera.read() # img.shape 640x480 image
    #print "ret: " + str(ret) + "\n"
    #ret = True
    #img = cv2.imread("c:\Untitled.tiff")
    #if not ret : print "oops!\n"
    #elif
    #    cv2.imshow('input',img)

    # Convert to hsv img
    #hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    h, s, v = rgb_to_hsl_hsv(img, True)
    #cv2.imshow("v", v)
    thresh = 255
    im_bw = cv2.threshold(v, 240, 255, cv2.THRESH_BINARY)[1]
    #cv2.imshow("im_bw",im_bw)

    #
    if False :
        rg = better_way(img)
        cv2.imshow('huh', rg)
    #rg1 = cv2.cvtColor(rg, cv2.COLOR_BGR2HSV)
    #hsv = cv2.cvtColor(rg, cv2.COLOR_BGR2HSV)

    #  Keep only green objects
    # higher s = less white, higher v = less black
    #invent sliders to adjust
    #lowerGreen = np.array([70, 70, 180])
    #upperGreen = np.array([110, 130,255])
    if False :
        lg_h, lg_s, lg_v = 0, 0, 254
        ug_h, ug_s, ug_v = 255, 255, 255
        #lg_h, lg_s, lg_v = 100, 6, 67
        #ug_h, ug_s, ug_v = 158, 98, 87
        lowerGreen = np.array([lg_h, lg_s, lg_v])
        upperGreen = np.array([ug_h, ug_s, ug_v])
        filteredGreen = cv2.inRange(hsv, lowerGreen, upperGreen)
        #cv2.imshow('fgreen',filteredGreen)

    if False :
        filteredGreen = rg
        #cv2.cvtColor(rg, cv2.COLOR_RGB2GRAY, filteredGreen, 1)
        #cv2.cvtColor(filteredGreen, cv2.COLOR_GRAY2RGBA, filteredGreen, 1)
        #rg.convertTo(filteredGreen, CV_8UC1)
        #try as hard as heck to convert to happy format for findContours...
        min_t = np.array((199, 199, 199))
        max_t = np.array((201, 201, 201))
        filteredGreen = cv2.inRange(rg, min_t, max_t)
    filteredGreen = im_bw
    #cv2.imshow('bigfilter',filteredGreen)

    # Filter out small objects
    filteredGreen = cv2.morphologyEx(filteredGreen, cv2.MORPH_OPEN, np.ones((3, 3)))
    #cv2.imshow('fgreens',filteredGreen)

    # 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
    foundVertTarget = False

    # work around subtle bug - see StackOverflow
    # http://stackoverflow.com/questions/13337058/data-type-error-with-drawcontours-unless-i-pickle-unpickle-first
    tmp = cPickle.dumps(contours)
    contours = cPickle.loads(tmp)

    possibleHotTarget = Rectangle(0,0,0,0)
    possibleHotArea = possibleHotTarget.getArea()

    possibleVertTarget1 = Rectangle(0,0,0,0)
    possibleVertTarget2 = Rectangle(0,0,0,0)

    # Parse contours, calculate distance and check if it's the hot target
    for shape in contours:
        #target = Rectangle(*cv2.boundingRect(shape))
        x,y,w,h = cv2.boundingRect(shape)
        target = Rectangle(x,y,w,h)

        # Filter out small contours
        if target.getArea() > 300 and target.getArea() < 30000:

            # Compensate for horizontal view of the target
            #target.width = target.width / math.cos(viewAngle * math.PI / 180)
            #target.width = target.width / math.cos(viewAngle * 3.14159 / 180)

            # MPH improvements: - width / height (23.5/4) +-15% then possibly the hot target
            #  If the width of the target is greater than its height then it's probably the hot target
            hotTargetRatio = 23.5 / 4
            hotTargetMargin = 0.25 # percent error margin
            if (target.width>target.height) and  (target.height * (hotTargetRatio)*(1+hotTargetMargin)) >= target.width >= (target.height * ((hotTargetRatio)*(1-hotTargetMargin))):
                foundHotTarget = True
                if target.getArea() > possibleHotArea :
                    possibleHotTarget = target
                    possibleHotArea = target.getArea()
                #distance = computeDistance(horizTarget.height, target.height)
#.........这里部分代码省略.........
开发者ID:SWATRobotics,项目名称:2014_FRC_3045_Auton_2,代码行数:103,代码来源:vision.py


注:本文中的rectangle.Rectangle.getArea方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。