コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
    def run(self):

        firstline = True
        for line in self.infile:
            if firstline:
                firstline = False
                continue


##         fields = line.split(',')
##         width = int(fields[0].strip())
##         height= int(fields[1].strip())
##         self.counter.add( Rectangle(width,height))

            line = line.strip()
            fields = line.split(
                ","
            )  #mapping each of the colums in the excel spreadsheet to their field name this makes it easier for me to type their column name instead of their position again
            stat = str(fields[0])
            value = float(fields[1])
            width = int(fields[2])
            code = fields[3]
            quant = int(fields[4])
            switch = str(fields[5])
            # then I pass a complete Rectangle to the counter object
            self.counter.add(Rectangle(stat, value, width, code, quant,
                                       switch))

        self.infile.close()
        self.gui.notify()
コード例 #4
0
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()
コード例 #5
0
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()
コード例 #6
0
ファイル: Final GUI.py プロジェクト: baec/Python_GUI_V2
    def run(self):
        #for all the lines in the file first line is set to true
        firstline = True
        for line in self.infile:
            if firstline:
                firstline = False
                continue

            line = line.strip(
            )  # line.strip() removes the end of the line character that is stuck in the end of each line as it is read
            fields = line.split(
                ","
            )  #mapping each of the columns in the excel spreadsheet to their field name this makes it easier for me to type their column name instead of their position again
            stat = str(
                fields[0]
            )  #The stat column is mapped out to be the first column and identified as a string
            value = float(
                fields[1]
            )  #The fields column is mapped out as the second column and identified as a float
            width = int(
                fields[2]
            )  #The width column is mapped out as the third column and identidfied as a number
            code = fields[
                3]  #The code column is mapped out as the fourth column
            quant = int(
                fields[4]
            )  # The quant column is mapped out as the fifth column and identified as a string
            switch = str(
                fields[5]
            )  #The switch column is mapped out as the fifth column and identified as a string
            # then I pass a complete Rectangle to the counter object
            self.counter.add(Rectangle(stat, value, width, code, quant,
                                       switch))

            #The file in the GUI needs to be closed after
        self.infile.close()
        self.gui.notify()
コード例 #7
0
ファイル: predict.py プロジェクト: PBL-2016/apis
def analysis(path):
    # Check the file is exist
    if path is None:
        return (None, P_NOTFOUND)

    img = cv2.imread(path, cv2.IMREAD_COLOR)
    img = resize(img, 300)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Face and body detection
    faces = face_cascade.detectMultiScale(gray, 1.1, 3)
    bodies = body_cascade.detectMultiScale(gray, 1.1, 3)
    if len(faces) <= 0 or len(bodies) <= 0:
        return ({
            "face_detect": len(faces),
            "body_detect": len(bodies)
        }, P_UNDETECTED)

    face = Rectangle(faces[0][0], faces[0][1], faces[0][2], faces[0][3])
    body = Rectangle(bodies[0][0], bodies[0][1], bodies[0][2], bodies[0][3])

    # Skin Section
    skinR = skinG = skinB = 0

    for col in range(face.half_w):
        for row in range(10):
            pixel = img[face.y + face.half_h - row + 5,
                        face.x + face.quarter_w + col]
            skinB += pixel[0]
            skinG += pixel[1]
            skinR += pixel[2]

    averageDivisor = face.half_w * 10
    skinR = int(skinR / averageDivisor)
    skinG = int(skinG / averageDivisor)
    skinB = int(skinB / averageDivisor)

    # Hair Section
    hairR = hairG = hairB = 0

    top = face.y - 5
    if top < 0:
        top = 0

    for col in range(face.half_w):
        for row in range(10):
            pixel = img[top + row, face.x + face.quarter_w + col]
            hairB += pixel[0]
            hairG += pixel[1]
            hairR += pixel[2]

    hairR = int(hairR / averageDivisor)
    hairG = int(hairG / averageDivisor)
    hairB = int(hairB / averageDivisor)

    # Ratio Section
    body_ratio = body.w / face.w

    # Contour Section
    if C.check_loaded():
        contour = recognize_contour(img[face.y:face.y2, face.x:face.x2])
        if contour == "b'circle'":
            contour = 0
        elif contour == "b'square'":
            contour = 1
        elif contour == "b'triangle'":
            contour = 2
    else:
        contour = 1
#    print('Contour:\t', contour)

