Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java
Reiskuchen 5 gadi atpakaļ
vecāks
revīzija
85cbb221f6

+ 4 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ImageProcessingController.java

@@ -33,6 +33,10 @@ public class ImageProcessingController {
         return screenshotService.saveAndProcessImage(screenshotvo);
     }
 
+    @RequestMapping("/reTestPic")
+    public HttpRespMsg reTestPic(Integer id) {
+        return screenshotService.reTestPicMatch(id);
+    }
     /**
      * 初始化redis图片搜索的关键词,
      * 防止数据库初始添加了其他字段导致redis里的数据不是最新的,

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ScreenshotService.java

@@ -22,5 +22,7 @@ public interface ScreenshotService extends IService<Screenshot> {
 
     HttpRespMsg saveAndProcessImage(ScreenshotVO screenshotvo);
 
+    HttpRespMsg reTestPicMatch(int id);
+
     HttpRespMsg updateRedisPicContentKeywords();
 }

+ 37 - 15
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java

@@ -255,7 +255,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
     @Override
     public HttpRespMsg saveAndProcessImage(ScreenshotVO screenshotvo) {
         Map<String, Object> fileMap = UploadFileToFileNameUtil.uploadFile(screenshotvo.getFile(), path);
-        String filePath = (String) fileMap.get("sqlFilePath");
+        String filePath = (String)fileMap.get("sqlFilePath");
         Screenshot screenshot = new Screenshot();
         BeanUtils.copyProperties(screenshotvo, screenshot);
         screenshot.setPicUrl(filePath);
@@ -291,7 +291,8 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
 //            //由于存入数据库的对象被序列化成了json字符串,所以从redis里拿方便
 //            members = redisUtil.members(Constant.COMMON_SOFTWARE_KEYWORDS);
 //        }
-        File picFile = new File((String) fileMap.get("newFile"));
+        File picFile = new File((String)fileMap.get("newFile"));
+        System.out.println("File:"+picFile.getAbsolutePath());
         if (isNovel(textContents)) {
             screenshot.setPicType(6);
         } else if (isDocument(textContents)) {
@@ -309,7 +310,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                 File f = new File(prePath);
                 if (f.exists()) {
                     ImageCompare comp = new ImageCompare();
-                    if (comp.isMoviePlay((String) fileMap.get("newFile"), prePath)) {
+                    if (comp.isMoviePlay((String)fileMap.get("newFile"), prePath)) {
                         screenshot.setPicType(7);
                         //前面那条也更新
                         if (preShot.getPicType() != null && preShot.getPicType() != 7) {
@@ -323,10 +324,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         if (screenshot.getPicType() == null) {
             //默认设置为查资料
             try {
-                String browserName = isBrowser(new File((String) fileMap.get("newFile")));
-                System.out.println(
-                        "找到浏览器==" + browserName
-                );
+                String browserName = isBrowser(picFile);
                 if (browserName != null) {
                     screenshot.setPicType(1);
                 }
@@ -341,11 +339,34 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         return new HttpRespMsg();
     }
 
+    @Override
+    public HttpRespMsg reTestPicMatch(int id) {
+        Screenshot item = screenshotMapper.selectById(id);
+        String fileName = item.getPicUrl().replaceAll("/upload/", "");
+        String filePath = path + fileName;
+        File pic = new File(filePath);
+        String devName = isDevelop(pic);
+        HttpRespMsg msg = new HttpRespMsg();
+        if(devName != null) {
+            msg.data = devName;
+        } else {
+            try {
+                String browserName = isBrowser(pic);
+                if (browserName != null) {
+                    msg.data = browserName;
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return msg;
+    }
+
     @Override
     public HttpRespMsg updateRedisPicContentKeywords() {
         List<PicContentKeywords> picContentKeywords = picContentKeywordsMapper.selectList(null);
-        for (PicContentKeywords keyWord : picContentKeywords) {
-            redisUtil.sSetJsonString("keyWords", keyWord);
+        for (PicContentKeywords  keyWord : picContentKeywords) {
+            redisUtil.sSetJsonString("keyWords",keyWord);
         }
         HttpRespMsg msg = new HttpRespMsg();
         msg.data = redisUtil.members("keyWords");
@@ -427,6 +448,8 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
 //        System.out.println("结果:"+b);
     }
 
+
+
     private static boolean isPureColor(BufferedImage img, int colorPixel) {
         int with = img.getWidth();
         int height = img.getHeight();
@@ -476,7 +499,6 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                 File[] targetFile = subFolder.listFiles();
                 boolean isMatch = false;
                 for (File targetPic : targetFile) {
-//                    System.out.println("targetPic==" + targetPic.getAbsolutePath());
                     boolean matchPic = ImageReconizeUtil.isTemplateMatch(pic.getAbsolutePath(), targetPic.getAbsolutePath());
                     if (matchPic) {
                         isMatch = true;
@@ -529,11 +551,11 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         boolean find = false;
         for (int i = 0; i < textContents.size() && i <= 2; i++) {//出现在前三行
             String text = textContents.get(i).trim();
-            if (text.endsWith("Word")
-                    || text.endsWith("Excel")
-                    || text.endsWith("Ecel")
-                    || text.endsWith("Power Point")
-                    || text.endsWith("Adobe Reader")) {
+            if (text.contains("Word")
+                    || text.contains("Excel")
+                    || text.contains("Ecel")
+                    || text.contains("Power Point")
+                    || text.contains("Adobe Reader")) {
                 find = true;
                 break;
             }

+ 13 - 29
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ImageReconizeUtil.java

@@ -5,21 +5,24 @@ import org.opencv.highgui.HighGui;
 import org.opencv.imgcodecs.Imgcodecs;
 import org.opencv.imgproc.Imgproc;
 
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
 import java.io.File;
+import java.io.IOException;
 
 import static java.lang.Math.E;
 import static org.opencv.imgproc.Imgproc.*;
 
 public class ImageReconizeUtil {
-    public static final double YUZHI = 1*Math.pow(0.1, 10);
+    public static final double YUZHI = 2*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:\\upload\\c6889ab6dea949a8a8d5d89fb677a421.jpg",
-                "C:\\picrecongnize\\browser\\360\\2.jpg");
+        boolean match = isTemplateMatch("C:\\Users\\seya\\Desktop\\my.jpg",
+                "C:\\picrecongnize\\develop\\idea_black.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",
@@ -58,7 +61,13 @@ public class ImageReconizeUtil {
      */
     public static double templete(int method, String sourcePic, String targetPic) {
         // 1 获取待匹配图片
+//        System.out.println("sourcePic="+sourcePic+", targetPic="+targetPic);
         Mat templete=Imgcodecs.imread(sourcePic);
+        //先裁减,左上角1/4的截图,提高比对速度。
+        Rect rect = new Rect(0,0,templete.width()/4, templete.height()/4);
+        Mat subMat = new Mat(templete, rect);
+        subMat.copyTo(templete);
+
         //将rgb灰化处理
 //        Imgproc.cvtColor(templete, templete,Imgproc.COLOR_BGR2GRAY);
 //
@@ -79,35 +88,10 @@ public class ImageReconizeUtil {
             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);
         //我们匹配的图像在左上角,考虑到用户可能拖动窗口,但是不应该偏差很大。 这里增加判断标准:坐标处在左上方。
-        if (x > templete.width()/4 || y > templete.height()/4) {
-            System.out.println("坐标非第一象限");
-            return 1;
-        }
 
 //        if (Math.abs(matchVal) < YUZHI) {
 //            Imgproc.rectangle(templete,new Point(x,y),new Point(x+demo.cols(),y+demo.rows()),new Scalar( 0, 0, 255),2,Imgproc.LINE_AA);