Parcourir la source

修改判断娱乐, 客户端比较图片变化后再请求接口

seyason il y a 5 ans
Parent
commit
a9822297a7

+ 23 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java

@@ -182,7 +182,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         }
         screenshot.setIsHandle(1);
         if (screenshot.getPicType() == null) {
-            //判断是否是游戏
+            //判断是否是娱乐:看电影, 打游戏
             if (isEntertainment(new File(filePath))) {
                 screenshot.setPicType(7);
             }
@@ -286,6 +286,8 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
             //统计出现最多的一个色值,计算所占比重
             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++;
@@ -298,6 +300,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                 }
             }
 
+            Map<Integer, Integer> sMap = new TreeMap<Integer, Integer>();
             int maxCnt = 0;
             int key = 0;
             Set<Map.Entry<Integer, Integer>> entry2 = colorCntMap.entrySet();
@@ -307,7 +310,15 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                     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;
@@ -315,7 +326,17 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
             System.out.println("色值为: " + rgb[0] + ", " + rgb[1]+", "+rgb[2]);
             //计算比例, 应该不低于50%
             int colorPercent = maxCnt * 100 / totalPixl;
-            System.out.println("底色比例=="+colorPercent);
+            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;

+ 54 - 9
fhKeeper/formulahousekeeper/mywork/home.cpp

@@ -31,7 +31,7 @@ Home::Home(QWidget *parent) :
     connect(myTimer,&QTimer::timeout,[this](){
             captureScreen();
     });
-    myTimer->start(10000);
+    myTimer->start(60000);
 
     //set ui data
     webWidget = new QWebEngineView(this);
@@ -64,13 +64,7 @@ Home::Home(QWidget *parent) :
 
   }
   BOOL bMore=::Process32First(hProcessSnap,&pe32);
-//  while(bMore)
-//  {
-//    qDebug()<<"进程名称="<<pe32.szExeFile<<"进程id="<<pe32.th32ProcessID;
 
-//    bMore=::Process32Next(hProcessSnap,&pe32);
-//  }
-//  qDebug()<<"不要忘记清楚掉snapshot";
   ::CloseHandle(hProcessSnap);
 
 }
@@ -131,7 +125,58 @@ BOOL Home::StaticEnumWindowsProc(HWND hwnd, LPARAM lParam)
 void Home::captureScreen() {
     QScreen *screen = QGuiApplication::primaryScreen();
     QString filePathName = "timeManager_screencap.jpg";
-    screen->grabWindow(0).save(filePathName, "jpg"); // 0值为整个电脑屏幕WId
+    QFile oldFile(filePathName);
+    if (oldFile.exists()) {
+        QImage oldImg(filePathName);
+        uchar* data = oldImg.bits();
+        int height = oldImg.height();
+        int width = oldImg.width();
+
+        screen->grabWindow(0).save(filePathName, "jpg"); // 0值为整个电脑屏幕WId
+        //判断图像是否和之前的那个一样
+        QImage curImg = QImage(filePathName);
+
+
+        int curHeight = curImg.height();
+        int curWidth = curImg.width();
+        uchar* curData = curImg.bits();
+        int similarPercent = 0;
+        if (height == curHeight && width == curWidth) {//必须先满足尺寸一致
+            unsigned char r,g,b,curR, curG, curB;
+            int totalPixel = 0;
+            int samePixel = 0;
+            for (int i=0;i<height;i++)
+            {
+                for (int j=0;j<width;j++)
+                {
+                    totalPixel++;
+                    r = *(data+2);
+                    g = *(data+1);
+                    b = *data;
+                    //判断像素点的值, 一致的数量
+                    curR = *(curData+2);
+                    curG = *(curData+1);
+                    curB = *curData;
+                    if (r == curR && g == curG && b == curB) {
+                        samePixel++;
+                    }
+                    data+=4;
+                    curData +=4;
+                }
+            }
+            similarPercent = samePixel *100/totalPixel;
+            qDebug() <<"similar percent = "<<similarPercent<<"%";
+        } else {
+            similarPercent = 0;
+        }
+        if (similarPercent >= 95) {//相似度90%以上,认为是一样的,不要上传
+            qDebug() << "不上传!!!";
+            return;
+        }
+    } else {
+        //直接保存
+        screen->grabWindow(0).save(filePathName, "jpg");
+    }
 
     //start upload file
     QNetworkRequest request;
@@ -158,7 +203,7 @@ void Home::captureScreen() {
     multiPart->append(textPart2);
 
     QString processList = getProcessList();
-    qDebug() << processList ;
+//    qDebug() << processList ;
     QHttpPart textPart3;
     textPart3.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"processList\""));
     textPart3.setBody(processList.toUtf8());

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

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