package cn.hmsoft.ai.face;

import java.io.File;

import cn.hmsoft.ai.idcard.IdCardOcr;
import cn.hmsoft.ai.util.AiParamUtil;

/******************
 * ai 免冠照识别
 *
 */
public abstract class FaceAI {
	private static FaceAI ai = null;

	public static FaceAI instance() {
		if (ai == null) {
			synchronized (IdCardOcr.class) {
				try {
					ai = (FaceAI) Class.forName(AiParamUtil.IdPhotoAIClass).newInstance();
				} catch (Exception e) {
					try {
						ai = FaceNoAI.class.newInstance();
					} catch (Exception ex) {

					}
				}
			}
		}
		return ai;
	}

	public FacePhoto distFace(String idphoto_image_path, String id_card) {
		FacePhoto photo = null;
		try {
			photo = this.distFaceByFile(new File(idphoto_image_path), id_card);
		} catch (Exception e) {

		}
		if (photo == null) {
			photo = new FacePhoto();
			photo.setError_msg("unknow error");
		}
		return photo;
	}

	public FacePhoto distFace(File idphoto_image_file, String id_card) {
		return distFace(idphoto_image_file.getPath(), id_card);
	}

	protected abstract FacePhoto distFaceByFile(File file, String id_card);
}
