虹軟產(chǎn)品地址:http://ai.arcsoft.com.cn/product/arcface.html
虹軟ArcFace功能簡介
- 人臉檢測
- 人臉跟蹤
- 人臉屬性檢測(性別、年齡)
- 人臉三維角度檢測
- 人臉對比
示例代碼說明袱吆,其中圖片操作部分用到了javacv芝薇,javacv中針對opencv進行了一些封裝劫拢,可以很好的對圖片進行處理。此處主要用到了opencv的幾個函數(shù)
加載圖片
IplImage img = cvLoadImage("e:/pic/g5.jpg");
格式轉(zhuǎn)換强胰,將IplImage 轉(zhuǎn)為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數(shù)據(jù)熟吏,寫入圖片文件中
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初始化,需要設(shè)置模式是video玄窝,還是image牵寺,配置人臉檢測的角度,engine需要支持的功能 mask恩脂,最大支持的人臉數(shù)量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());
}
//獲取圖片數(shù)據(jù),此處使用javacv中封裝的對應(yīng)opencv的方法完成
IplImage img = cvLoadImage("e:/pic/g5.jpg");
BytePointer bp = img.arrayData();
byte[] imgData = new byte[img.arraySize()];//圖片數(shù)據(jù)
bp.get(imgData);
//獲得engine對應(yīng)的指針
Pointer hEngine = phEngine.getValue();
//當(dāng)前系統(tǒng)版本
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對照片進行處理黎休,將人臉區(qū)域畫出來,保存為一張新圖片
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);
}
}
待做人臉檢測的圖片
程序識別后玉凯,并標(biāo)識出人臉位置后势腮,效果看起來很棒
再找一張人臉特別多的圖片,準(zhǔn)確圈出所有人臉位置
使用已經(jīng)封裝好的SDK進行人臉識別
http://www.reibang.com/p/96636db03792
使用已經(jīng)封裝好的SDK進行人臉識別【人臉特征提取比對】
http://www.reibang.com/p/ab64464571da
虹軟ArcFace 2.0漫仆,java SDK使用捎拯、人臉信息識別(年齡、性別)
http://www.reibang.com/p/cfe90f82be97
需要完整代碼盲厌,加qq:79295735