Python Forum
homework - how make contrast stretching?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
homework - how make contrast stretching?
#1
Photo 
Hy guys.
I have a homework :

Write a program that gets a filename for its input, then looks for these human faces and prints each one in a separate file 1-1. If e.g. the name of the input file is family.jpg, then the output names should be family-face-01.png, family-face-02.png, ... Make sure that the output portraits contain the full face. (Some hair may be left behind.) Apply a tolerance contrast stretch to the output images one at a time, allowing 1-1% of the pixels to overflow or overflow. You can use e.g. OpenCV's built-in Haar-cascade-based face recognition.

I did face recognition, but i don't how to make the othet parts.

Please help me...

import cv2


face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
img = cv2.imread('csalad1.jpg')


gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(50, 50)
)

print("[INFO] Talált {0} arcot.".format(len(faces)))



i_cont=0
for (x, y, w, h) in faces:
    cv2.rectangle(img, (x, y), (x+w, y+h), (255, 72, 0), 2)
    cont_arc = img[y:y + h, x:x + w]
    
    print("[INFO] Arcok megtalálva. Mentés helyileg.")
    cv2.imwrite('csalad_arc%03d.jpg'%i_cont, cont_arc)


  
    i_cont+=1
    
status = cv2.imwrite('arcok_megtalalva.jpg', img)
print("[INFO] Kep arcok_megtalalva.jpg kiirva mappába: ", status)


cv2.imshow('img', img)
cv2.waitKey()

[python]
[/python]
[python]
[/python]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I attempted to make a rock paper scissors bot for homework Intellectual11 3 2,926 Jun-24-2021, 08:00 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020