|
|
@@ -27,6 +27,7 @@ import static org.bytedeco.javacpp.lept.pixRead;
|
|
|
import static org.bytedeco.javacpp.opencv_core.*;
|
|
|
import static org.bytedeco.javacpp.opencv_imgcodecs.imencode;
|
|
|
import static org.bytedeco.javacpp.opencv_imgproc.*;
|
|
|
+import static org.bytedeco.javacpp.opencv_imgproc.bilateralFilter;
|
|
|
import static org.bytedeco.javacpp.opencv_ml.SVM;
|
|
|
import static org.bytedeco.javacpp.tesseract.PSM_SINGLE_LINE;
|
|
|
|
|
|
@@ -54,28 +55,45 @@ public class VideoProcessToolNew {
|
|
|
}
|
|
|
Mat frame = removeBlackBarAndRotate(converterToMat.convert(vFrame));
|
|
|
if (matchGameOver(svm, frame)) {
|
|
|
+ Mat filtered = new Mat();
|
|
|
+ bilateralFilter(frame, filtered, 25, 25 * 2, 25 / 2f);
|
|
|
if (map.get("rank") == null) {
|
|
|
- String rank = extractRank(frame);
|
|
|
+ String rank = extractRank(filtered);
|
|
|
if (StringUtils.isNotEmpty(rank))
|
|
|
map.put("rank", rank);
|
|
|
}
|
|
|
if (map.get("total") == null) {
|
|
|
- String total = extractTotalNum(frame);
|
|
|
+ String total = extractTotalNum(filtered);
|
|
|
if (StringUtils.isNotEmpty(total))
|
|
|
map.put("total", total);
|
|
|
}
|
|
|
if (map.get("参赛时间") == null) {
|
|
|
- Map<String, String> statistics = getStatistics(frame);
|
|
|
+ Map<String, String> statistics = getStatistics(filtered);
|
|
|
if (statistics != null)
|
|
|
map.putAll(statistics);
|
|
|
}
|
|
|
+ filtered.release();
|
|
|
if (map.get("rank") != null
|
|
|
&& map.get("total") != null
|
|
|
- && map.get("参赛时间") != null) {
|
|
|
- imwrite(DateFormatUtils.format(new Date(), "yyyyMMddhhmmss") + RandomStringUtils.randomAlphabetic(4) + ".jpg", frame);
|
|
|
- map.put("image", uploadImage(frame));
|
|
|
- System.out.println(map);
|
|
|
- break;
|
|
|
+ && map.get("参赛时间") != null
|
|
|
+ && map.get("评分") != null) {
|
|
|
+ double score = 0;
|
|
|
+ double total = 0;
|
|
|
+ double rank = 0;
|
|
|
+
|
|
|
+ try {
|
|
|
+ score = Double.parseDouble(map.get("评分"));
|
|
|
+ total = Double.parseDouble(map.get("total"));
|
|
|
+ rank = Double.parseDouble(map.get("rank").replace("第", ""));
|
|
|
+
|
|
|
+ if (score > (total - rank) / total * 100 / 2) {
|
|
|
+ imwrite(DateFormatUtils.format(new Date(), "yyyyMMddhhmmss") + RandomStringUtils.randomAlphabetic(4) + ".jpg", frame);
|
|
|
+ map.put("image", uploadImage(frame));
|
|
|
+ System.out.println(map);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } catch (Exception ignore) {
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
frame.release();
|
|
|
@@ -319,14 +337,22 @@ public class VideoProcessToolNew {
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
Rect[] rects = {
|
|
|
new Rect(0, 0, (int) (filtered.cols() * 0.128), filtered.rows()),
|
|
|
- new Rect((int) (filtered.cols() * 0.128), 0, (int) (filtered.cols() * 0.128), filtered.rows()),
|
|
|
+ // new Rect((int) (filtered.cols() * 0.128), 0, (int) (filtered.cols() * 0.128), filtered.rows()),
|
|
|
new Rect((int) (filtered.cols() * 0.256), 0, (int) (filtered.cols() * 0.162), filtered.rows()),
|
|
|
- new Rect((int) (filtered.cols() * 0.428), 0, (int) (filtered.cols() * 0.114), filtered.rows()),
|
|
|
- new Rect((int) (filtered.cols() * 0.542), 0, (int) (filtered.cols() * 0.1), filtered.rows()),
|
|
|
- new Rect((int) (filtered.cols() * 0.642), 0, (int) (filtered.cols() * 0.1), filtered.rows()),
|
|
|
+ // new Rect((int) (filtered.cols() * 0.428), 0, (int) (filtered.cols() * 0.114), filtered.rows()),
|
|
|
+ // new Rect((int) (filtered.cols() * 0.542), 0, (int) (filtered.cols() * 0.1), filtered.rows()),
|
|
|
+ // new Rect((int) (filtered.cols() * 0.642), 0, (int) (filtered.cols() * 0.1), filtered.rows()),
|
|
|
new Rect((int) (filtered.cols() * 0.742), 0, (int) (filtered.cols() * 0.1), filtered.rows())
|
|
|
};
|
|
|
- String[] names = {"淘汰", "伤害", "参赛时间", "治疗量", "救援", "助攻", "评分"};
|
|
|
+ String[] names = {
|
|
|
+ "淘汰",
|
|
|
+ // "伤害",
|
|
|
+ "参赛时间",
|
|
|
+ // "治疗量",
|
|
|
+ // "救援",
|
|
|
+ // "助攻",
|
|
|
+ "评分"
|
|
|
+ };
|
|
|
int i = 0;
|
|
|
for (Rect rect : rects) {
|
|
|
Mat txtImg = new Mat(filtered, new Range(rect.y(), rect.y() + rect.height()), new Range(rect.x(), rect.x() + rect.width()));
|
|
|
@@ -357,7 +383,14 @@ public class VideoProcessToolNew {
|
|
|
roi.release();
|
|
|
if (Pattern.matches("((^([0-9]+[.][0-9]*))|(^\\d{1,2}))分钟", map.get("参赛时间")) &&
|
|
|
Pattern.matches("((^([0-9]+[.][0-9]*))|(^\\d{1,2}))", map.get("评分"))) {
|
|
|
- return map;
|
|
|
+ try {
|
|
|
+ double score = Double.parseDouble(map.get("评分"));
|
|
|
+ double time = Double.parseDouble(map.get("参赛时间").replace("分钟", ""));
|
|
|
+ if (score >= 0 && score <= 100 && time >= 0 && time <= 45) {
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@@ -385,50 +418,6 @@ public class VideoProcessToolNew {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public Mat rankFilter(Mat src) {
|
|
|
- Mat result = new Mat(src.rows(), src.cols(), CV_8UC1, new Scalar(0));
|
|
|
- Mat hsvImg = new Mat();
|
|
|
- cvtColor(src, hsvImg, COLOR_BGR2HSV);
|
|
|
-
|
|
|
- UByteRawIndexer hsvIndexer = hsvImg.createIndexer();
|
|
|
- UByteRawIndexer resultIndexer = result.createIndexer();
|
|
|
- for (int i = 0; i < src.rows(); i++) {
|
|
|
- for (int j = 0; j < src.cols(); j++) {
|
|
|
- int h = hsvIndexer.get(i, j, 0);
|
|
|
- int s = hsvIndexer.get(i, j, 1);
|
|
|
- int v = hsvIndexer.get(i, j, 2);
|
|
|
- int dh = 0;
|
|
|
- if (h > 26) {
|
|
|
- dh = h - 26;
|
|
|
- } else if (h < 21) {
|
|
|
- dh = 21 - h;
|
|
|
- }
|
|
|
- int ds = 0;
|
|
|
- if (s > 161) {
|
|
|
- ds = s - 161;
|
|
|
- } else if (s < 120) {
|
|
|
- ds = 120 - s;
|
|
|
- }
|
|
|
- int dv = 0;
|
|
|
- if (v > 251) {
|
|
|
- dv = v - 251;
|
|
|
- } else if (v < 238) {
|
|
|
- dv = 238 - v;
|
|
|
- }
|
|
|
- int gray = (int) (255 - Math.min(255, dh * 50)
|
|
|
- - Math.min(255, ds * 3)
|
|
|
- - Math.min(255, dv * 10));
|
|
|
- gray = gray < 0 ? 0 : gray;
|
|
|
- // int gray = (h == 26 && Math.abs(s - S) < 50) ? 255 : 0;
|
|
|
- resultIndexer.put(i, j, gray);
|
|
|
- }
|
|
|
- }
|
|
|
- hsvIndexer.release();
|
|
|
- hsvImg.release();
|
|
|
- resultIndexer.release();
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
public Mat timeFilter(Mat src) {
|
|
|
return bgrFilter(src, 27, 129, 243);
|
|
|
}
|