# Prediction
# Default contour type is 1(square)
# 0(triangle) and 2(circle)

    cluster = predict(skinR, skinG, skinB, hairR, hairG, hairB, body_ratio,
                      contour)

    return ({
        "cluster": cluster,
        "skinR": skinR,
        "skinG": skinG,
        "skinB": skinB,
        "hairR": hairR,
        "hairG": hairG,
        "hairB": hairB,
        "ratio": body_ratio,
        "contour": contour
    }, P_SUCCESS)
コード例 #8
0
 def draw(self):
     Rectangle(self.x, self.y, self.w, self.h, mode='center')
コード例 #9
0
ファイル: extract.py プロジェクト: PBL-2016/apis
def extract(path):
    img = cv2.imread(path, cv2.IMREAD_COLOR)
    img = resize(img, 300)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    faces = face_cascade.detectMultiScale(gray, 1.1, 3)
    if len(faces) <= 0:
        return None

    bodies = body_cascade.detectMultiScale(gray, 1.1, 3)
    if len(bodies) <= 0:
        return None

    face = Rectangle(faces[0][0], faces[0][1], faces[0][2], faces[0][3])
    body = Rectangle(bodies[0][0], bodies[0][1], bodies[0][2], bodies[0][3])

    # Body/Face Section
    body_ratio = body.w / face.w
    if body_ratio <= BODY_RATIO_THRESHOLD:
        return None

    # Skin Section
    skinR = skinG = skinB = 0

    for col in range(face.half_w):
        for row in range(10):
            pixel = img[face.y + face.half_h - row + 5,
                        face.x + face.quarter_w + col]
            skinB += pixel[0]
            skinG += pixel[1]
            skinR += pixel[2]

    averageDivisor = face.half_w * 10
    skinR = int(skinR / averageDivisor)
    skinG = int(skinG / averageDivisor)
    skinB = int(skinB / averageDivisor)

    # Hair Section
    hairR = hairG = hairB = 0

    top = face.y - 5
    if top < 0:
        top = 0

    for col in range(face.half_w):
        for row in range(10):
            pixel = img[top + row, face.x + face.quarter_w + col]
            hairB += pixel[0]
            hairG += pixel[1]
            hairR += pixel[2]

    hairR = int(hairR / averageDivisor)
    hairG = int(hairG / averageDivisor)
    hairB = int(hairB / averageDivisor)

    # Contour Section
    contour = recognize_contour(img[face.y:face.y2, face.x:face.x2])

    print("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}".format(os.path.basename(path),
                                                      skinR, skinG, skinB,
                                                      hairR, hairG, hairB,
                                                      body_ratio, contour))
コード例 #10
0
ファイル: main.py プロジェクト: AeroKnight21/PythonStudy
from rect import Rectangle
from triangle import Triangle

rect = Rectangle()
tri = Triangle()
rect.set_values(50, 40)
tri.set_values(50, 40)

rect.set_color('red')
tri.set_color('blue')

print(rect.area())
print(tri.area())
print(rect.get_color())
print(tri.get_color())
コード例 #11
0
 def setUp(self):
     self.rectangle = Rectangle(1, 2, 3, 4)
コード例 #12
0
ファイル: rect_fig.py プロジェクト: qwer121zaq1/public
from rect import Rectangle, Square, Circle

rect_1 = Rectangle(3, 4)
rect_2 = Rectangle(12, 5)

print(rect_1.get_area())
print(rect_2.get_area())
print('_-_-_-_-_-_-_-_-_-_-_-_-_-_')

square_1 = Square(5)
square_2 = Square(10)
print(square_1.get_area_square())
print(square_2.get_area_square())
print('_-_-_-_-_-_-_-_-_-_-_-_-_-_')

cir_1 = Circle(7)
cir_2 = Circle(13)
print(cir_1.get_area_circle())
print(cir_2.get_area_circle())
print('_-_-_-_-_-_-_-_-_-_-_-_-_-_')

figures = [rect_1, rect_2, square_1, square_2, cir_1, cir_2]

for figure in figures:
    if isinstance(figure, Rectangle):
        print(figure.get_area())
    elif isinstance(figure, Square):
        print(figure.get_area_square())
    else:
        print(figure.get_area_circle())
コード例 #13
0
 def setUp(self):
     self.rectangle = Rectangle(1, 2, 3, 4)