0

My problem is that I want to find the largest square that contains all faces in an image, then crop image base on this square.
It looks like this (the red square is what I want):
enter image description here

I searched on many questions and found this question is similar to my question, but his way only crop the face on photo.
Is there any suggestions to solve my problem?
P:/s: if the largest square doesn't contain all faces (there are faces outside the square), just don't crop it. Update: the red square can move around the photo to find matched result. The other thing that I forgot to mention: is there any way to get the good result with the faces and bodies on the photo?

Community
  • 1
  • 1
ductran
  • 10,043
  • 19
  • 82
  • 165

1 Answers1

1

Okay here it goes.

  1. Store the vertices of all the squares that show faces.
  2. Draw your largest square and store its vertices
  3. Check every square in the list. If the top-left coordinate of the face square lies outside the largest square or the bottom-right lies outside the largest square, the face lies outside the largest square.
An SO User
  • 24,612
  • 35
  • 133
  • 221
  • And to add: 4. add some padding to your result (this would match your desired output as shown above) – Brent McFerrin Aug 25 '14 at 03:06
  • @BrentMcFerrin Thanks for the input. I guess the red square is placed arbitrarily? Who defines the red square? Can it be moved around? :) All those questions are unanswered. From the question it seems the OP *needs* to find that red square. – An SO User Aug 25 '14 at 03:10
  • Yeah, my thought is that you want the faces -- and some of the surroundings. Otherwise you may have lots of partial heads (i.e. no hair, ears, etc.) in the results. But it's not entirely clear because the question doesn't quite match the picture. – Brent McFerrin Aug 25 '14 at 03:17
  • @BrentMcFerrin Yes, the square edges need to be equidistant from the faces. The left and right atleast. But the OP will get the gist. – An SO User Aug 25 '14 at 03:19
  • Thanks, I forgot to mention, I want to get the good result with the faces and bodies (you know, I can't make the body out of the square). Please check my update question – ductran Aug 25 '14 at 03:29