eye detection - Inserting an image at a particular position using matlab -
i want insert sunglasses(png image) @ position eyes gets detected(considering in-plane rotation). have used in-built haar cascade detector detecting eyes in matlab. have eyes detected highlighted bounding boxes return position of eyes in image.let me know how can done(i beginner in matlab).
(presuming both images greyscale, expansion rgb not difficult. unchecked , i'm not promising haven't flipped x/y coords @ point).
if eye positions on same horizontal line, e.g. for straight face:
face = face image ohyeah = sunglasses image fspan = horizontal distance between eyes, in pixels (you should able bounding box info) gspan = ditto sunglasses image (you can manually - need measure once) cpos = central position, [x y] of eyes (again, calc bounding box)
check if need resize sunglasses image - might need if it's lot larger or smaller need:
sr = fspan/gspan; if abs(sr-1)>thresh; ohyeah = imresize(ohyeah, sr); end
now, find top left , bottom right corners:
pos1 = pos - ceil(size(ohyeah)/2); pos2 = pos1 + size(ohyeah) - 1;
note: may want/need check @ point values don't go beyond outer edges of original image.
provided above values acceptable indices face
, can copy sunglasses images over:
face2 = face; face2(pos1(1):pos2(1),pos1(2):pos2(2))=ohyeah; imshow(face2);
this pastes rectangle in correct position. can fancier , use mask, see below:
for rotated faces:
1) rotate , resize glasses image match (for example if know points on glasses image want centres of eyes go simple geometry).
2) make bw mask 1 glasses , 0 otherwise (relatively easy if image on black background).
3) find position need put glasses on
4) clip out appropriate part of face image:
face2 = face(pos1(1):pos2(1),pos1(2):pos2(2));
5) replace appropriate parts of sunglasses image:
face2(bw) = ohyeah(bw);
6) stick original image
face(pos1(1):pos2(1),pos1(2):pos2(2)) = face2;
Comments
Post a Comment