尝试刷一下微信跳一跳的分数,做了如下尝试:
猜测如下的request(sessionid是发帖时删的)是设置分数的,我按照如下格式设置分数发request,返回无异常,但是分数没有修改成功。求指导思路。
POST 22aK9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6E0M7q4)9J5k6i4N6W2K9i4S2A6L8W2)9J5k6i4q4I4i4K6u0W2j5$3!0E0i4K6u0r3N6%4S2S2k6$3q4E0k6g2)9J5c8Y4N6^5j5h3N6S2L8h3g2Q4y4h3k6T1L8%4c8@1L8r3g2J5k6i4m8G2M7Y4c8Q4x3U0k6F1j5Y4y4H3i4K6y4n7d9q4c8f1f1q4)9J5c8U0q4Q4x3X3f1I4
charset: utf-8
Accept-Encoding: gzip
referer: 50bK9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6K6k6i4u0$3K9h3y4W2N6$3g2U0K9r3q4@1i4K6u0W2j5$3!0E0i4K6u0r3N6%4R3%4j5K6S2V1y4e0V1K6j5U0u0U0x3$3p5%4y4K6l9K6i4K6u0r3x3#2)9J5c8Y4m8S2k6$3g2Q4x3X3c8X3M7X3q4E0k6g2)9J5k6h3S2@1L8h3H3`.
content-type: application/json
User-Agent: MicroMessenger/6.6.1.1220(0x26060133) NetType/WIFI Language/zh_CN
Content-Length: 400
Host: mp.weixin.qq.com
Connection: Keep-Alive
{
"base_req": {
"session_id": "XXX",
"fast": 1,
"client_info": {
"platform": "android",
"brand": "Xiaomi",
"model": "MI 5s",
"system": "Android 7.0"
}
},
"report_list": [{
"ts": 1514644685,
"type": 1,
"score": 1122,
"best_score": 119,
"break_record": 1,
"duration": 87,
"times": 366
}]
}
2、通过adb模拟点击屏幕进行游戏。
通过颜色区分物体、识别目标,计算距离,模拟触摸。有时候目标很小时识别不了
,差不多到八九百分就挂了
,下面上图。求指导有没有什么好的图像识别算法可以适用本例。
如下是代码,求别喷,写的时候没想给别人看。
package Main;
import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Main {
private double v = 0.7075;
public static void main(String[] args) throws Exception {
File d = new File("./");
File[] ds = d.listFiles();
for (File tmp : ds) {
if (tmp.getName().endsWith("png")) {
tmp.delete();
}
}
Main m = new Main();
while (true) {
try {
m.getImage();
m.load();
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
m.push(10.0);
}
}
}
private void getImage() throws Exception {
Thread.sleep(1200);
Process p = Runtime.getRuntime().exec("adb shell screencap -p /sdcard/1.png");
p.waitFor();
p = Runtime.getRuntime().exec("adb pull /sdcard/1.png .");
p.waitFor();
}
private void push(double time) throws Exception {
String exe = "adb shell input swipe 410 1720 410 1720 " + (int) time;
Runtime.getRuntime().exec(exe);
System.out.println(exe);
Thread.sleep((long) (time + 720));
}
private int index = 0;
private Color b = null;
private String genFileName() {
return "P_" + (index++) + ".png";
}
void mark(Point p, BufferedImage buff) {
for (int y = -10; y < 10; y++) {
for (int x = -10; x < 10; x++) {
buff.setRGB((int) (x + p.getX()), (int) (y + p.getY()), Color.RED.getRGB());
}
}
}
void setBackground(BufferedImage buff) {
b = new Color(buff.getRGB(500, 500));
System.out.println("background RGB:" + b);
}
private void load() throws Exception {
BufferedImage buff = ImageIO.read(new File("./1.png"));
setBackground(buff);
Point t = findTarget(buff), me = findMe(buff);
System.out.println("target:" + t + " me:" + me);
mark(t, buff);
mark(me, buff);
ImageIO.write(buff, "png", new File(genFileName()));
double dis = Math.sqrt(
(me.getX() - t.getX()) * (me.getX() - t.getX()) + (me.getY() - t.getY()) * (me.getY() - t.getY()));
double time = dis / v;
if (dis < 300) {
System.out.println(String.format("distance plus from [%f] to [%f]-------------------", time, time + 100));
time += 50;
}
push(time);
}
private boolean colorSame(int left, int mid, int right) {
return colorSame(left, right) && colorSame(left, mid) && colorSame(mid, right);
}
private boolean colorSame(int left, int right) {
Color l = new Color(left);
Color r = new Color(right);
return Math.abs(l.getRed() - r.getRed()) < 10 && Math.abs(l.getGreen() - r.getGreen()) < 10
&& Math.abs(l.getBlue() - r.getBlue()) < 10;
}
public Point findTarget(BufferedImage buff) {
int width = buff.getWidth();
int step = 75;
for (int y = 500; y < 1743; y++) {
for (int x = 10; x < width - step - 1; x++) {
int left = buff.getRGB(x, y);
int right = buff.getRGB(x + step, y);
int mid = buff.getRGB(x + step / 2, y);
if (colorSame(left, mid, right) && !isBackGround(left) && !isBackGround(right) && !isBackGround(mid)) {
// isBackGround(left);
// isBackGround(left);
return new Point(x + step / 2, y /*+ step * 1 / 2*/);
}
}
}
return null;
}
private boolean isBackGround(int rgb) {
if (b == null) {
int gray = this.gray(rgb);
return gray < 235 && gray > 225;
} else {
Color t = new Color(rgb);
return Math.abs(t.getRed() - b.getRed()) < 20 && Math.abs(t.getGreen() - b.getGreen()) < 20
&& Math.abs(t.getBlue() - b.getBlue()) < 20;
}
}
int gray(int rgb) {
Color c = new Color(rgb);
return (c.getRed() + c.getGreen() + c.getBlue()) / 3;
}
private Point findMe(BufferedImage buff) {
int width = buff.getWidth(), height = buff.getHeight();
for (int y = 700; y < 1743; y++) {
for (int x = 10; x < width - 70 - 1; x++) {
int left = buff.getRGB(x, y);
int right = buff.getRGB(x + 70, y);
if (isMe(left) && isMe(right) && !isBackGround(left) && !isBackGround(right)) {
return new Point(x + 35, y);
}
}
}
return new Point(width, height);
}
private boolean isMe(int rgb) {
Color a = new Color(rgb);
return a.getRed() > 39 && a.getRed() < 60 && a.getGreen() > 39 && a.getGreen() < 60 && a.getBlue() > 70
&& a.getBlue() < 98;
}
}
下图是正常识别,打红点是mark函数做的

