Selaa lähdekoodia

娱乐电影识别

seyason 5 vuotta sitten
vanhempi
commit
c9b6968abb

+ 100 - 8
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java

@@ -163,10 +163,10 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         } else if (isDocument(textContents)) {
             screenshot.setPicType(2);//看文档
         } else if (isDevelop(picFile) != null) {//开发
-            screenshot.setPicType(7);
+            screenshot.setPicType(0);
         }
         screenshot.setIsHandle(1);
-        if (screenshot.getPicType() == null) {
+        if (screenshot.getPicType() == null && isEntertainmentColorMode(picFile)) {
             //判断是否是娱乐:看电影, 打游戏
             String uid = screenshotvo.getUid();
             Screenshot preShot = screenshotMapper.selectOne(new QueryWrapper<Screenshot>().eq("uid", uid).orderByDesc("indate").last("limit 1"));
@@ -290,7 +290,8 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
     }
 
     public static void main(String[] args) throws Exception {
-//        isDevelop(new File("C:\\Users\\seya\\Desktop\\3.jpg"));
+//        String b = isDevelop(new File("C:\\Users\\seya\\Desktop\\proj.jpg"));
+//        System.out.println("结果:"+b);
     }
 
     private static boolean isPureColor(BufferedImage img, int colorPixel) {
@@ -396,8 +397,9 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
 
     //判断是否是浏览器
     private String isBrowser(File pic) throws Exception {
-        System.out.println("picrecongnizeFolder=="+browserFolder);
+//        System.out.println("picrecongnizeFolder=="+browserFolder);
         File folder = new File(browserFolder);
+//        File folder = new File("C:/picrecongnize/browser/");
         if (!folder.exists()) {
             throw new Exception("没有设置图片上传的浏览器比对模板库");
         } else {
@@ -441,10 +443,6 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                 System.out.println("targetPic==" + targetPic.getAbsolutePath());
                 boolean matchPic = ImageReconizeUtil.isTemplateMatch(pic.getAbsolutePath(), targetPic.getAbsolutePath());
                 if (matchPic) {
-                    isMatch = true;
-                    break;
-                }
-                if (isMatch) {
                     toolName = targetPic.getName();
                     break;
                 }
@@ -474,4 +472,98 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         }
         return find;
     }
+
+    //娱乐类: 电影+游戏; 画面比较丰富的
+    public static boolean isEntertainmentColorMode(File pic) {
+        try {
+            int[] rgb = new int[3];
+            if (!pic.exists()) {
+                System.err.println("文件不存在" + pic.getAbsolutePath());
+            } else {
+                System.out.println("找到文件"  + pic.getAbsolutePath());
+            }
+            BufferedImage img = ImageIO.read(pic);
+            int width = img.getWidth();
+            int height = img.getHeight();
+            int minx = img.getMinX();
+            int miny = img.getMinY();
+            System.out.println("width=" + width + ",height=" + height + ".");
+            System.out.println("minx=" + minx + ",miniy=" + miny + ".");
+            //统计出现最多的一个色值,计算所占比重
+            int totalPixl = 0;
+            HashMap<Integer, Integer> colorCntMap = new HashMap<Integer, Integer>();
+            for (int i = minx; i < width; i++) {
+                for (int j = miny; j < height; j++) {
+                    totalPixl++;
+                    int pixel = img.getRGB(i, j); // 下面三行代码将一个数字转换为RGB数字
+                    if (colorCntMap.get(pixel) == null) {
+                        colorCntMap.put(pixel, 1);
+                    } else {
+                        colorCntMap.put(pixel, colorCntMap.get(pixel) + 1);
+                    }
+                }
+            }
+
+            Map<Integer, Integer> sMap = new TreeMap<Integer, Integer>();
+            int maxCnt = 0;
+            int key = 0;
+            Set<Map.Entry<Integer, Integer>> entry2 = colorCntMap.entrySet();
+            for (Map.Entry<Integer, Integer> temp : entry2) {
+//                System.out.println("sortedMap:"+temp.getKey()+" 值"+temp.getValue());
+                if (temp.getValue() > maxCnt) {
+                    maxCnt = temp.getValue();
+                    key = temp.getKey();
+                }
+                sMap.put(temp.getValue(), temp.getKey());
+            }
+            sMap = ((TreeMap) sMap).descendingMap();
+            Iterator it = sMap.keySet().iterator();
+            Integer k1 = (Integer) it.next();
+            Integer k2 = (Integer) it.next();
+            Integer color1 = sMap.get(k1);
+            Integer color2 = sMap.get(k2);
+            System.out.println("kkkk==" + k1 + "," + color1 + "," + k2 + "," + color2);
+            System.out.println("最.." + maxCnt + ", key=" + key);
+            rgb[0] = (key & 0xff0000) >> 16;
+            rgb[1] = (key & 0xff00) >> 8;
+            rgb[2] = (key & 0xff);
+            System.out.println("色值为: " + rgb[0] + ", " + rgb[1] + ", " + rgb[2]);
+            //计算比例, 应该不低于50%
+            int colorPercent = maxCnt * 100 / totalPixl;
+            if (colorPercent < 50) {
+                //可能存在2中底色, 大布局的底色和小模块的底色,都算底色。
+                int secPercent = k2 * 100 / totalPixl;
+                rgb[0] = (color2 & 0xff0000) >> 16;
+                rgb[1] = (color2 & 0xff00) >> 8;
+                rgb[2] = (color2 & 0xff);
+                System.out.println("二级底色色值为: " + rgb[0] + ", " + rgb[1] + ", " + rgb[2]);
+                System.out.println("二级底色比例==" + secPercent);
+                colorPercent = (k1 + k2) * 100 / totalPixl;
+            }
+            System.out.println("总底色比例==" + colorPercent);
+            //计算底色是否是连续分布的
+            int windowSize = 50;
+            int pureColorBlockCnt = 0;
+            int totalBlockCnt = 0;
+            for (int i = minx; i < width - windowSize; i += windowSize) {
+                for (int j = miny; j < height - windowSize; j += windowSize) {
+                    totalBlockCnt++;
+                    BufferedImage rect = img.getSubimage(i, j, windowSize, windowSize);
+                    if (isPureColor(rect, key)) {
+                        pureColorBlockCnt++;
+                    }
+                }
+            }
+            log.info("pureColorBlockCnt===" + pureColorBlockCnt);
+            int pureColorBlackPercent = pureColorBlockCnt * 100 / totalBlockCnt;
+            log.info("pureColorBlackPercent===" + pureColorBlackPercent);
+            if (colorPercent < 50 && pureColorBlackPercent < 30) {
+                return true;
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return false;
+    }
 }

+ 4 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ImageCompare.java

@@ -278,7 +278,6 @@ public class ImageCompare {
         System.out.println("hitCount="+hitCount+", percent="+(100*hitCount/allPoints.size())+"%");
         int percent = (100*hitCount/allPoints.size());
 
-
         if (percent > 80) {
             return true;//
         } else {
@@ -287,10 +286,12 @@ public class ImageCompare {
     }
 
     public static void main(String[] args) {
-        String img1 = "C:\\Users\\seya\\Desktop\\m1.jpg";
-        String img2 = "C:\\Users\\seya\\Desktop\\m2.jpg";
+        String img1 = "C:\\Users\\seya\\Desktop\\e.jpg";
+        String img2 = "C:\\Users\\seya\\Desktop\\d.jpg";
         ImageCompare ip = new ImageCompare();
         System.out.println("是电影娱乐吗?"+ip.test(img1, img2));
     }
+
+
 }
 

+ 9 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ImageReconizeUtil.java

@@ -1,6 +1,7 @@
 package com.management.platform.util;
 
 import org.opencv.core.*;
+import org.opencv.highgui.HighGui;
 import org.opencv.imgcodecs.Imgcodecs;
 import org.opencv.imgproc.Imgproc;
 
@@ -10,7 +11,7 @@ import static java.lang.Math.E;
 import static org.opencv.imgproc.Imgproc.*;
 
 public class ImageReconizeUtil {
-    public static final double YUZHI = 5*Math.pow(0.1, 11);
+    public static final double YUZHI = 1*Math.pow(0.1, 11);
     static {
         System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
         //注意程序运行的时候需要在VM option添加该行 指明opencv的dll文件所在路径
@@ -102,8 +103,13 @@ public class ImageReconizeUtil {
 //        }
         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);
+        //我们匹配的图像在左上角,考虑到用户可能拖动窗口,但是不应该偏差很大。 这里增加判断标准:坐标需要处在第一象限。
+        if (x > templete.width()/2 || y > templete.height()) {
+            System.out.println("坐标非第一象限");
+            return 1;
+        }
+//        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);

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

@@ -0,0 +1,89 @@
+server:
+  port: 10010
+  tomcat:
+    uri-encoding: utf-8
+    max-http-form-post-size: -1
+    connection-timeout: 18000000s
+spring:
+  servlet:
+    multipart:
+      # 配置上传文件的大小设置
+      # Single file max size  即单个文件大小
+      max-file-size: 10000MB
+      max-request-size: 10000MB
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://118.190.47.230:3306/man_hour_manager?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+    username: root
+    password: p011430seya1026
+    hikari:
+      maximum-pool-size: 10
+      minimum-idle: 3
+      max-lifetime: 30000
+      connection-test-query: SELECT 1
+    #######redis配置######
+    # redis
+    redis:
+      host: 118.190.47.230
+      port: 6379
+      timeout: 3
+      # password:
+      pool:
+        minIdle: 1
+        maxIdle: 10
+        maxWait: 3
+        maxActive: 8
+    ####全局配置时间返回格式#####
+  jackson:
+    #参数意义:
+    #JsonInclude.Include.ALWAYS       默认
+    #JsonInclude.Include.NON_DEFAULT   属性为默认值不序列化
+    #JsonInclude.Include.NON_EMPTY     属性为 空(””) 或者为 NULL 都不序列化
+    #JsonInclude.Include.NON_NULL      属性为NULL  不序列化
+    default-property-inclusion: ALWAYS
+    time-zone: GMT+8
+    date-format: yyyy-MM-dd HH:mm:ss
+
+##########日志配置
+logging:
+  level:
+    root: info
+    org.mybatis: debug
+    java.sql: debug
+    org.springframework.web: trace
+    #打印sql语句
+    com.management.platform.mapper: debug
+  path: E:/
+##########
+mybatis-plus:
+  #  mapper-locations: classpath:mapper/*/*.xml
+  #  #实体扫描,多个package用逗号或者分号分隔
+  #  typeAliasesPackage: com.hssx.cloudmodel
+  global-config:
+    #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+    id-type: 0
+    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
+    field-strategy: 2
+    db-column-underline: true
+    refresh-mapper:
+    #################插入和更新非null判断
+    db-config:
+      insert-strategy: not_null
+      update-strategy: not_null
+  configuration:
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+######mybstis配置#######
+mybatis:
+  type-aliases-package: com.management.platform.entity
+  mapper-locations: mappers/*Mapper.xml
+#####配置图片上传路径####
+upload:
+  path: E:/staticproject/timesheet/upload/
+picrecongnize:
+  browser: E:/picrecongnize/browser/
+  develop: E:/picrecongnize/develop/
+
+
+
+

+ 2 - 2
fhKeeper/formulahousekeeper/mywork/constants.h

@@ -1,4 +1,4 @@
-#ifndef CONSTANTS_H
+#ifndef CONSTANTS_H
 #define CONSTANTS_H
 
 #define API_ACCEPT "*/*"
@@ -7,5 +7,5 @@
 #define API_SECRET "secrect"
 #define SETTING_ACCOUNT_ID "id"
 #define SETTING_ACCOUNT_TOKEN "token"
-
+//#define SERVER_URL "http://47.100.37.243:10010"
 #endif // CONSTANTS_H

+ 12 - 8
fhKeeper/formulahousekeeper/mywork/home.cpp

@@ -26,12 +26,13 @@ Home::Home(QWidget *parent) :
     ui(new Ui::Home)
 {
     ui->setupUi(this);
+
     myTimer = new QTimer(this);
     //start timer for screen capture
     connect(myTimer,&QTimer::timeout,[this](){
             captureScreen();
     });
-    myTimer->start(10000);
+    myTimer->start(60000);
     setWindowTitle(tr("智能工时管家"));
     //set ui data
     webWidget = new QWebEngineView(this);
@@ -50,7 +51,7 @@ Home::Home(QWidget *parent) :
   qs->beginGroup("user");
   QString id = qs->value("id").toString();
   qDebug() << "id=="<<id<<", phone="<<qs->value("name").toString();
-  QString str = "http://47.100.37.243:9092/#/desktop/" + id;
+  QString str = HOME_PAGE_URL + id;
   loadNavigate(str);
 
 }
@@ -65,12 +66,13 @@ void Home::captureScreen() {
         uchar* data = oldImg.bits();
         int height = oldImg.height();
         int width = oldImg.width();
-
-        screen->grabWindow(0).save(filePathName, "jpg"); // 0值为整个电脑屏幕WId
+        bool result = screen->grabWindow(0).save(filePathName, "jpg"); // 0值为整个电脑屏幕WId
+        if (!result) {
+            QMessageBox msg3(QMessageBox::Information,windowTitle(),"请尝试使用管理员运行程序!",QMessageBox::Ok,this);
+            msg3.exec();
+        }
         //判断图像是否和之前的那个一样
         QImage curImg = QImage(filePathName);
-
-
         int curHeight = curImg.height();
         int curWidth = curImg.width();
         uchar* curData = curImg.bits();
@@ -103,6 +105,8 @@ void Home::captureScreen() {
         } else {
             similarPercent = 0;
         }
+        QString qs = QString::number(similarPercent);
+
         if (similarPercent >= 95) {//相似度90%以上,认为是一样的,不要上传
             qDebug() << "不上传!!!";
             return;
@@ -114,6 +118,7 @@ void Home::captureScreen() {
 
     //start upload file
     QNetworkRequest request;
+
     request.setUrl(QUrl(SERVER_URL + "/imageProcessing/saveAndProcessImage"));
     QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
     QHttpPart imagePart;
@@ -201,13 +206,12 @@ Home::~Home()
 }
 void Home::closeEvent ( QCloseEvent * e )
 {
-    if( QMessageBox::question(this,
+    if(QMessageBox::question(this,
                              tr("退出"),
                              tr("退出软件将无法统计到您的工时,影响绩效,您确定要退出吗?"),
                               QMessageBox::Yes, QMessageBox::No )
                    == QMessageBox::Yes){
         e->accept();//不会将事件传递给组件的父组件
-
         qDebug()<<"ok";
     }
     else

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

@@ -1,13 +1,15 @@
-#ifndef HOME_H
+#ifndef HOME_H
 #define HOME_H
 
 #include <QMainWindow>
 #include <QTimer>
 #include <QtWebEngineWidgets>
+#include "constants.h"
 //#include "Windows.h"
 #define GWL_HWNDPARENT = -8
 #define GCL_HICON = -14
 #define GCL_MENUNAME = -8
+const QString HOME_PAGE_URL = QString("http://47.100.37.243:9092/#/desktop/");
 
 namespace Ui {
 class Home;

+ 3 - 2
fhKeeper/formulahousekeeper/mywork/httpapi.h

@@ -6,8 +6,9 @@
 #include <QPair>
 #include <QJsonObject>
 #include "baseapi.h"
-const QString SERVER_URL = QString("http://127.0.0.1:10010");
-//const QString SERVER_URL = QString("http://47.100.37.243:10010");
+#include "constants.h"
+//const QString SERVER_URL = QString("http://127.0.0.1:10010");
+const QString SERVER_URL = QString("http://47.100.37.243:10010");
 class HttpAPI: public BaseAPI
 {
 public: