|
@@ -171,7 +171,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
|
screenshot.setIsHandle(1);
|
|
|
if (screenshot.getPicType() == null) {
|
|
|
//判断是否是游戏
|
|
|
- if (isGame(new File(filePath))) {
|
|
|
+ if (isEntertainment(new File(filePath))) {
|
|
|
screenshot.setPicType(7);
|
|
|
}
|
|
|
}
|
|
@@ -255,10 +255,11 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
|
// System.out.println(find);
|
|
|
String str = "中文";
|
|
|
System.out.println(str.toCharArray().length);
|
|
|
- isGame(new File("C://Users/seya/Desktop/1.jpg"));
|
|
|
+ isEntertainment(new File("C://Users/seya/Desktop/1.jpg"));
|
|
|
}
|
|
|
|
|
|
- public static boolean isGame(File pic) {
|
|
|
+ //娱乐类: 电影+游戏; 画面比较丰富的
|
|
|
+ public static boolean isEntertainment(File pic) {
|
|
|
try {
|
|
|
int[] rgb = new int[3];
|
|
|
BufferedImage img = ImageIO.read(pic);
|
|
@@ -274,32 +275,12 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
|
for (int i = minx; i < width; i++) {
|
|
|
for (int j = miny; j < height; j++) {
|
|
|
totalPixl++;
|
|
|
-// int w=20;
|
|
|
-// int h=20;
|
|
|
-// BufferedImage rect = img.getSubimage(i, j, w, h);
|
|
|
-
|
|
|
int pixel = img.getRGB(i, j); // 下面三行代码将一个数字转换为RGB数字
|
|
|
if (colorCntMap.get(pixel) == null) {
|
|
|
colorCntMap.put(pixel, 1);
|
|
|
} else {
|
|
|
colorCntMap.put(pixel, colorCntMap.get(pixel) + 1);
|
|
|
}
|
|
|
-// rgb[0] = (pixel & 0xff0000) >> 16;
|
|
|
-// rgb[1] = (pixel & 0xff00) >> 8;
|
|
|
-// rgb[2] = (pixel & 0xff);
|
|
|
-// if (rgb[0] != 255 || rgb[1] != 255 || rgb[2] != 255) {
|
|
|
-// //红色判断
|
|
|
-// if (rgb[0]>=200 && rgb[1] <=50 && rgb[2] <= 50) {
|
|
|
-// System.out.println("红色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
|
|
|
-// + rgb[1] + "," + rgb[2] + ")");
|
|
|
-// } else if (rgb[0] <= 50 && rgb[1] >= 200 && rgb[2] <= 50) {
|
|
|
-// System.out.println("绿色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
|
|
|
-// + rgb[1] + "," + rgb[2] + ")");
|
|
|
-// } else if (rgb[0] <= 50 && rgb[1] <= 50 && rgb[2] >= 200) {
|
|
|
-// System.out.println("蓝色i=" + i + ",j=" + j + ":(" + rgb[0] + ","
|
|
|
-// + rgb[1] + "," + rgb[2] + ")");
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -307,7 +288,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
|
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());
|
|
|
+// System.out.println("sortedMap:"+temp.getKey()+" 值"+temp.getValue());
|
|
|
if (temp.getValue() > maxCnt) {
|
|
|
maxCnt = temp.getValue();
|
|
|
key = temp.getKey();
|
|
@@ -321,6 +302,25 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
|
//计算比例, 应该不低于50%
|
|
|
int colorPercent = maxCnt * 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++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("pureColorBlockCnt==="+pureColorBlockCnt);
|
|
|
+ int pureColorBlackPercent = pureColorBlockCnt * 100 / totalBlockCnt;
|
|
|
+ System.out.println("pureColorBlackPercent==="+pureColorBlackPercent);
|
|
|
+ if (colorPercent < 50 && pureColorBlackPercent < 30) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
} catch (IOException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
@@ -328,6 +328,25 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ private static boolean isPureColor(BufferedImage img, int colorPixel) {
|
|
|
+ int with = img.getWidth();
|
|
|
+ int height = img.getHeight();
|
|
|
+ boolean hasDifferent = false;
|
|
|
+ for (int i=0;i<with; i++) {
|
|
|
+ for (int y = 0; y < height; y++) {
|
|
|
+ int pixel = img.getRGB(i, y); // 下面三行代码将一个数字转换为RGB数字
|
|
|
+ if (pixel != colorPixel) {
|
|
|
+ hasDifferent = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hasDifferent) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return !hasDifferent;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 是否全是汉字<br>
|