Skip to content

Commit 6bc6767

Browse files
committed
start conversion of bmp to rgb dlib image
1 parent 30b8869 commit 6bc6767

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

visionSamples/FaceTracker/app/src/main/cpp/native-lib.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,35 @@
33
#include <android/log.h>
44
#include <android/bitmap.h>
55

6+
#include <dlib/dnn.h>
7+
#include <dlib/image_processing/frontal_face_detector.h>
68
#include <dlib/image_processing.h>
9+
#include <dlib/svm/svm_multiclass_linear_trainer.h>
710

811
using namespace std;
12+
using namespace dlib;
913

1014
#define LOG_TAG "Native"
1115
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
1216
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
1317

18+
typedef struct
19+
{
20+
uint8_t alpha;
21+
uint8_t red;
22+
uint8_t green;
23+
uint8_t blue;
24+
} argb;
25+
1426
extern "C"
1527
JNIEXPORT jstring JNICALL
1628
Java_com_google_android_gms_samples_vision_face_facetracker_CustomDetector_test(JNIEnv *env,
1729
jobject instance,
1830
jobject bmp) {
1931
AndroidBitmapInfo infocolor;
32+
void* pixelscolor;
33+
int y;
34+
int x;
2035
int ret;
2136
if ((ret = AndroidBitmap_getInfo(env, bmp, &infocolor)) < 0) {
2237
LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
@@ -29,6 +44,30 @@ Java_com_google_android_gms_samples_vision_face_facetracker_CustomDetector_test(
2944
LOGE("Bitmap format is not RGBA_8888 !");
3045
return env->NewStringUTF("Image broken 2");
3146
}
47+
48+
if ((ret = AndroidBitmap_lockPixels(env, bmp, &pixelscolor)) < 0) {
49+
LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
50+
}
51+
52+
for (y=0;y<infocolor.height;y++) {
53+
argb * line = (argb *) pixelscolor;
54+
pixelscolor = (char *)pixelscolor + infocolor.stride;
55+
}
56+
57+
// array2d<rgb_pixel> img;
58+
// img.set_size(infocolor.height, infocolor.width);
59+
// for (int y = 0; y < infocolor.height; y++){
60+
// for (int x = 0; x < infocolor.width; x++){
61+
// img[y][x] = pixelscolor[y * infocolor.width + x];
62+
// }
63+
// }
64+
65+
66+
LOGI("unlocking pixels");
67+
AndroidBitmap_unlockPixels(env, bmp);
68+
69+
70+
3271
const char *returnValue = "test";
3372
return env->NewStringUTF(returnValue);
3473
}

visionSamples/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face/facetracker/CustomDetector.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ public SparseArray<Face> detect(Frame frame) {
6363
mFrame = frame;
6464
if (IsBusy) {
6565
if (recognitionHandler != null) {
66-
YuvImage yuvImage = new YuvImage(frame.getGrayscaleImageData().array(), ImageFormat.NV21, frame.getMetadata().getWidth(), frame.getMetadata().getHeight(), null);
66+
YuvImage yuvImage = new YuvImage(frame.getGrayscaleImageData().array(), ImageFormat.NV21,
67+
frame.getMetadata().getWidth(), frame.getMetadata().getHeight(), null);
6768
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
68-
yuvImage.compressToJpeg(new Rect(0, 0, frame.getMetadata().getWidth(), frame.getMetadata().getHeight()), 100, byteArrayOutputStream);
69+
yuvImage.compressToJpeg(new Rect(0, 0, frame.getMetadata().getWidth(),
70+
frame.getMetadata().getHeight()), 100, byteArrayOutputStream);
6971
byte[] jpegArray = byteArrayOutputStream.toByteArray();
7072
Bitmap tmpBitmap = BitmapFactory.decodeByteArray(jpegArray, 0, jpegArray.length);
7173
final Bitmap cropped = Bitmap.createBitmap(tmpBitmap, x, y, w, h);

0 commit comments

Comments
 (0)