|
@@ -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;
|
|
|
+ }
|
|
|
}
|