if (this.imageInput != null && this.imInput != null) {
int nTargetWidth = Math.min(imInput.getWidth(),g.getClipWidth());
int nTargetHeight = Math.min(imInput.getHeight(),g.getClipHeight());
// convert the image to gray and then
// warp the image to the clipping size
RgbShrink rs = new RgbShrink(nTargetWidth, nTargetHeight);
rs.push(this.imInput);
if (this.dh != null && !this.dh.isEmpty()) {
jjil.core.Gray8Image imMask = null;
jjil.core.Image image = dh.getFront();
if (image instanceof jjil.core.Gray8Image) {
imMask = (Gray8Image) image;
GrayConnComp gcc = new GrayConnComp();
gcc.push(imMask);
if (gcc.getComponents()> 0) {
// found a face
Rect r = gcc.getComponent(0);
// calculate center of face in mask coordinates
int x = r.getLeft() + r.getWidth() / 2;
int y = r.getTop() + r.getHeight() / 2;
// convert from mask to original image
x = (x * this.imInput.getWidth()) / imMask.getWidth();
y = (y * this.imInput.getHeight()) / imMask.getHeight();
// (x,y) is the center of the detected face
}
} else if (image instanceof jjil.core.Gray32Image) {
jjil.algorithm.Gray322Gray8 g322g8 =
new jjil.algorithm.Gray322Gray8();
g322g8.push(image);
imMask = (Gray8Image) g322g8.getFront();
} else if (image instanceof jjil.core.RgbImage) {
RgbAvg2Gray r2g = new RgbAvg2Gray();
r2g.push(image);
imMask = (Gray8Image) r2g.getFront();
}
if (imMask != null) {
// shrink the mask to fit the display
GrayShrink gs = new GrayShrink(nTargetWidth, nTargetHeight);
gs.push(imMask);
imMask = (Gray8Image) gs.getFront();
// combine the gray image and the mask to make a displayable image
ApplyMaskRgb am = new ApplyMaskRgb();
RgbImage rgb = am.push((RgbImage)rs.getFront(), imMask);
g.setColor(0x0000FF00); // green
g.fillRect(
g.getClipX(),
g.getClipY(),
g.getClipWidth(),
g.getClipHeight());
g.drawImage(
RgbImageJ2me.toImage(rgb),
g.getClipX() + (g.getClipWidth() - rgb.getWidth())/2,
g.getClipY() + (g.getClipHeight() - rgb.getHeight())/2,
0);
} else {
RgbImage rgb = (RgbImage) rs.getFront();
g.setColor(0x00FF0000); // red
g.fillRect(
g.getClipX(),
g.getClipY(),
g.getClipWidth(),