|
|
@@ -39,88 +39,7 @@ public class VideoProcessToolNew {
|
|
|
private OSSFileService ossFileService = new OSSFileService();
|
|
|
public String imgPrefix = "/tmp/";
|
|
|
|
|
|
- public Map<String, String> processVideo(String path, int frameSkip) throws FrameGrabber.Exception {
|
|
|
- SVM svm = SVM.load(GetResource.class.getClassLoader().getResource("trainneddata/pubg.xml").getPath());
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- OpenCVFrameConverter.ToMat converterToMat = new OpenCVFrameConverter.ToMat();
|
|
|
- long frameCount = 0;
|
|
|
- FrameGrabber videoGrabber = new FFmpegFrameGrabber(path);
|
|
|
- videoGrabber.start();
|
|
|
- System.out.println(videoGrabber.getLengthInFrames());
|
|
|
- System.out.println(videoGrabber.getLengthInTime());
|
|
|
- videoGrabber.setTimestamp(62500000L);
|
|
|
- Frame vFrame;
|
|
|
- do {
|
|
|
- vFrame = videoGrabber.grabFrame();
|
|
|
- if (vFrame != null) {
|
|
|
- frameCount++;
|
|
|
- if (!vFrame.keyFrame) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- System.out.println(vFrame.timestamp);
|
|
|
- if (frameCount % 200 == 0) {
|
|
|
- System.gc();
|
|
|
- }
|
|
|
- if (frameSkip > 0 && frameCount % frameSkip != 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- 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) {
|
|
|
- Integer rank = extractRank(filtered);
|
|
|
- if (rank != null)
|
|
|
- map.put("rank", rank.toString());
|
|
|
- }
|
|
|
- if (map.get("total") == null) {
|
|
|
- Integer total = extractTotalNum(filtered);
|
|
|
- if (total != null)
|
|
|
- map.put("total", total.toString());
|
|
|
- }
|
|
|
- if (map.get("参赛时间") == null) {
|
|
|
- Map<String, Double> statistics = getStatistics(filtered);
|
|
|
- if (statistics != null) {
|
|
|
- statistics.forEach((s, aDouble) -> map.put(s, aDouble.toString()));
|
|
|
- }
|
|
|
- }
|
|
|
- filtered.release();
|
|
|
- if (map.get("rank") != null
|
|
|
- && map.get("total") != null
|
|
|
- && 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) {
|
|
|
- String filename = "/var/samples/" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + RandomStringUtils.randomNumeric(8) + ".jpg";
|
|
|
- org.bytedeco.javacpp.opencv_imgcodecs.imwrite(filename, frame);
|
|
|
- map.put("image", uploadImage(frame));
|
|
|
- System.out.println(map);
|
|
|
- break;
|
|
|
- }
|
|
|
- } catch (Exception ignore) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- frame.release();
|
|
|
- System.out.println(frameCount + " frame processed");
|
|
|
- }
|
|
|
- } while (vFrame != null);
|
|
|
- videoGrabber.stop();
|
|
|
- videoGrabber.release();
|
|
|
- svm.deallocate();
|
|
|
- System.gc();
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- public VideoProcessResult processVideo1(String path, int frameSkip) throws FrameGrabber.Exception {
|
|
|
+ public VideoProcessResult processVideo(String path, int frameSkip) throws FrameGrabber.Exception {
|
|
|
SVM svm = SVM.load(GetResource.class.getClassLoader().getResource("trainneddata/pubg.xml").getPath());
|
|
|
VideoProcessResult result = new VideoProcessResult();
|
|
|
OpenCVFrameConverter.ToMat converterToMat = new OpenCVFrameConverter.ToMat();
|
|
|
@@ -199,6 +118,58 @@ public class VideoProcessToolNew {
|
|
|
return result.isValid() ? result : null;
|
|
|
}
|
|
|
|
|
|
+ public VideoProcessResult getKill3Time(String path, int frameSkip) throws FrameGrabber.Exception {
|
|
|
+ SVM svm = SVM.load(GetResource.class.getClassLoader().getResource("trainneddata/pubg.xml").getPath());
|
|
|
+ VideoProcessResult result = new VideoProcessResult();
|
|
|
+ OpenCVFrameConverter.ToMat converterToMat = new OpenCVFrameConverter.ToMat();
|
|
|
+ long frameCount = 0;
|
|
|
+ FrameGrabber videoGrabber = new FFmpegFrameGrabber(path);
|
|
|
+ videoGrabber.start();
|
|
|
+ Frame vFrame;
|
|
|
+ List<long[]> slices = toSlices(videoGrabber.getLengthInTime());
|
|
|
+ for (long[] slice : slices) {
|
|
|
+ long start = slice[0];
|
|
|
+ long end = slice[1];
|
|
|
+ long ts = start;
|
|
|
+ videoGrabber.setTimestamp(start);
|
|
|
+ while (ts <= end) {
|
|
|
+ vFrame = videoGrabber.grabFrame();
|
|
|
+ if (vFrame != null) {
|
|
|
+ ts = vFrame.timestamp;
|
|
|
+ frameCount++;
|
|
|
+ if (frameCount % 200 == 0) {
|
|
|
+ System.gc();
|
|
|
+ }
|
|
|
+ if (frameSkip > 0 && frameCount % frameSkip != 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Mat frame = removeBlackBarAndRotate(converterToMat.convert(vFrame));
|
|
|
+ Mat filtered = new Mat();
|
|
|
+ bilateralFilter(frame, filtered, 25, 25 * 2, 25 / 2f);
|
|
|
+ if (getKillNum(filtered) >= 3) {
|
|
|
+ String filename = "/var/samples/" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + RandomStringUtils.randomNumeric(8) + ".jpg";
|
|
|
+ org.bytedeco.javacpp.opencv_imgcodecs.imwrite(filename, frame);
|
|
|
+ result.setImage(uploadImage(frame));
|
|
|
+ result.setKill3time(ts);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ frame.release();
|
|
|
+ System.out.println(frameCount + " frame processed");
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (result.getKill3time() != null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ videoGrabber.stop();
|
|
|
+ videoGrabber.release();
|
|
|
+ svm.deallocate();
|
|
|
+ System.gc();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
private List<long[]> toSlices(Long total) {
|
|
|
List<long[]> list = new ArrayList<>();
|
|
|
long end = total;
|