ソースを参照

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java
seyason 5 年 前
コミット
9aa1a5bf3e

+ 5 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java

@@ -298,7 +298,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
 //        isEntertainment(new File("C://Users/seya/Desktop/1.jpg"));
         String browserName = null;
         try {
-            browserName = isBrowser(new File("C://Users/seya/Desktop/360.jpg"));
+            browserName = isBrowser(new File("C://Users/seya/Desktop/chrome.jpg"));
             System.out.println(
                     "找到浏览器=="+browserName
             );
@@ -506,15 +506,16 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
             String browserName = null;
             for (File subFolder : files) {
                 File[] targetFile = subFolder.listFiles();
-                int matchCnt = 0;
+                boolean isMatch = false;
                 for (File targetPic : targetFile) {
                     System.out.println("targetPic=="+targetPic.getAbsolutePath());
                     boolean matchPic = ImageReconizeUtil.isTemplateMatch(pic.getAbsolutePath(), targetPic.getAbsolutePath());
                     if (matchPic) {
-                        matchCnt++;
+                        isMatch = true;
+                        break;
                     }
                 }
-                if (matchCnt >=4) {
+                if (isMatch) {
                     browserName = subFolder.getName();
                     break;
                 }

+ 38 - 31
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ImageReconizeUtil.java

@@ -11,17 +11,24 @@ import java.io.File;
 import static java.lang.Math.E;
 
 public class ImageReconizeUtil {
-    public static final double YUZHI = Math.pow(0.1, 10);
+    public static final double YUZHI = 5*Math.pow(0.1, 11);
     static {
         System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
         //注意程序运行的时候需要在VM option添加该行 指明opencv的dll文件所在路径
         //-Djava.library.path=$PROJECT_DIR$\opencv\x64
     }
     public static void main(String[] args) {
-//        boolean match = isTemplateMatch("C:\\Users\\seya\\Desktop\\360_2.jpg",
-//                "C:\\picrecongnize\\360Safe\\2.jpg");
-        boolean match = isTemplateMatch("C:\\Users\\seya\\Desktop\\qyt_2.jpg",
-                "C:\\\\picrecongnize\\\\360Safe\\\\2.jpg");
+        boolean match = isTemplateMatch("C:\\Users\\seya\\Desktop\\loading.jpg",
+                "C:\\\\picrecongnize\\\\Chrome\\\\4-125.jpg");
+//        match = isTemplateMatch("C:\\Users\\seya\\Desktop\\chrome_gray.jpg",
+//                "C:\\\\picrecongnize\\\\Chrome\\\\4-125.jpg");
+//        match = isTemplateMatch("C:\\Users\\seya\\Desktop\\chrome_gray.jpg",
+//                "C:\\\\picrecongnize\\\\Chrome\\\\2-125.jpg");
+//        match = isTemplateMatch("C:\\Users\\seya\\Desktop\\chrome_gray.jpg",
+//                "C:\\\\picrecongnize\\\\Chrome\\\\3-125.jpg");
+
+//        boolean match = isTemplateMatch("C:\\Users\\seya\\Desktop\\chrome2.jpg",
+//                "C:\\picrecongnize\\Chrome\\bar125.jpg");
     }
 
     public static boolean isTemplateMatch(String sourcePic, String targetPic) {
@@ -53,11 +60,11 @@ public class ImageReconizeUtil {
         // 1 获取待匹配图片
         Mat templete=Imgcodecs.imread(sourcePic);
         //将rgb灰化处理
-        Imgproc.cvtColor(templete, templete,Imgproc.COLOR_BGR2GRAY);
-
+//        Imgproc.cvtColor(templete, templete,Imgproc.COLOR_BGR2GRAY);
+//
         // 2 获取匹配模板
         Mat demo=Imgcodecs.imread(targetPic);
-        Imgproc.cvtColor(demo, demo,Imgproc.COLOR_BGR2GRAY);
+//        Imgproc.cvtColor(demo, demo,Imgproc.COLOR_BGR2GRAY);
 
         Core.MinMaxLocResult mmr = getLocResult(method, templete, demo);
         // 7 绘制匹配到的结果
@@ -73,34 +80,34 @@ public class ImageReconizeUtil {
             matchVal = mmr.maxVal;
         }
         //if not match , resize the targetPic and try to match again!
-        if (Math.abs(matchVal) > YUZHI) {
-            System.out.println("第一次没匹配上, 尝试125%尺寸再次匹配~~");
-            Mat demoResize = demo.clone();
-            float scale=1.25f;
-            float widthT=demo.width();
-            float heightT=demo.height();
-            Imgproc.resize(demo, demoResize, new Size(widthT*scale,heightT*scale));
-            demo = demoResize;
-            mmr = getLocResult(method, templete, demo);
-            // 7 绘制匹配到的结果
-            matchVal = 0;
-            if (method==Imgproc.TM_SQDIFF_NORMED || method==Imgproc.TM_SQDIFF) {
-                x = mmr.minLoc.x;
-                y = mmr.minLoc.y;
-                matchVal = mmr.minVal;
-            } else {
-                x = mmr.maxLoc.x;
-                y = mmr.maxLoc.y;
-                matchVal = mmr.maxVal;
-            }
-        }
+//        if (Math.abs(matchVal) > YUZHI) {
+//            System.out.println("第一次没匹配上, 尝试125%尺寸再次匹配~~");
+//            Mat demoResize = demo.clone();
+//            float scale=1.25f;
+//            float widthT=demo.width();
+//            float heightT=demo.height();
+//            Imgproc.resize(demo, demoResize, new Size(widthT*scale,heightT*scale));
+//            demo = demoResize;
+//            mmr = getLocResult(method, templete, demo);
+//            // 7 绘制匹配到的结果
+//            matchVal = 0;
+//            if (method==Imgproc.TM_SQDIFF_NORMED || method==Imgproc.TM_SQDIFF) {
+//                x = mmr.minLoc.x;
+//                y = mmr.minLoc.y;
+//                matchVal = mmr.minVal;
+//            } else {
+//                x = mmr.maxLoc.x;
+//                y = mmr.maxLoc.y;
+//                matchVal = mmr.maxVal;
+//            }
+//        }
         System.out.println("匹配度=="+matchVal);
         System.out.println("x="+x+", y=" + y);
         Imgproc.rectangle(templete,new Point(x,y),new Point(x+demo.cols(),y+demo.rows()),new Scalar( 0, 0, 255),2,Imgproc.LINE_AA);
         Imgproc.putText(templete,"Match Success",new Point(x,y),Imgproc.FONT_HERSHEY_SCRIPT_COMPLEX, 1.0, new Scalar(0, 255, 0),1,Imgproc.LINE_AA);
 //        // 8 显示结果
-        HighGui.imshow("模板匹配", templete);
-        HighGui.waitKey(0);
+//        HighGui.imshow("模板匹配", templete);
+//        HighGui.waitKey(0);
         return matchVal;
     }
 

+ 14 - 0
fhKeeper/formulahousekeeper/mywork/home.cpp

@@ -235,3 +235,17 @@ Home::~Home()
 {
     delete ui;
 }
+void Home::closeEvent ( QCloseEvent * e )
+{
+    if( QMessageBox::question(this,
+                             tr("退出"),
+                             tr("Are you sure to quit this application?"),
+                              QMessageBox::Yes, QMessageBox::No )
+                   == QMessageBox::Yes){
+        e->accept();//不会将事件传递给组件的父组件
+
+        qDebug()<<"ok";
+    }
+    else
+      e->ignore();
+}

+ 1 - 0
fhKeeper/formulahousekeeper/mywork/home.h

@@ -20,6 +20,7 @@ class Home : public QMainWindow
 public:
     explicit Home(QWidget *parent = nullptr);
     ~Home();
+    void closeEvent(QCloseEvent *event);
 public slots:
     void captureScreen();
     QString getProcessList();