Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # for loop to iterate the x,y,width and height of the face
- for (x,y,w,h) in faces:
- #draw rectangle using x,y,width+x and height+y
- cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
- #The ROI is set using the relevant x,y width and height coodinates
- roi_gray = gray[y:y+h, x:x+w]
- # Same is done for the color region of interest
- roi_color = img[y:y+h, x:x+w]
- # global var:
- eye_counter = 0
- # eyes variable is set with module to detect eyes
- eyes = eye_cascade.detectMultiScale(roi_gray)
- # for loop to iterate through the x,y,width,height of the eyes
- for (ex, ey, ew, eh) in eyes:
- # ROI is determined from y value found between the other y value.
- # ey:ey + h means eye(Y value) between eye(Y value) plus the eye height.
- # The : is a slicing operator which means between in this context.
- roi_color_eye = roi_color[ey:ey + eh, ex:ex + ew]
- # write the ROI to image and counter is included so that the new JPG will be numbered acordingly.
- # E.g on first iteration, eye_0.jpg will be written, then eye_1.jpg second iteration.
- cv2.imwrite("eye_%d.jpg" % eye_counter, roi_color_eye)
- # increment the counter
- eye_counter += 1
- # draw rectangle around area of interest which is equal to the eye x,y,width,height coodinates.
- cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 50, 0), 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement