打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
源码大赛+看脸时代测脸龄

源码大赛+看脸时代测脸龄

15
devandroidaa | 2014-10-21 13:32    浏览量(115)    评论(42)    收藏(1)
功能分类:娱乐 支持平台:Android 运行环境:Eclipse
开发语言:Java 开发工具:Eclipse 源码大小:11.27MB
下载源码 266 人下载

源码简介

这是一个娱乐性的app,用户可以通过拍照或者从本地图库选择自己或者朋友的照片,然后分析出年龄,性别,还可以把分析的结果和照片分享到地图上,其他用户也可以看到您分享的照片和测试出来的年龄。
对图片进行了深度的优化,防止内存溢出。

源码截图

  • 运行截图
  • 运行截图
  • 运行截图
  • 运行截图
  • 运行截图
DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// TODO Auto-generated method stub
dialog = createLoadingDialog(MainActivity.this, "分析中...");
dialog.show();
// textView.setText("Waiting ...");
FaceppDetect faceppDetect = new FaceppDetect();
faceppDetect.setDetectCallback(new DetectCallback() {
    public void detectResult(final JSONObject rst) {
        // use the red paint
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setStrokeWidth(Math.max(img.getWidth(),
                img.getHeight()) / 100f);
        // create a new canvas
        final Bitmap bitmap = Bitmap.createBitmap(
                img.getWidth(), img.getHeight(),
                img.getConfig());
        Canvas canvas = new Canvas(bitmap);
        canvas.drawBitmap(img, new Matrix(), null);
        try {
            // find out all faces
            final int count = rst.getJSONArray("face").length();
            for (int i = 0; i < count; ++i) {
                float x, y, w, h;
                // get the center point
                x = (float) rst.getJSONArray("face")
                        .getJSONObject(i)
                        .getJSONObject("position")
                        .getJSONObject("center").getDouble("x");
                y = (float) rst.getJSONArray("face")
                        .getJSONObject(i)
                        .getJSONObject("position")
                        .getJSONObject("center").getDouble("y");
                // get face size
                w = (float) rst.getJSONArray("face")
                        .getJSONObject(i)
                        .getJSONObject("position")
                        .getDouble("width");
                h = (float) rst.getJSONArray("face")
                        .getJSONObject(i)
                        .getJSONObject("position")
                        .getDouble("height");
                age = rst.getJSONArray("face").getJSONObject(i)
                        .getJSONObject("attribute")
                        .getJSONObject("age")
                        .getString("value");
                range = rst.getJSONArray("face")
                        .getJSONObject(i)
                        .getJSONObject("attribute")
                        .getJSONObject("age")
                        .getString("range");
                gender = rst.getJSONArray("face")
                        .getJSONObject(i)
                        .getJSONObject("attribute")
                        .getJSONObject("gender")
                        .getString("value");
                // change percent value to the real size
                x = x / 100 * img.getWidth();
                w = w / 100 * img.getWidth() * 0.7f;
                y = y / 100 * img.getHeight();
                h = h / 100 * img.getHeight() * 0.7f;
                // draw the box to mark it out
                canvas.drawLine(x - w, y - h, x - w, y + h,
                        paint);
                canvas.drawLine(x - w, y - h, x + w, y - h,
                        paint);
                canvas.drawLine(x + w, y + h, x - w, y + h,
                        paint);
                canvas.drawLine(x + w, y + h, x + w, y - h,
                        paint);
            }
            // save new image
            // img = bitmap;
            MainActivity.this.runOnUiThread(new Runnable() {
                public void run() {
                    dialog.dismiss();
                    String msg = null;
                    try {
                        if (Integer.valueOf(age) <= 15) {
                            msg = Integer.valueOf(age)
                                    + Integer.valueOf(range)
                                    + "";
                        } else if (Integer.valueOf(age) <= 18
                                && Integer.valueOf(age) >= 15) {
                            msg = age;
                        } else if (Integer.valueOf(age) > 25
                                && Integer.valueOf(age) <= 35) {
                            int i = (Integer.valueOf(age) - 25)
                                    / Integer.valueOf(range);
                            msg = Integer.valueOf(age) - i + "";
                        } else if (Integer.valueOf(age) > 35) {
                            msg = Integer.valueOf(age)
                                    - Integer.valueOf(range)
                                    + "";
                        } else {
                            msg = age;
                        }
                        age = msg;
                    } catch (Exception e) {
                        showToast("分析失败.");
                        return;
                    }
                    if (gender.equals("Male")) {
                        gender = "男";
                    } else if (gender.equals("Female")) {
                        gender = "女";
                    }
                    msg = "分析结果:" + gender + "   " + msg + "岁";
                    showToast(msg);
                    // show the image
                    imageView.setImageBitmap(bitmap);
                    // textView.setText("Finished, "+ count +
                    // " faces.");
                    showdialog(msg, age);
                    age = "";
                };
            });
        } catch (JSONException e) {
            e.printStackTrace();
            MainActivity.this.runOnUiThread(new Runnable() {
                public void run() {
                    showToast("JSONException");
                }
            });
        }
    }
});
faceppDetect.detect(img);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
html2canvas网页截图
delphi7编程技巧与实例精解之图形图像(修正重绘变形)
java解析json
Javascript网页截屏的方法
js打印功能的实现(通用)
初探JavaScript的截屏实现
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服