Skip to content

7-2 人脸识别

face.JPG

人脸识别是基于人的脸部特征信息进行身份识别的技术,包括人脸图像采集及检测、图像预处理、特征提取以及匹配与识别四大部分。本题请你为机器人警察实现一个非常简单的特征匹配算法,帮助查找罪犯:即给定数据库中存储的某罪犯的双眼间距、鼻梁长度、唇宽,然后与面前这个人的特征数据进行匹配,判断其是否该罪犯。

输入格式:

输入在第一行中给出罪犯的双眼间距 L0、鼻梁长度 L1、唇宽 L2、以及允许的误差范围 T。第二行中给出当前被检测的人的双眼间距 l0、鼻梁长度 l1、唇宽 l2。所有数字均为毫米为单位的长度,是不超过 100 的正整数,同行数字间以空格分隔。

输出格式:

首先在第一行中输出两个人脸特征的误差,格式为:

Diff = D0, D1, D2
Diff = D0, D1, D2

其中 D0=L0−l0,D1=L1−l1,D2=L2−l2。如果三项误差的绝对值之和不超过 T,则在第二行输出 Yes,否则输出 No

输入样例 1:

tex
23 60 54 3
23 59 56
23 60 54 3
23 59 56

输出样例 1:

tex
Diff = 0, 1, -2
Yes
Diff = 0, 1, -2
Yes

输入样例 2:

tex
23 60 54 3
24 59 56
23 60 54 3
24 59 56

输出样例 2:

tex
Diff = -1, 1, -2
No
Diff = -1, 1, -2
No

Solution:

java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] input = in.readLine().split(" ");
        int L0 = Integer.parseInt(input[0]);
        int L1 = Integer.parseInt(input[1]);
        int L2 = Integer.parseInt(input[2]);
        int T = Integer.parseInt(input[3]);
        input = in.readLine().split(" ");
        int l0 = Integer.parseInt(input[0]);
        int l1 = Integer.parseInt(input[1]);
        int l2 = Integer.parseInt(input[2]);
        int D0 = L0 - l0;
        int D1 = L1 - l1;
        int D2 = L2 - l2;
        System.out.printf("Diff = %d, %d, %d\n", D0, D1, D2);
        if (Math.abs(D0) + Math.abs(D1) + Math.abs(D2) <= T) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] input = in.readLine().split(" ");
        int L0 = Integer.parseInt(input[0]);
        int L1 = Integer.parseInt(input[1]);
        int L2 = Integer.parseInt(input[2]);
        int T = Integer.parseInt(input[3]);
        input = in.readLine().split(" ");
        int l0 = Integer.parseInt(input[0]);
        int l1 = Integer.parseInt(input[1]);
        int l2 = Integer.parseInt(input[2]);
        int D0 = L0 - l0;
        int D1 = L1 - l1;
        int D2 = L2 - l2;
        System.out.printf("Diff = %d, %d, %d\n", D0, D1, D2);
        if (Math.abs(D0) + Math.abs(D1) + Math.abs(D2) <= T) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Released under the MIT License.