标签:col stat 模式 inter 格式 out alt rect height
虹软产品地址:http://ai.arcsoft.com.cn/product/arcface.html
虹软ArcFace功能简介
人脸检测
人脸跟踪
人脸属性检测(性别、年龄)
人脸三维角度检测
人脸对比
示例代码说明,其中图片操作部分用到了javacv,javacv中针对opencv进行了一些封装,可以很好的对图片进行处理。此处主要用到了opencv的几个函数
加载图片 IplImage img = cvLoadImage("e:/pic/g5.jpg"); 格式转换,将IplImage 转为Mat, OpenCVFrameConverter.ToMat converterToMat = new OpenCVFrameConverter.ToMat(); Mat mat = converterToMat.convert(converterToMat.convert(img)); 对图片,增加矩形框,此处用来圈出人脸的位置 rectangle(mat, new Rect(mrect.left,mrect.top,mrect.right-mrect.left,mrect.bottom-mrect.top), new Scalar(0, 255, 0, 1)); 将mat数据,写入图片文件中 imwrite("e:/pic/detected.jpg", mat);
示例代码如下:
package com.arcsoft.face; import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage; import static org.bytedeco.javacpp.opencv_imgcodecs.imwrite; import static org.bytedeco.javacpp.opencv_imgproc.rectangle; import org.bytedeco.javacpp.BytePointer; import org.bytedeco.javacpp.opencv_core.IplImage; import org.bytedeco.javacpp.opencv_core.Mat; import org.bytedeco.javacpp.opencv_core.Rect; import org.bytedeco.javacpp.opencv_core.Scalar; import org.bytedeco.javacv.OpenCVFrameConverter; import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.PointerByReference; public class FaceDetectTest { public static void main(String[] args) { FaceEngine ins = FaceEngine.INSTANCE; //SDK激活 ins.ASFActivation("6iYHk9hRsCNBJvFY7qhpaxnmmpFPnjWWpboYSafaz5hN", "GRwuiEVRTyeRUCHyihMP1B8Xf59zsQBtdZSbeQtfWWhg"); PointerByReference phEngine = new PointerByReference(); //SDK初始化,需要设置模式是video,还是image,配置人脸检测的角度,engine需要支持的功能 mask,最大支持的人脸数量50,人脸大小16 int mask = FaceEngine.ASF_FACE_DETECT | FaceEngine.ASF_FACERECOGNITION | FaceEngine.ASF_AGE | FaceEngine.ASF_GENDER | FaceEngine.ASF_FACE3DANGLE; NativeLong ret = ins.ASFInitEngine(FaceEngine.ASF_DETECT_MODE_IMAGE, OrientPriority.AFD_FSDK_OPF_0_ONLY, 16,50, mask, phEngine); if (ret.longValue() != FaceEngine.MOK) { System.out.println(ret.longValue()); } //获取图片数据,此处使用javacv中封装的对应opencv的方法完成 IplImage img = cvLoadImage("e:/pic/g5.jpg"); BytePointer bp = img.arrayData(); byte[] imgData = new byte[img.arraySize()];//图片数据 bp.get(imgData); //获得engine对应的指针 Pointer hEngine = phEngine.getValue(); //当前系统版本 Version version = ins.ASFGetVersion(hEngine); System.out.println(version.Version); System.out.println(version.CopyRight); System.out.println(version.BuildDate); //进行人脸检测,detectedFaces为输出项 MultiFaceInfo detectedFaces = new MultiFaceInfo(); ins.ASFDetectFaces(hEngine, img.width(), img.height(), ASVL_COLOR_FORMAT.ASVL_PAF_RGB24_B8G8R8,imgData, detectedFaces); System.out.println("detected face num:"+detectedFaces.faceNum); //使用opencv的api对照片进行处理,将人脸区域画出来,保存为一张新图片 OpenCVFrameConverter.ToMat converterToMat = new OpenCVFrameConverter.ToMat(); Mat mat = converterToMat.convert(converterToMat.convert(img)); MRECT[] rects = detectedFaces.getFaceRects(); for (MRECT mrect : rects) { rectangle(mat, new Rect(mrect.left,mrect.top,mrect.right-mrect.left,mrect.bottom-mrect.top), new Scalar(0, 255, 0, 1)); } imwrite("e:/pic/detected.jpg", mat); } }
待做人脸检测的图片
程序识别后,并标识出人脸位置后,效果看起来很棒
再找一张人脸特别多的图片,准确圈出所有人脸位置
使用已经封装好的SDK进行人脸识别
https://www.jianshu.com/p/96636db03792
使用已经封装好的SDK进行人脸识别【人脸特征提取比对】
https://www.jianshu.com/p/ab64464571da
虹软ArcFace 2.0,java SDK使用、人脸信息识别(年龄、性别)
https://www.jianshu.com/p/cfe90f82be97
java 虹软ArcFace 2.0,java SDK使用-进行人脸检测
标签:col stat 模式 inter 格式 out alt rect height
原文地址:https://www.cnblogs.com/Zzz-/p/10619503.html