« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Legends
Identify People in a Photo
In[1]:=
Identify faces in a photo and draw a colored square around each match.
In[2]:=
X
faces = FindFaces[img, {40, 50}];
In[3]:=
X
newimg = Show[img, Graphics[Table[ {EdgeForm[{Thick, Hue[Rescale[i, {0, Length[faces]}]]}], FaceForm[], Rectangle @@ faces[[i]]}, {i, Length[faces]}]]]
Out[3]=
Create a swatch legend that matches each person's name with the colored square.
In[4]:=
X
legend[layout_] := SwatchLegend[ Table[Hue[Rescale[i, {0, Length[faces]}]], {i, Length[faces]}], {"Mark", "Cynthia", "Michelle", "Adrian", "Rachel"}, LegendMarkerSize -> Medium, LabelStyle -> {GrayLevel[0.3], 16, Bold}, LegendLayout -> layout]
In[5]:=
X
legend["Row"]
Out[5]=
Add the legend to the photo.
In[6]:=
X
Legended[newimg, legend["Column"]]
Out[6]=
Change the legend position and orientation.
In[7]:=
X
Legended[newimg, Placed[legend["Row"], Below]]
Out[7]=