From f5f35bc520747e4fb58e980976d675001f7eb5be Mon Sep 17 00:00:00 2001 From: JoeAllen <2494136784@qq.com> Date: Fri, 29 Jul 2022 11:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=A3=80=E6=B5=8B=E5=88=B0?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E7=9A=84=E6=97=B6=E9=97=B4=E5=92=8C=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: JoeAllen <2494136784@qq.com> --- src/main/java/cn/heavenlybook/Main.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/cn/heavenlybook/Main.java b/src/main/java/cn/heavenlybook/Main.java index 9c51fe2..663f403 100644 --- a/src/main/java/cn/heavenlybook/Main.java +++ b/src/main/java/cn/heavenlybook/Main.java @@ -19,13 +19,15 @@ import javax.swing.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.util.Date; +import java.nio.file.Paths; /** * @author ht */ @Log public class Main { + static int i = 0; + public static void main(String[] args) throws IOException, ModelException, TranslateException { // 开启摄像头,获取图像(得到的图像为frame类型,需要转换为mat类型进行检测和识别) OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0); @@ -54,9 +56,13 @@ public class Main { log.info(classifications.toJson()); // 显示视频图像 canvas.showImage(frame); - if (bestItem.getProbability() == 1.0) { - File outPutFile = new File(new Date() + ".png"); + if (bestItem.getProbability() == 1.0 && !"非动物".equals(bestItem.getClassName())) { + File outPutFile = + new File(String.valueOf(Paths.get("src/test/resources/" + i++ + "coffee.png"))); assert buffImg != null; + if (!outPutFile.exists()) { + log.info(String.valueOf(outPutFile.createNewFile())); + } ImageIO.write(buffImg, "png", outPutFile); } }