编辑代码

#include <stdio.h>
#include <stdlib.h>

#include "bmp.h"

//读取图片用---图像宽、长、每像素所占字节数、读取到的图片矩阵的总字节数
unsigned char *PinJie, *man1, *man2, *woman1, *woman2;

int PinJie_getWidth, man1_getWidth, man2_getWidth, woman1_getWidth, woman2_getWidth;//图像宽
int PinJie_getHeight, man1_getHeight, man2_getHeight, woman1_getHeight, woman2_getHeight;//图像长
int PinJie_pByteCount, man1_pByteCount, man2_pByteCount, woman1_pByteCount, woman2_pByteCount;//每像素所占字节数
int PinJie_picSize, man1_picSize, man2_picSize, woman1_picSize, woman2_picSize;//读取到的图片矩阵的总字节数



int main() {

    //读取图片
    man1 = bmp_get("E:\\C语言答辩图片库\\man1.bmp", &man1_picSize, &man1_getWidth,
                   &man1_getHeight, &man1_pByteCount);  //后面那几个取址的参数是用来接收图片参数的,不接收的话可以置NULL
    man2 = bmp_get("E:\\C语言答辩图片库\\man2.bmp", &man2_picSize, &man2_getWidth,
                   &man2_getHeight, &man2_pByteCount);
    woman1 = bmp_get("E:\\C语言答辩图片库\\woman1.bmp", &woman1_picSize, &woman1_getWidth,
                     &woman1_getHeight, &woman1_pByteCount);
    woman2 = bmp_get("E:\\C语言答辩图片库\\woman2.bmp", &woman2_picSize, &woman2_getWidth,
                     &woman2_getHeight, &woman2_pByteCount);
//读取图片无误#include <stdio.h>
#include <stdlib.h>

#include "bmp.h"

//读取图片用---图像宽、长、每像素所占字节数、读取到的图片矩阵的总字节数
unsigned char *PinJie, *man1, *man2, *woman1, *woman2;

int PinJie_getWidth, man1_getWidth, man2_getWidth, woman1_getWidth, woman2_getWidth;//图像宽
int PinJie_getHeight, man1_getHeight, man2_getHeight, woman1_getHeight, woman2_getHeight;//图像长
int PinJie_pByteCount, man1_pByteCount, man2_pByteCount, woman1_pByteCount, woman2_pByteCount;//每像素所占字节数
int PinJie_picSize, man1_picSize, man2_picSize, woman1_picSize, woman2_picSize;//读取到的图片矩阵的总字节数



int main() {

    //读取图片
    man1 = bmp_get("E:\\C语言答辩图片库\\man1.bmp", &man1_picSize, &man1_getWidth,
                   &man1_getHeight, &man1_pByteCount);  //后面那几个取址的参数是用来接收图片参数的,不接收的话可以置NULL
    man2 = bmp_get("E:\\C语言答辩图片库\\man2.bmp", &man2_picSize, &man2_getWidth,
                   &man2_getHeight, &man2_pByteCount);
    woman1 = bmp_get("E:\\C语言答辩图片库\\woman1.bmp", &woman1_picSize, &woman1_getWidth,
                     &woman1_getHeight, &woman1_pByteCount);
    woman2 = bmp_get("E:\\C语言答辩图片库\\woman2.bmp", &woman2_picSize, &woman2_getWidth,
                     &woman2_getHeight, &woman2_pByteCount);
//读取图片无误
    if (man1 && man2 && woman1 && woman2) {
        char *PATH = "E:\\C语言答辩图片库\\PinJie.bmp";//拼接后的图片路径--按需求更改

        PinJie_getWidth = man1_getWidth;
        PinJie_getHeight = man1_getHeight + man2_getHeight + woman1_getHeight + woman2_getHeight;
        PinJie_pByteCount = man1_pByteCount;
        PinJie_picSize = man1_picSize + man2_picSize + woman1_picSize + woman2_picSize;
        printf("PinJie_picSize:%d\n", PinJie_picSize);

        PinJie = (unsigned char *) malloc(PinJie_picSize * sizeof(unsigned char));

//4张图片数据-拼接
        for (int i = 0; i < man1_picSize; ++i) {
            PinJie[i] = man1[i];
        }
        for (int i = man1_picSize; i < man1_picSize + man2_picSize; ++i) {
            PinJie[i] = man2[i - man1_picSize];
        }
        for (int i = man1_picSize + man2_picSize; i < man1_picSize + man2_picSize + woman1_picSize; ++i) {
            PinJie[i] = woman1[i - man1_picSize - man2_picSize];
        }
        for (int i = man1_picSize + man2_picSize + woman1_picSize; i < PinJie_picSize; ++i) {
            PinJie[i] = woman2[i - man1_picSize - man2_picSize - woman1_picSize];
        }
//将拼接后的图片数据写入到新的图片中,并保存到指定路径。
        bmp_create(PATH, PinJie, PinJie_getWidth, PinJie_getHeight, PinJie_pByteCount);
    }


//识别发色色块
    int x, y;//x是宽,y是高
    int count = 0;//头发色块的个数
    int man1_count, man2_count, woman1_count, woman2_count;

    for (y = 0; y < man1_getHeight; y++) {
        for (x = 0; x < man1_getWidth; x++) {
            int colorLocation = y * man1_getWidth * man1_pByteCount + x * man1_pByteCount;
            if ((man1[colorLocation] >= 0 && man1[colorLocation] <= 70) &&
                (man1[colorLocation + 1] >= 0 && man1[colorLocation + 1] <= 70) &&
                (man1[colorLocation + 2] >= 0 && man1[colorLocation + 2] <= 70)) {
                //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                count++;
            }
        }
    }
    man1_count=count;
    printf("man1_count:%d\n", count);
    count = 0;
    for (y = 0; y < man2_getHeight; y++) {
        for (x = 0; x < man2_getWidth; x++) {
            int colorLocation = y * man2_getWidth * man2_pByteCount + x * man2_pByteCount;
            if ((man2[colorLocation] >= 0 && man2[colorLocation] <= 32) &&
                (man2[colorLocation + 1] >= 0 && man2[colorLocation + 1] <= 32) &&
                (man2[colorLocation + 2] >= 0 && man2[colorLocation + 2] <= 32)) {
                //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                count++;
            }
        }
    }
    man2_count=count;
    printf("man2_count:%d\n", count);
    count = 0;
    for (y = 0; y < woman1_getHeight; y++) {
        for (x = 0; x < woman1_getWidth; x++) {
            int colorLocation = y * woman1_getWidth * woman1_pByteCount + x * woman1_pByteCount;
            if ((woman1[colorLocation] >= 0 && woman1[colorLocation] <= 32) &&
                (woman1[colorLocation + 1] >= 0 && woman1[colorLocation + 1] <= 32) &&
                (woman1[colorLocation + 2] >= 0 && woman1[colorLocation + 2] <= 32)) {
                //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                count++;
            }
        }
    }
    woman1_count=count;
    printf("woman1_count:%d\n", count);
    count = 0;
    for (y = 0; y < woman2_getHeight; y++) {
        for (x = 0; x < woman2_getWidth; x++) {
            int colorLocation = y * woman2_getWidth * woman2_pByteCount + x * woman2_pByteCount;
            if ((woman2[colorLocation] >= 0 && woman2[colorLocation] <= 32) &&
                (woman2[colorLocation + 1] >= 0 && woman2[colorLocation + 1] <= 32) &&
                (woman2[colorLocation + 2] >= 0 && woman2[colorLocation + 2] <= 32)) {
                //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                count++;
            }
        }
    }
    woman2_count=count;
    printf("woman2_count:%d\n", count);

//面部大小识别
    double scale_TouFaChuLian;
    int num=0;//面部像素点个数
    for (y = 0; y < man1_getHeight; y++) {
        for (x = 0; x < man1_getWidth; x++) {
            int colorLocation = y * man1_getWidth * man1_pByteCount + x * man1_pByteCount;
            if (y <= (int) (0.64 * man1_getHeight)) {
                if ((man1[colorLocation] >= 100 && man1[colorLocation] <= 230) &&
                    (man1[colorLocation + 1] >= 130 && man1[colorLocation + 1] <= 234) &&
                    (man1[colorLocation + 2] >= 143 && man1[colorLocation + 2] <= 254)) {
                    //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                    num++;
                }

            }
        }
    }

    scale_TouFaChuLian=(double)man1_count/num;
    printf("man1_scale_TouFaChuLian:%f\n", scale_TouFaChuLian);
    num = 0;
    for (y = 0; y < man2_getHeight; y++) {
        for (x = 0; x < man2_getWidth; x++) {
            int colorLocation = y * man2_getWidth * man2_pByteCount + x * man2_pByteCount;
            if (y <= (int) (0.50 * man2_getHeight)) {
                if ((man2[colorLocation] >= 100 && man2[colorLocation] <= 230) &&
                    (man2[colorLocation + 1] >= 130 && man2[colorLocation + 1] <= 234) &&
                    (man2[colorLocation + 2] >= 143 && man2[colorLocation + 2] <= 254)) {
                    //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                    num++;
                }
            }
        }
    }

    scale_TouFaChuLian=(double)man2_count/num;
    printf("man2_scale_TouFaChuLian:%f\n", scale_TouFaChuLian);
    num = 0;
    for (y = 0; y < woman1_getHeight; y++) {
        for (x = 0; x < woman1_getWidth; x++) {
            int colorLocation = y * woman1_getWidth * woman1_pByteCount + x * woman1_pByteCount;
            if (y <= (int) (0.32 * man1_getHeight)) {
                if ((woman1[colorLocation] >= 100 && woman1[colorLocation] <= 230) &&
                    (woman1[colorLocation + 1] >= 130 && woman1[colorLocation + 1] <= 234) &&
                    (woman1[colorLocation + 2] >= 163 && woman1[colorLocation + 2] <= 254)) {
                    //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                    num++;
                }
            }
        }
    }
    scale_TouFaChuLian=(double)woman1_count/num;
    printf("woman1_scale_TouFaChuLian:%f\n", scale_TouFaChuLian);
    num = 0;
    for (y = 0; y < woman2_getHeight; y++) {
        for (x = 0; x < woman2_getWidth; x++) {
            int colorLocation = y * woman2_getWidth * woman2_pByteCount + x * woman2_pByteCount;
            if (y <= (int) (0.64 * man1_getHeight)) {
                if ((woman2[colorLocation] >= 209 && woman2[colorLocation] <= 230) &&
                    (woman2[colorLocation + 1] >= 130 && woman2[colorLocation + 1] <= 234) &&
                    (woman2[colorLocation + 2] >= 143 && woman2[colorLocation + 2] <= 254)) {
                    //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                    num++;
                }
            }
        }
    }
    scale_TouFaChuLian=(double) woman2_count/num;
    printf("woman2_scale_TouFaChuLian:%f\n", scale_TouFaChuLian);

    return 0;
}


    if (man1 && man2 && woman1 && woman2) {
        char *PATH = "D:\\CProject\\CLionProjects\\ByWork\\20230625\\PinJie.bmp";//拼接后的图片路径--按需求更改

        PinJie_getWidth = man1_getWidth;
        PinJie_getHeight = man1_getHeight + man2_getHeight + woman1_getHeight + woman2_getHeight;
        PinJie_pByteCount = man1_pByteCount;
        PinJie_picSize = man1_picSize + man2_picSize + woman1_picSize + woman2_picSize;
        printf("PinJie_picSize:%d\n", PinJie_picSize);

        PinJie = (unsigned char *) malloc(PinJie_picSize * sizeof(unsigned char));

//4张图片数据-拼接
        for (int i = 0; i < man1_picSize; ++i) {
            PinJie[i] = man1[i];
        }
        for (int i = man1_picSize; i < man1_picSize + man2_picSize; ++i) {
            PinJie[i] = man2[i - man1_picSize];
        }
        for (int i = man1_picSize + man2_picSize; i < man1_picSize + man2_picSize + woman1_picSize; ++i) {
            PinJie[i] = woman1[i - man1_picSize - man2_picSize];
        }
        for (int i = man1_picSize + man2_picSize + woman1_picSize; i < PinJie_picSize; ++i) {
            PinJie[i] = woman2[i - man1_picSize - man2_picSize - woman1_picSize];
        }
//将拼接后的图片数据写入到新的图片中,并保存到指定路径。
        bmp_create(PATH, PinJie, PinJie_getWidth, PinJie_getHeight, PinJie_pByteCount);
    }


//识别发色色块
    int x, y;//x是宽,y是高
    int count = 0;//头发色块的个数
    int man1_count, man2_count, woman1_count, woman2_count;

    for (y = 0; y < man1_getHeight; y++) {
        for (x = 0; x < man1_getWidth; x++) {
            int colorLocation = y * man1_getWidth * man1_pByteCount + x * man1_pByteCount;
            if ((man1[colorLocation] >= 0 && man1[colorLocation] <= 70) &&
                (man1[colorLocation + 1] >= 0 && man1[colorLocation + 1] <= 70) &&
                (man1[colorLocation + 2] >= 0 && man1[colorLocation + 2] <= 70)) {
                //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                count++;
            }
        }
    }
    man1_count=count;
    printf("man1_count:%d\n", count);
    count = 0;
    for (y = 0; y < man2_getHeight; y++) {
        for (x = 0; x < man2_getWidth; x++) {
            int colorLocation = y * man2_getWidth * man2_pByteCount + x * man2_pByteCount;
            if ((man2[colorLocation] >= 0 && man2[colorLocation] <= 32) &&
                (man2[colorLocation + 1] >= 0 && man2[colorLocation + 1] <= 32) &&
                (man2[colorLocation + 2] >= 0 && man2[colorLocation + 2] <= 32)) {
                //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                count++;
            }
        }
    }
    man2_count=count;
    printf("man2_count:%d\n", count);
    count = 0;
    for (y = 0; y < woman1_getHeight; y++) {
        for (x = 0; x < woman1_getWidth; x++) {
            int colorLocation = y * woman1_getWidth * woman1_pByteCount + x * woman1_pByteCount;
            if ((woman1[colorLocation] >= 0 && woman1[colorLocation] <= 32) &&
                (woman1[colorLocation + 1] >= 0 && woman1[colorLocation + 1] <= 32) &&
                (woman1[colorLocation + 2] >= 0 && woman1[colorLocation + 2] <= 32)) {
                //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                count++;
            }
        }
    }
    woman1_count=count;
    printf("woman1_count:%d\n", count);
    count = 0;
    for (y = 0; y < woman2_getHeight; y++) {
        for (x = 0; x < woman2_getWidth; x++) {
            int colorLocation = y * woman2_getWidth * woman2_pByteCount + x * woman2_pByteCount;
            if ((woman2[colorLocation] >= 0 && woman2[colorLocation] <= 32) &&
                (woman2[colorLocation + 1] >= 0 && woman2[colorLocation + 1] <= 32) &&
                (woman2[colorLocation + 2] >= 0 && woman2[colorLocation + 2] <= 32)) {
                //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                count++;
            }
        }
    }
    woman2_count=count;
    printf("woman2_count:%d\n", count);

//面部大小识别
    double scale_TouFaChuLian;
    int num=0;//面部像素点个数
    for (y = 0; y < man1_getHeight; y++) {
        for (x = 0; x < man1_getWidth; x++) {
            int colorLocation = y * man1_getWidth * man1_pByteCount + x * man1_pByteCount;
            if (y <= (int) (0.64 * man1_getHeight)) {
                if ((man1[colorLocation] >= 100 && man1[colorLocation] <= 230) &&
                    (man1[colorLocation + 1] >= 130 && man1[colorLocation + 1] <= 234) &&
                    (man1[colorLocation + 2] >= 143 && man1[colorLocation + 2] <= 254)) {
                    //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                    num++;
                }

            }
        }
    }

    scale_TouFaChuLian=(double)man1_count/num;
    printf("man1_scale_TouFaChuLian:%f\n", scale_TouFaChuLian);
    num = 0;
    for (y = 0; y < man2_getHeight; y++) {
        for (x = 0; x < man2_getWidth; x++) {
            int colorLocation = y * man2_getWidth * man2_pByteCount + x * man2_pByteCount;
            if (y <= (int) (0.50 * man2_getHeight)) {
                if ((man2[colorLocation] >= 100 && man2[colorLocation] <= 230) &&
                    (man2[colorLocation + 1] >= 130 && man2[colorLocation + 1] <= 234) &&
                    (man2[colorLocation + 2] >= 143 && man2[colorLocation + 2] <= 254)) {
                    //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                    num++;
                }
            }
        }
    }

    scale_TouFaChuLian=(double)man2_count/num;
    printf("man2_scale_TouFaChuLian:%f\n", scale_TouFaChuLian);
    num = 0;
    for (y = 0; y < woman1_getHeight; y++) {
        for (x = 0; x < woman1_getWidth; x++) {
            int colorLocation = y * woman1_getWidth * woman1_pByteCount + x * woman1_pByteCount;
            if (y <= (int) (0.32 * man1_getHeight)) {
                if ((woman1[colorLocation] >= 100 && woman1[colorLocation] <= 230) &&
                    (woman1[colorLocation + 1] >= 130 && woman1[colorLocation + 1] <= 234) &&
                    (woman1[colorLocation + 2] >= 163 && woman1[colorLocation + 2] <= 254)) {
                    //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                    num++;
                }
            }
        }
    }
    scale_TouFaChuLian=(double)woman1_count/num;
    printf("woman1_scale_TouFaChuLian:%f\n", scale_TouFaChuLian);
    num = 0;
    for (y = 0; y < woman2_getHeight; y++) {
        for (x = 0; x < woman2_getWidth; x++) {
            int colorLocation = y * woman2_getWidth * woman2_pByteCount + x * woman2_pByteCount;
            if (y <= (int) (0.64 * man1_getHeight)) {
                if ((woman2[colorLocation] >= 209 && woman2[colorLocation] <= 230) &&
                    (woman2[colorLocation + 1] >= 130 && woman2[colorLocation + 1] <= 234) &&
                    (woman2[colorLocation + 2] >= 143 && woman2[colorLocation + 2] <= 254)) {
                    //3通道的位图数据(也就是我们通常说的彩图),那么它是按照B0G0R0B1G1R1B2G2R2...的顺序进行存储的(即蓝绿红)
                    num++;
                }
            }
        }
    }
    scale_TouFaChuLian=(double) woman2_count/num;
    printf("woman2_scale_TouFaChuLian:%f\n", scale_TouFaChuLian);

    return 0;
}