Explorar el Código

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java
seyason hace 5 años
padre
commit
0c9a05eb5c

BIN
fhKeeper/formulahousekeeper/management-platform/opencv/opencv-420.jar


BIN
fhKeeper/formulahousekeeper/management-platform/opencv/x64/opencv_java420.dll


BIN
fhKeeper/formulahousekeeper/management-platform/opencv/x86/opencv_java420.dll


+ 0 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/UserController.java

@@ -45,8 +45,6 @@ public class UserController {
      */
     @RequestMapping("/loginEmployee")
     public HttpRespMsg loginEmployee(@RequestParam String username, @RequestParam String password) {
-        String property = System.getProperty("java.io.tmpdir");
-        System.out.println("tomcat临时目录==" + property);
         return userService.loginEmployee(username, password);
     }
 

+ 61 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java

@@ -55,6 +55,9 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
 
     @Value(value = "${upload.path}")
     private String path;
+    @Value(value = "${picrecongnize.path}")
+    private static String picrecongnizeFolder;
+
     @Value("classpath:novel_words.data")
     private org.springframework.core.io.Resource novelWords;
     @Autowired
@@ -195,6 +198,21 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                 screenshot.setPicType(7);
             }
         }
+        if (screenshot.getPicType() == null) {
+            //默认设置为查资料
+            try {
+                String browserName = isBrowser(new File(filePath));
+                System.out.println(
+                        "找到浏览器=="+browserName
+                );
+                if (browserName != null) {
+                    screenshot.setPicType(1);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+        }
         //将获取到的截图进行时间计算
         calculateTime(screenshot);
         screenshotMapper.insert(screenshot);
@@ -275,9 +293,19 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
     public static void main(String[] args) {
 //        boolean find = matchCategory("第22 重生");
 //        System.out.println(find);
-        String str = "中文";
-        System.out.println(str.toCharArray().length);
-        isEntertainment(new File("C://Users/seya/Desktop/1.jpg"));
+//        String str = "中文";
+//        System.out.println(str.toCharArray().length);
+//        isEntertainment(new File("C://Users/seya/Desktop/1.jpg"));
+        String browserName = null;
+        try {
+            browserName = isBrowser(new File("C://Users/seya/Desktop/360.jpg"));
+            System.out.println(
+                    "找到浏览器=="+browserName
+            );
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
     }
 
     //娱乐类: 电影+游戏; 画面比较丰富的
@@ -462,4 +490,34 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
             log.info("=====工作时长统计失败 缺少用户或时间数据=====");
         }
     }
+
+    //判断是否是浏览器
+    private static String isBrowser(File pic) throws Exception {
+        if (picrecongnizeFolder == null) {
+            picrecongnizeFolder = "C:\\picrecongnize";
+        }
+        File folder = new File(picrecongnizeFolder);
+        if (!folder.exists()) {
+            throw new Exception("没有设置图片上传的浏览器比对模板库");
+        } else {
+            File[] files = folder.listFiles();
+            String browserName = null;
+            for (File subFolder : files) {
+                File[] targetFile = subFolder.listFiles();
+                int matchCnt = 0;
+                for (File targetPic : targetFile) {
+                    System.out.println("targetPic=="+targetPic.getAbsolutePath());
+                    boolean matchPic = ImageReconizeUtil.isTemplateMatch(pic.getAbsolutePath(), targetPic.getAbsolutePath());
+                    if (matchPic) {
+                        matchCnt++;
+                    }
+                }
+                if (matchCnt >=4) {
+                    browserName = subFolder.getName();
+                    break;
+                }
+            }
+            return browserName;
+        }
+    }
 }

+ 120 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ImageReconizeUtil.java

