
5 changed files with 175 additions and 0 deletions
@ -0,0 +1,45 @@ |
|||||
|
package com.visual.open.anpr.core.domain; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
public class ExtParam implements Serializable { |
||||
|
|
||||
|
private float scoreTh; |
||||
|
|
||||
|
private float iouTh; |
||||
|
|
||||
|
private int topK = 5; |
||||
|
|
||||
|
private ExtParam(){} |
||||
|
|
||||
|
public static ExtParam build(){ |
||||
|
return new ExtParam(); |
||||
|
} |
||||
|
|
||||
|
public float getScoreTh() { |
||||
|
return scoreTh; |
||||
|
} |
||||
|
|
||||
|
public ExtParam setScoreTh(float scoreTh) { |
||||
|
this.scoreTh = scoreTh; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public float getIouTh() { |
||||
|
return iouTh; |
||||
|
} |
||||
|
|
||||
|
public ExtParam setIouTh(float iouTh) { |
||||
|
this.iouTh = iouTh; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public int getTopK() { |
||||
|
return topK; |
||||
|
} |
||||
|
|
||||
|
public ExtParam setTopK(int topK) { |
||||
|
this.topK = topK; |
||||
|
return this; |
||||
|
} |
||||
|
} |
@ -0,0 +1,62 @@ |
|||||
|
package com.visual.open.anpr.core.domain; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class PlateImage implements Serializable { |
||||
|
|
||||
|
/**图像数据**/ |
||||
|
public String imageBase64; |
||||
|
/**人脸解析数据**/ |
||||
|
public List<PlateInfo> PlateInfos; |
||||
|
|
||||
|
/** |
||||
|
* 构建函数 |
||||
|
* @param imageBase64 图像数据 |
||||
|
* @param PlateInfos 人脸解析数据 |
||||
|
* @return |
||||
|
*/ |
||||
|
private PlateImage(String imageBase64, List<PlateInfo> PlateInfos) { |
||||
|
this.imageBase64 = imageBase64; |
||||
|
this.PlateInfos = PlateInfos; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 构建对象 |
||||
|
* @param imageBase64 图像数据 |
||||
|
* @param PlateInfos 人脸解析数据 |
||||
|
* @return |
||||
|
*/ |
||||
|
public static PlateImage build(String imageBase64, List<PlateInfo> PlateInfos){ |
||||
|
if(PlateInfos == null){ |
||||
|
PlateInfos = new ArrayList<>(); |
||||
|
} |
||||
|
return new PlateImage(imageBase64, PlateInfos); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 图像数据 |
||||
|
* @return |
||||
|
*/ |
||||
|
public String imageBase64(){ |
||||
|
return this.imageBase64; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取图像数据 |
||||
|
* @return |
||||
|
*/ |
||||
|
public ImageMat imageMat(){ |
||||
|
return ImageMat.fromBase64(this.imageBase64); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取人脸解析数据 |
||||
|
* @return |
||||
|
*/ |
||||
|
public List<PlateInfo> PlateInfos(){ |
||||
|
return this.PlateInfos; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package com.visual.open.anpr.core.extract; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
import com.visual.open.anpr.core.domain.ExtParam; |
||||
|
import com.visual.open.anpr.core.domain.ImageMat; |
||||
|
import com.visual.open.anpr.core.domain.PlateImage; |
||||
|
|
||||
|
public interface PlateExtractor { |
||||
|
|
||||
|
/** |
||||
|
* 人脸特征提取 |
||||
|
* @param image |
||||
|
* @param extParam |
||||
|
* @param params |
||||
|
* @return |
||||
|
*/ |
||||
|
public PlateImage extract(ImageMat image, ExtParam extParam, Map<String, Object> params); |
||||
|
|
||||
|
} |
@ -0,0 +1,42 @@ |
|||||
|
package com.visual.open.anpr.core.extract; |
||||
|
|
||||
|
import com.visual.open.anpr.core.domain.ExtParam; |
||||
|
import com.visual.open.anpr.core.domain.ImageMat; |
||||
|
import com.visual.open.anpr.core.domain.PlateImage; |
||||
|
import com.visual.open.anpr.core.domain.PlateInfo; |
||||
|
import com.visual.open.anpr.core.models.TorchPlateDetection; |
||||
|
import com.visual.open.anpr.core.models.TorchPlateRecognition; |
||||
|
import com.visual.open.anpr.core.utils.CropUtil; |
||||
|
import org.opencv.core.Mat; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public class PlateExtractorImpl implements PlateExtractor { |
||||
|
|
||||
|
private TorchPlateDetection torchPlateDetection; |
||||
|
private TorchPlateRecognition torchPlateRecognition; |
||||
|
|
||||
|
public PlateExtractorImpl(TorchPlateDetection torchPlateDetection, TorchPlateRecognition torchPlateRecognition) { |
||||
|
this.torchPlateDetection = torchPlateDetection; |
||||
|
this.torchPlateRecognition = torchPlateRecognition; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public PlateImage extract(ImageMat image, ExtParam extParam, Map<String, Object> params) { |
||||
|
List<PlateInfo> plateInfos = torchPlateDetection.inference(image, extParam.getScoreTh(),extParam.getIouTh(), new HashMap<>()); |
||||
|
//取人脸topK
|
||||
|
int topK = (extParam.getTopK() > 0) ? extParam.getTopK() : 5; |
||||
|
if(plateInfos.size() > topK){ |
||||
|
plateInfos = plateInfos.subList(0, topK); |
||||
|
} |
||||
|
//解析车牌信息
|
||||
|
for(PlateInfo plateInfo : plateInfos){ |
||||
|
Mat crop = CropUtil.crop(image.toCvMat(), plateInfo.box); |
||||
|
plateInfo.parseInfo = torchPlateRecognition.inference(ImageMat.fromCVMat(crop), plateInfo.single, new HashMap<>()); |
||||
|
} |
||||
|
//返回数据
|
||||
|
return PlateImage.build(image.toBase64AndNoReleaseMat(), plateInfos); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue