Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. # for loop to iterate the x,y,width and height of the face
  2. for (x,y,w,h) in faces:
  3. #draw rectangle using x,y,width+x and height+y
  4. cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
  5. #The ROI is set using the relevant x,y width and height coodinates
  6. roi_gray = gray[y:y+h, x:x+w]
  7. # Same is done for the color region of interest
  8. roi_color = img[y:y+h, x:x+w]
  9.  
  10. # global var:
  11. eye_counter = 0
  12. # eyes variable is set with module to detect eyes
  13. eyes = eye_cascade.detectMultiScale(roi_gray)
  14.  
  15. # for loop to iterate through the x,y,width,height of the eyes
  16. for (ex, ey, ew, eh) in eyes:
  17. # ROI is determined from y value found between the other y value.
  18. # ey:ey + h means eye(Y value) between eye(Y value) plus the eye height.
  19. # The : is a slicing operator which means between in this context.
  20. roi_color_eye = roi_color[ey:ey + eh, ex:ex + ew]
  21. # write the ROI to image and counter is included so that the new JPG will be numbered acordingly.
  22. # E.g on first iteration, eye_0.jpg will be written, then eye_1.jpg second iteration.
  23. cv2.imwrite("eye_%d.jpg" % eye_counter, roi_color_eye)
  24. # increment the counter
  25. eye_counter += 1
  26. # draw rectangle around area of interest which is equal to the eye x,y,width,height coodinates.
  27. cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 50, 0), 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement