Browse Source

init

master
diven 2 years ago
parent
commit
b0bd057f47
  1. 34
      open-anpr-client/src/main/java/com/visual/open/anpr/model/LocationPoint.java
  2. 110
      open-anpr-client/src/main/java/com/visual/open/anpr/model/PlateLocation.java
  3. 32
      open-anpr-test/src/main/java/com/visual/open/anpr/exps/PlateRecognitionExample.java
  4. 9
      open-anpr-test/src/main/java/com/visual/open/anpr/utils/DrawImage.java

34
open-anpr-client/src/main/java/com/visual/open/anpr/model/LocationPoint.java

@ -0,0 +1,34 @@
package com.visual.open.anpr.model;
import java.io.Serializable;
public class LocationPoint implements Serializable {
/**坐标X的值**/
private int x;
/**坐标Y的值**/
private int y;
public LocationPoint(){}
public LocationPoint(float x, float y) {
this.x = (int)x;
this.y = (int)y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}

110
open-anpr-client/src/main/java/com/visual/open/anpr/model/PlateLocation.java

@ -3,64 +3,94 @@ package com.visual.open.anpr.model;
import java.io.Serializable;
public class PlateLocation implements Serializable {
/**左上角x坐标**/
private int x;
/**左上角y坐标**/
private int y;
/**宽度**/
private int w;
/**高度**/
private int h;
/**
* 构建坐标
* @param x
* @param y
* @param w
* @param h
* @return
*/
public static PlateLocation build(int x, int y, int w, int h){
return new PlateLocation().setX(x).setY(y).setW(w).setH(h);
/**左上角坐标值**/
private LocationPoint leftTop;
/**右上角坐标**/
private LocationPoint rightTop;
/**右下角坐标**/
private LocationPoint rightBottom;
/**左下角坐标**/
private LocationPoint leftBottom;
public LocationPoint getLeftTop() {
return leftTop;
}
public static PlateLocation build(float x, float y, float w, float h){
return new PlateLocation().setX((int) x).setY((int) y).setW((int) w).setH((int) h);
public void setLeftTop(LocationPoint leftTop) {
this.leftTop = leftTop;
}
public int getX() {
return x;
public LocationPoint getRightTop() {
return rightTop;
}
public PlateLocation setX(int x) {
this.x = x;
return this;
public void setRightTop(LocationPoint rightTop) {
this.rightTop = rightTop;
}
public int getY() {
return y;
public LocationPoint getRightBottom() {
return rightBottom;
}
public PlateLocation setY(int y) {
this.y = y;
return this;
public void setRightBottom(LocationPoint rightBottom) {
this.rightBottom = rightBottom;
}
public int getW() {
return w;
public LocationPoint getLeftBottom() {
return leftBottom;
}
public PlateLocation setW(int w) {
this.w = w;
return this;
public void setLeftBottom(LocationPoint leftBottom) {
this.leftBottom = leftBottom;
}
/**
* x的最小坐标
* @return
*/
public int minX(){
return Math.min(Math.min(Math.min(leftTop.getX(), rightTop.getX()), rightBottom.getX()), leftBottom.getX());
}
public int getH() {
return h;
/**
* y的最小坐标
* @return
*/
public int minY(){
return Math.min(Math.min(Math.min(leftTop.getY(), rightTop.getY()), rightBottom.getY()), leftBottom.getY());
}
public PlateLocation setH(int h) {
this.h = h;
return this;
/**
* x的最大坐标
* @return
*/
public int maxX(){
return Math.max(Math.max(Math.max(leftTop.getX(), rightTop.getX()), rightBottom.getX()), leftBottom.getX());
}
/**
* y的最大坐标
* @return
*/
public int maxY(){
return Math.max(Math.max(Math.max(leftTop.getY(), rightTop.getY()), rightBottom.getY()), leftBottom.getY());
}
/**
* 获取宽度
* @return
*/
public float width(){
return (float) Math.sqrt(Math.pow((rightTop.getX()-leftTop.getX()), 2)+Math.pow((rightTop.getY()-leftTop.getY()), 2));
}
/**
* 获取高度
* @return
*/
public float height(){
return (float) Math.sqrt(Math.pow((rightTop.getX()-rightBottom.getX()), 2)+Math.pow((rightTop.getY()-rightBottom.getY()), 2));
}
}

32
open-anpr-test/src/main/java/com/visual/open/anpr/exps/PlateRecognitionExample.java

@ -37,17 +37,35 @@ public class PlateRecognitionExample {
DrawImage drawImage = DrawImage.build(imageA.getAbsolutePath());
if(response.ok()){
for(RecognitionRep recognitionRep : response.getData()){
//画位置信息
PlateLocation location = recognitionRep.getLocation();
drawImage.drawRect(
new DrawImage.Rect(location.getX(), location.getY(), location.getW(), location.getH()), 2, Color.RED);
drawImage.drawLine(
new DrawImage.Point(location.getLeftTop().getX(), location.getLeftTop().getY()),
new DrawImage.Point(location.getRightTop().getX(), location.getRightTop().getY()),
2, Color.RED
);
drawImage.drawLine(
new DrawImage.Point(location.getRightTop().getX(), location.getRightTop().getY()),
new DrawImage.Point(location.getRightBottom().getX(), location.getRightBottom().getY()),
2, Color.RED
);
drawImage.drawLine(
new DrawImage.Point(location.getRightBottom().getX(), location.getRightBottom().getY()),
new DrawImage.Point(location.getLeftBottom().getX(), location.getLeftBottom().getY()),
2, Color.RED
);
drawImage.drawLine(
new DrawImage.Point(location.getLeftBottom().getX(), location.getLeftBottom().getY()),
new DrawImage.Point(location.getLeftTop().getX(), location.getLeftTop().getY()),
2, Color.RED
);
//画识别信息
RecognitionInfo recognition = recognitionRep.getRecognition();
int fonSize = Float.valueOf(1.4f * location.getW() / recognition.getPlateNo().length()).intValue();
int fonSize = Float.valueOf(1.4f * location.width() / recognition.getPlateNo().length()).intValue();
drawImage.drawText(recognition.getPlateNo(),
new DrawImage.Point(location.getX(), location.getY()-(int)(fonSize*2.2)), fonSize, Color.RED);
new DrawImage.Point(location.minX(), location.minY()-(int)(fonSize*2.2)), fonSize, Color.RED);
drawImage.drawText((recognition.getLayout() == PlateLayout.SINGLE ? "单排" : "双排") + ":" + recognition.getPlateColor().getName(),
new DrawImage.Point(location.getX(), location.getY()-(int)(fonSize*1.2)), fonSize, Color.RED);
new DrawImage.Point(location.minX(), location.minY()-(int)(fonSize*1.2)), fonSize, Color.RED);
}
}
HighGui.imshow("image", drawImage.toMat());

9
open-anpr-test/src/main/java/com/visual/open/anpr/utils/DrawImage.java

@ -1,6 +1,5 @@
package com.visual.open.anpr.utils;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
@ -51,6 +50,14 @@ public class DrawImage {
return this;
}
public DrawImage drawLine(Point point1, Point point2, int lineWidth, Color color){
Graphics2D g = (Graphics2D)image.getGraphics();
g.setColor(color);
g.setStroke(new BasicStroke(lineWidth));
g.drawLine(point1.x, point1.y, point2.x, point2.y);
return this;
}
public DrawImage drawText(String text, Point point, int fontSize, Color color){
Graphics2D g = image.createGraphics();
g.setColor(color);

Loading…
Cancel
Save