下面就识别不了,因为目标面太小。
物块颜色不完全一致。是否有颜色域过滤的算法、或者形状识别的算法呢?
POST 22aK9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6E0M7q4)9J5k6i4N6W2K9i4S2A6L8W2)9J5k6i4q4I4i4K6u0W2j5$3!0E0i4K6u0r3N6%4S2S2k6$3q4E0k6g2)9J5c8Y4N6^5j5h3N6S2L8h3g2Q4y4h3k6T1L8%4c8@1L8r3g2J5k6i4m8G2M7Y4c8Q4x3U0k6F1j5Y4y4H3i4K6y4n7d9q4c8f1f1q4)9J5c8U0q4Q4x3X3f1I4
charset: utf-8
Accept-Encoding: gzip
referer: 50bK9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6K6k6i4u0$3K9h3y4W2N6$3g2U0K9r3q4@1i4K6u0W2j5$3!0E0i4K6u0r3N6%4R3%4j5K6S2V1y4e0V1K6j5U0u0U0x3$3p5%4y4K6l9K6i4K6u0r3x3#2)9J5c8Y4m8S2k6$3g2Q4x3X3c8X3M7X3q4E0k6g2)9J5k6h3S2@1L8h3H3`.
content-type: application/json
User-Agent: MicroMessenger/6.6.1.1220(0x26060133) NetType/WIFI Language/zh_CN
Content-Length: 400
Host: mp.weixin.qq.com
Connection: Keep-Alive
{
"base_req": {
"session_id": "XXX",
"fast": 1,
"client_info": {
"platform": "android",
"brand": "Xiaomi",
"model": "MI 5s",
"system": "Android 7.0"
}
},
"report_list": [{
"ts": 1514644685,
"type": 1,
"score": 1122,
"best_score": 119,
"break_record": 1,
"duration": 87,
"times": 366
}]
}
通过颜色区分物体、识别目标,计算距离,模拟触摸。有时候目标很小时识别不了
,差不多到八九百分就挂了
,下面上图。求指导有没有什么好的图像识别算法可以适用本例。
如下是代码,求别喷,写的时候没想给别人看。
package Main;
import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Main {
private double v = 0.7075;
public static void main(String[] args) throws Exception {
File d = new File("./");
File[] ds = d.listFiles();
for (File tmp : ds) {
if (tmp.getName().endsWith("png")) {
tmp.delete();
}
}
Main m = new Main();
while (true) {
try {
m.getImage();
m.load();
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
m.push(10.0);
}
}
}
private void getImage() throws Exception {
Thread.sleep(1200);
Process p = Runtime.getRuntime().exec("adb shell screencap -p /sdcard/1.png");
p.waitFor();
p = Runtime.getRuntime().exec("adb pull /sdcard/1.png .");
p.waitFor();
}
private void push(double time) throws Exception {
String exe = "adb shell input swipe 410 1720 410 1720 " + (int) time;
Runtime.getRuntime().exec(exe);
System.out.println(exe);
Thread.sleep((long) (time + 720));
}
private int index = 0;
private Color b = null;
private String genFileName() {
return "P_" + (index++) + ".png";
}
void mark(Point p, BufferedImage buff) {
for (int y = -10; y < 10; y++) {
for (int x = -10; x < 10; x++) {
buff.setRGB((int) (x + p.getX()), (int) (y + p.getY()), Color.RED.getRGB());
}
}
}
void setBackground(BufferedImage buff) {
b = new Color(buff.getRGB(500, 500));
System.out.println("background RGB:" + b);
}
private void load() throws Exception {
BufferedImage buff = ImageIO.read(new File("./1.png"));
setBackground(buff);
Point t = findTarget(buff), me = findMe(buff);
System.out.println("target:" + t + " me:" + me);
mark(t, buff);
mark(me, buff);
ImageIO.write(buff, "png", new File(genFileName()));
double dis = Math.sqrt(
(me.getX() - t.getX()) * (me.getX() - t.getX()) + (me.getY() - t.getY()) * (me.getY() - t.getY()));
double time = dis / v;
if (dis < 300) {
System.out.println(String.format("distance plus from [%f] to [%f]-------------------", time, time + 100));
time += 50;
}
push(time);
}
private boolean colorSame(int left, int mid, int right) {
return colorSame(left, right) && colorSame(left, mid) && colorSame(mid, right);
}
private boolean colorSame(int left, int right) {
Color l = new Color(left);
Color r = new Color(right);
return Math.abs(l.getRed() - r.getRed()) < 10 && Math.abs(l.getGreen() - r.getGreen()) < 10
&& Math.abs(l.getBlue() - r.getBlue()) < 10;
}
public Point findTarget(BufferedImage buff) {
int width = buff.getWidth();
int step = 75;
for (int y = 500; y < 1743; y++) {
for (int x = 10; x < width - step - 1; x++) {
int left = buff.getRGB(x, y);
int right = buff.getRGB(x + step, y);
int mid = buff.getRGB(x + step / 2, y);
if (colorSame(left, mid, right) && !isBackGround(left) && !isBackGround(right) && !isBackGround(mid)) {
// isBackGround(left);
// isBackGround(left);
return new Point(x + step / 2, y /*+ step * 1 / 2*/);
}
}
}
return null;
}
private boolean isBackGround(int rgb) {
if (b == null) {
int gray = this.gray(rgb);
return gray < 235 && gray > 225;
} else {
Color t = new Color(rgb);
return Math.abs(t.getRed() - b.getRed()) < 20 && Math.abs(t.getGreen() - b.getGreen()) < 20
&& Math.abs(t.getBlue() - b.getBlue()) < 20;
}
}
int gray(int rgb) {
Color c = new Color(rgb);
return (c.getRed() + c.getGreen() + c.getBlue()) / 3;
}
private Point findMe(BufferedImage buff) {
int width = buff.getWidth(), height = buff.getHeight();
for (int y = 700; y < 1743; y++) {
for (int x = 10; x < width - 70 - 1; x++) {
int left = buff.getRGB(x, y);
int right = buff.getRGB(x + 70, y);
if (isMe(left) && isMe(right) && !isBackGround(left) && !isBackGround(right)) {
return new Point(x + 35, y);
}
}
}
return new Point(width, height);
}
private boolean isMe(int rgb) {
Color a = new Color(rgb);
return a.getRed() > 39 && a.getRed() < 60 && a.getGreen() > 39 && a.getGreen() < 60 && a.getBlue() > 70
&& a.getBlue() < 98;
}
}
下图是正常识别,打红点是mark函数做的