@@ -0,0 +1,120 @@
+package com.management.platform.util;
+
+import org.opencv.core.*;
+import org.opencv.features2d.DescriptorMatcher;
+import org.opencv.highgui.HighGui;
+import org.opencv.imgcodecs.Imgcodecs;
+import org.opencv.imgproc.Imgproc;
+
+import java.io.File;
+
+import static java.lang.Math.E;
+
+public class ImageReconizeUtil {
+    public static final double YUZHI = Math.pow(0.1, 10);
+    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");
+    }
+
+    public static boolean isTemplateMatch(String sourcePic, String targetPic) {
+        double matchVal = templete(Imgproc.TM_SQDIFF_NORMED, sourcePic, targetPic);
+        if (Math.abs(matchVal) < YUZHI) {
+            System.out.println("找到啦");
+            return true;
+        } else {
+            System.out.println("没匹配上");
+            return false;
+        }
+    }
+
+    /**
+     * OpenCV-4.1.0 模板匹配
+     * <table border="1" cellpadding="8">
+     * <tr><th>输入参数</th><th>参数解释</th></tr>
+     * <tr><td align="left">TM_SQDIFF是平方差匹配、TM_SQDIFF_NORMED是标准平方差匹配</td><td>利用平方差来进行匹配,最好匹配为0.匹配越差,匹配值越大。</td></tr>
+     * <tr><td align="left">TM_CCORR是相关性匹配、TM_CCORR_NORMED是标准相关性匹配</td><td>采用模板和图像间的乘法操作,数越大表示匹配程度较高, 0表示最坏的匹配效果。</td></tr>
+     * <tr><td align="left">TM_CCOEFF是相关性系数匹配、TM_CCOEFF_NORMED是标准相关性系数匹配</td><td>将模版对其均值的相对值与图像对其均值的相关值进行匹配,1表示完美匹配,-1表示糟糕的匹配,0表示没有任何相关性(随机序列)。</td></tr>
+     * <tr><td colspan="2">随着从简单的测量(平方差)到更复杂的测量(相关系数),我们可获得越来越准确的匹配(同时也意味着越来越大的计算代价)。</td></tr>
+     * <tr><td colspan="2">相关性是越接近1越大越好,平方差是越小越好,所以TM_SQDIFF在使用时和其他的是有所区别的。</td></tr>
+     * <tr><td colspan="2">模板匹配结果Mat要是32位的。</td></tr>
+     * </table>
+     * @return: void
+     * @date: 2019年5月7日12:16:55
+     */
+    public static double templete(int method, String sourcePic, String targetPic) {
+        // 1 获取待匹配图片
+        Mat templete=Imgcodecs.imread(sourcePic);
+        //将rgb灰化处理
+        Imgproc.cvtColor(templete, templete,Imgproc.COLOR_BGR2GRAY);
+
+        // 2 获取匹配模板
+        Mat demo=Imgcodecs.imread(targetPic);
+        Imgproc.cvtColor(demo, demo,Imgproc.COLOR_BGR2GRAY);
+
+        Core.MinMaxLocResult mmr = getLocResult(method, templete, demo);
+        // 7 绘制匹配到的结果
+        double x,y;
+        double 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 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;
+            }
+        }
+        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);
+        return matchVal;
+    }
+
+    private static Core.MinMaxLocResult getLocResult(int method, Mat templete, Mat demo) {
+        int width=templete.cols()-demo.cols()+1;
+        int height=templete.rows()-demo.rows()+1;
+        // 3 创建32位模板匹配结果Mat
+        Mat result=new Mat(width,height,CvType.CV_32FC1);
+        // 4 调用 模板匹配函数
+        Imgproc.matchTemplate(templete, demo, result, method);
+        // 5 归一化
+        Core.normalize(result, result,0, 1, Core.NORM_MINMAX, -1, new Mat());
+        // 6 获取模板匹配结果
+        Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
+        return mmr;
+    }
+}

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/application.yml

@@ -81,5 +81,7 @@ mybatis:
 #####配置图片上传路径####
 upload:
   path: C:/upload/
+picrecongnize:
+  path: C:/picrecongnize/
 
 

+ 5 - 1
fhKeeper/formulahousekeeper/mywork/home.cpp

@@ -46,7 +46,11 @@ Home::Home(QWidget *parent) :
   this->setCentralWidget(widget);
 
   setWindowState(Qt::WindowMaximized);//最大化
-  QString str = "http://118.190.47.230:9095/#/login";
+  QSettings *qs = new QSettings("MyManager",QSettings::IniFormat,this);
+  qs->beginGroup("user");
+  QString id = qs->value("id").toString();
+  qDebug() << "id=="<<id<<", phone="<<qs->value("name").toString();
+  QString str = "http://118.190.47.230:9092/#/desktop/" + id;
   loadNavigate(str);
 
 

+ 7 - 0
fhKeeper/formulahousekeeper/mywork/mainwindow.cpp

@@ -13,6 +13,7 @@ MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
 {
+    m_setting = new QSettings("MyManager",QSettings::IniFormat,this);
     ui->setupUi(this);
     connect(ui->loginBtn,SIGNAL(clicked()),this,SLOT(login_in()));
 //    connect(ui->loginBtn, &QAction::triggered, this, &MainWindow::login_in);
@@ -32,6 +33,12 @@ void MainWindow::login_in(void){//登陆
             qDebug()<<"request success==";
             if (json.value("code").toString() == "ok") {
                 myWin->close();
+                QJsonObject obj = json.value("data").toObject();
+                m_setting->beginGroup("user");
+                m_setting->setValue("id", obj.value("id"));
+                m_setting->setValue("name", obj.value("name"));
+                m_setting->setValue("phone", obj.value("phone"));
+                m_setting->endGroup();
                 //enter home page
                 home = new Home();
                 home->show();

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

@@ -22,5 +22,6 @@ public slots:                   //新增
 
 private:
     Ui::MainWindow *ui;
+    QSettings *m_setting;
 };
 #endif // MAINWINDOW_H