android - FaceDetector does not detect faces -
i images device camera:
public synchronized void onpreviewframe(byte[] data, photographic camera camera) { //get image info } decode images rgb:
int[] rgb = decodeyuv420sptorgb(data, width, height); rgb bitmap:
bitmap bitmap = rgbtobitmap(rgb,width, height); print images in imageview create sure conversion fine:
iv.setimagebitmap(bitmap); detect num faces:
facedetector facedet = new facedetector(bitmap.getwidth(), bitmap.getheight(), 1); face[] facelist = new face[1]; int faces = facedet.findfaces(bitmap, facelist); log.e("numfaces: ",faces + ""); decode functions:
private int[] decodeyuv420sptorgb(byte[] yuv420sp, int width, int height) { if (yuv420sp == null) throw new nullpointerexception(); final int framesize = width * height; int[] rgb = new int[framesize]; (int j = 0, yp = 0; j < height; j++) { int uvp = framesize + (j >> 1) * width, u = 0, v = 0; (int = 0; < width; i++, yp++) { int y = (0xff & (yuv420sp[yp])) - 16; if (y < 0) y = 0; if ((i & 1) == 0) { v = (0xff & yuv420sp[uvp++]) - 128; u = (0xff & yuv420sp[uvp++]) - 128; } int y1192 = 1192 * y; int r = (y1192 + 1634 * v); int g = (y1192 - 833 * v - 400 * u); int b = (y1192 + 2066 * u); if (r < 0) r = 0; else if (r > 262143) r = 262143; if (g < 0) g = 0; else if (g > 262143) g = 262143; if (b < 0) b = 0; else if (b > 262143) b = 262143; rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff); } } homecoming rgb; } public static bitmap rgbtobitmap(int[] rgb, int width, int height) { if (rgb == null) throw new nullpointerexception(); bitmap bitmap = bitmap.createbitmap(width, height, bitmap.config.rgb_565); bitmap.setpixels(rgb, 0, width, 0, 0, width, height); homecoming bitmap; } i 0 in log.e("numfaces: ",faces + ""); while i'm seeing in imageview faces, real faces , faces in photos. tried physical devices, 2.3 (bad camera) , 4.2 (good photographic camera hd)
edit: in 4.2 device getting 800x480 frames in onpreviewframe.
any thought happens?
i have solved problem holding device in hands horizontally instead of vertically.
android image-processing
No comments:
Post a Comment