I'm working on an app that draws a square on peoples faces (very basic but not the easiest). It only prints 1 square instead of 2+.
For example, this is the output:
output wished for (Photoshop obv):
code (snipped):
while x <= faces:
print(x)
image_height = int(response[x]["faceRectangle"]["height"]) * image_modifier_height
image_top = int(response[x]["faceRectangle"]["top"]) * image_modifier_height # - image_height/2
image_left = int(response[x]["faceRectangle"]["left"]) * image_modifier_width
image_width = int(response[x]["faceRectangle"]["width"]) * image_modifier_width
upper_line = (image_left, image_top)
bottom_line = (image_left, image_top + image_height)
right_line = (image_left + image_width, image_top)
# print("top: {}".format(image_top))
# print("left: {}".format(image_left))
# print("width: {}".format(image_width))
# print("height: {}".format(image_height))
# print("upper_line: {}".format(upper_line))
# print("bottom_line: {}".format(bottom_line))
# print("right_line: {}".format(right_line))
horizontal_line = pygame.image.load(r'C:\Users\Wit\PycharmProjects\LauEnv\Python learning\img\horizontalline.png')
horizontal_line = pygame.transform.scale(horizontal_line, (int(image_width), 5))
vertical_line = pygame.image.load(r'C:\Users\Wit\PycharmProjects\LauEnv\Python learning\img\verticalline.png')
vertical_line = pygame.transform.scale(vertical_line, (5, int(image_height)))
image_ = pygame.transform.scale(image_, (512, 512))
size = (512, 512)
screen = pygame.display.set_mode(size)
emotion = max(response[x]["faceAttributes"]["emotion"].items(), key=operator.itemgetter(1))[0]
emotion = pygame.font.Font('freesansbold.ttf', int(image_height / 10)).render(emotion, True, [0, 0, 0], [255, 255, 255])
age = str(int(response[x]["faceAttributes"]["age"]))
age = pygame.font.Font('freesansbold.ttf', int(image_height / 10)).render(age, True, [0, 0, 0], [255, 255, 255])
gender = response[x]["faceAttributes"]["gender"]
gender = pygame.font.Font('freesansbold.ttf', int(image_height / 10)).render(gender, True, [0, 0, 0], [255, 255, 255])
screen.blit(image_, (0, 0))
screen.blit(horizontal_line, upper_line)
screen.blit(horizontal_line, bottom_line)
screen.blit(vertical_line, upper_line)
screen.blit(vertical_line, right_line)
screen.blit(emotion, (upper_line[0], upper_line[1] - int(image_height / 8)))
screen.blit(age, (upper_line[0], upper_line[1] - int(image_height / 8) * 2))
screen.blit(gender, (upper_line[0], upper_line[1] - int(image_height / 8) * 3))
Face list/dic:
[{'faceRectangle': {'top': 157, 'left': 48, 'width': 349, 'height': 349}, 'faceAttributes': {'gender': 'female', 'age': 18.0,
'emotion': {'anger': 0.0, 'contempt': 0.0, 'disgust': 0.0, 'fear': 0.0,
'happiness': 0.0, 'neutral': 0.999, 'sadness': 0.0,
'surprise': 0.0}}},
{'faceRectangle': {'top': 144, 'left': 594, 'width': 341, 'height': 341}, 'faceAttributes': {'gender': 'male', 'age': 62.0,
'emotion': {'anger': 0.023, 'contempt': 0.054, 'disgust': 0.0, 'fear': 0.0,
'happiness': 0.0, 'neutral': 0.922, 'sadness': 0.001,
'surprise': 0.0}}}]
Fixed it. I put "screen.blit(image_, (0, 0))" in the loop which overwrites every square.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.