package Main;
import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Main {
private double v = 0.7075;
public static void main(String[] args) throws Exception {
File d = new File("./");
File[] ds = d.listFiles();
for (File tmp : ds) {
if (tmp.getName().endsWith("png")) {
tmp.delete();
}
}
Main m = new Main();
while (true) {
try {
m.getImage();
m.load();
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
m.push(10.0);
}
}
}
private void getImage() throws Exception {
Thread.sleep(1200);
Process p = Runtime.getRuntime().exec("adb shell screencap -p /sdcard/1.png");
p.waitFor();
p = Runtime.getRuntime().exec("adb pull /sdcard/1.png .");
p.waitFor();
}
private void push(double time) throws Exception {
String exe = "adb shell input swipe 410 1720 410 1720 " + (int) time;
Runtime.getRuntime().exec(exe);
System.out.println(exe);
Thread.sleep((long) (time + 720));
}
private int index = 0;
private Color b = null;
private String genFileName() {
return "P_" + (index++) + ".png";
}
void mark(Point p, BufferedImage buff) {
for (int y = -10; y < 10; y++) {
for (int x = -10; x < 10; x++) {
buff.setRGB((int) (x + p.getX()), (int) (y + p.getY()), Color.RED.getRGB());
}
}
}
void setBackground(BufferedImage buff) {
b = new Color(buff.getRGB(500, 500));
System.out.println("background RGB:" + b);
}
private void load() throws Exception {
BufferedImage buff = ImageIO.read(new File("./1.png"));
setBackground(buff);
Point t = findTarget(buff), me = findMe(buff);
System.out.println("target:" + t + " me:" + me);
mark(t, buff);
mark(me, buff);
ImageIO.write(buff, "png", new File(genFileName()));
double dis = Math.sqrt(
(me.getX() - t.getX()) * (me.getX() - t.getX()) + (me.getY() - t.getY()) * (me.getY() - t.getY()));
double time = dis / v;
if (dis < 300) {
System.out.println(String.format("distance plus from [%f] to [%f]-------------------", time, time + 100));
time += 50;
}
push(time);
}
private boolean colorSame(int left, int mid, int right) {
return colorSame(left, right) && colorSame(left, mid) && colorSame(mid, right);
}
private boolean colorSame(int left, int right) {
Color l = new Color(left);
Color r = new Color(right);
return Math.abs(l.getRed() - r.getRed()) < 10 && Math.abs(l.getGreen() - r.getGreen()) < 10
&& Math.abs(l.getBlue() - r.getBlue()) < 10;
}
public Point findTarget(BufferedImage buff) {
int width = buff.getWidth();
int step = 75;
for (int y = 500; y < 1743; y++) {
for (int x = 10; x < width - step - 1; x++) {
int left = buff.getRGB(x, y);
int right = buff.getRGB(x + step, y);
int mid = buff.getRGB(x + step / 2, y);
if (colorSame(left, mid, right) && !isBackGround(left) && !isBackGround(right) && !isBackGround(mid)) {
// isBackGround(left);
// isBackGround(left);
return new Point(x + step / 2, y /*+ step * 1 / 2*/);
}
}
}
return null;
}
private boolean isBackGround(int rgb) {
if (b == null) {
int gray = this.gray(rgb);
return gray < 235 && gray > 225;
} else {
Color t = new Color(rgb);
return Math.abs(t.getRed() - b.getRed()) < 20 && Math.abs(t.getGreen() - b.getGreen()) < 20
&& Math.abs(t.getBlue() - b.getBlue()) < 20;
}
}
int gray(int rgb) {
Color c = new Color(rgb);
return (c.getRed() + c.getGreen() + c.getBlue()) / 3;
}
private Point findMe(BufferedImage buff) {
int width = buff.getWidth(), height = buff.getHeight();
for (int y = 700; y < 1743; y++) {
for (int x = 10; x < width - 70 - 1; x++) {
int left = buff.getRGB(x, y);
int right = buff.getRGB(x + 70, y);
if (isMe(left) && isMe(right) && !isBackGround(left) && !isBackGround(right)) {
return new Point(x + 35, y);
}
}
}
return new Point(width, height);
}
private boolean isMe(int rgb) {
Color a = new Color(rgb);
return a.getRed() > 39 && a.getRed() < 60 && a.getGreen() > 39 && a.getGreen() < 60 && a.getBlue() > 70
&& a.getBlue() < 98;
}
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课