欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++ OpenCV模擬實(shí)現(xiàn)微信跳一跳

 更新時間:2021年12月17日 14:24:53   作者:大千小熊  
這篇文章主要介紹了使用C++和OpenCV模擬實(shí)現(xiàn)微信跳一跳功能,本文圖文并茂通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

前提精要:

本程序參考了大量的大佬佬的代碼,在此基礎(chǔ)之上,改編而成。而且其實(shí)代碼寫的奇差無比,很容易就掛了。然后呢,這里只是稍微提供一些思路,作為參考,就醬。

本程序依賴adb.exe和opencv425庫。

本程序還有待優(yōu)化,很渣很糟糕~

僅供學(xué)習(xí)交流使用,切勿使用在違規(guī)違法的環(huán)境之中。

實(shí)機(jī)演示Gif:

思路:

獲取小黑人的位置,獲得目標(biāo)方塊的位置,計算兩者的距離,從而計算粗按壓屏幕的時間是多少。

具體實(shí)現(xiàn)1:使用mumu模擬器獲取截圖

使用mumu模擬器,模擬手機(jī)端,然后使用adb調(diào)試工具截圖,保存到本地,然后從OpenCV程序獲取在本地的截圖。

具體實(shí)現(xiàn)2:使用adb工具模擬按壓

當(dāng)計算完距離和時間之后,考慮使用模擬按壓屏幕的方法,控制小人的移動。

具體實(shí)現(xiàn)3:按壓的位置剛好在“再來一次”的按鈕上

這樣就算跳失敗了,只要用戶不停下,那么小程序就會一直的進(jìn)行跳躍。

獲取小黑人的位置:

很簡單,只是使用OpenCV的matchTemplate就可以啦,注意使用“TM_CCORR_NORMED”方法。

獲取終點(diǎn)的位置:

這里使用的是Canny邊緣檢測算法

需要自定義的:

一個文件夾,將圖片,從mumu模擬器,保存到本地的目錄文件夾。和Debug的緩存目錄。

您還可以自定義,程序運(yùn)行的循環(huán)次數(shù):

//最大執(zhí)行次數(shù)
#define MaxRound 100

修改后面的100即可。

還有您的匹配模式圖片位置:

character3.png

完整項(xiàng)目:

項(xiàng)目配置:DebugX64,包含頭文件opencv頭文件,lib選擇為opencv_world425d.dll(好像是這個名字),這個lib一定要有d,因?yàn)槲覀兪荄ebug模式,所以使用這個庫。然后鏈接器的附加輸入,也填入這個選項(xiàng)。

項(xiàng)目依賴:adb、opencv425

下面是完整的項(xiàng)目參考。

項(xiàng)目結(jié)構(gòu)

pch.h

#pragma once
#include <opencv2/opencv.hpp>
#include <iostream>
#include <opencv.hpp>
#include <windows.h>

main.cpp?

//跳一跳作弊程序
//版本 v1.0.2 作者:CSDN陳千里

/*
* 程序使用說明:
* 需要配合mumu模擬器使用,電腦需要安裝adb調(diào)試工具,和opencv庫。
* 程序原理介紹:
* 通過計算兩點(diǎn)之間的距離,估算跳躍的長度,按壓屏幕的時間間隔
*
* 參考論文:
* https://blog.csdn.net/qq_37406130/article/details/79007335
* https://blog.csdn.net/sundy_2004/article/details/7749093
* https://blog.csdn.net/q5222890/article/details/105533233
* https://blog.csdn.net/qq_47342178/article/details/109779840
* adb swip使用:
* https://blog.csdn.net/u010042669/article/details/104066744
* Canny 邊緣檢測:
* https://blog.csdn.net/hensonwells/article/details/112557073
*/


#include "pch.h"
#include <windows.h>
#include <sstream>
using namespace cv;

Mat srcImage;//存放跳一跳的截圖
Mat blackPeopleTem;//黑色小人匹配圖
std::stringstream ssm; //int轉(zhuǎn)string
//最大執(zhí)行次數(shù)
#define MaxRound 100

//由于分辨率的不同,微調(diào)終點(diǎn)的位置
#define Tuning 0.52f

//Debug函數(shù)
void DebugImg(const std::string& fileName, Mat& mat, const Point& point);
void DebugImg(const std::string& fileName, Mat& mat);
//刷新srcImage的信息(截圖)
void refreshSrcImage() {
	system("adb shell screencap -p /sdcard/ScreenCatch.png");
	//您需要自定義的地方,下面的"C:\\adb"
	system("adb pull /sdcard/ScreenCatch.png C:\\adb\\temp");
	srcImage = imread("C:\\adb\\temp\\ScreenCatch.png");
}

//尋找跳一跳黑色小人的位置
Point GetNowPoint(Mat& srcImage, Mat& Tem_img) {
	cv::Mat image_matched;
	matchTemplate(srcImage, Tem_img, image_matched, TM_CCORR_NORMED);// 匹配黑棋子
	double minVal, maxVal;
	Point minLoc, maxLoc, matchLoc;
	DebugImg("黑人匹配圖.png", image_matched);
	minMaxLoc(image_matched, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
	matchLoc = maxLoc; //matchLoc是最佳匹配的區(qū)域左上角點(diǎn)
	//調(diào)試輸出
	DebugImg("1黑人位置.png", srcImage, Point(matchLoc.x + Tem_img.cols, matchLoc.y + Tem_img.rows));
	//DebugImg("1黑人位置.png", srcImage, Point(matchLoc.x + Tem_img.cols * 0.5, matchLoc.y + Tem_img.rows));
	return Point(matchLoc.x, matchLoc.y);
}

//獲得小方塊的目標(biāo)點(diǎn)
Point GetNextPoint(Mat& srcImage) {
	cv::Point point1;
	cv::Point point2;
	cv::GaussianBlur(srcImage, srcImage, cv::Size(5, 5), 0);  //高斯濾波,降低噪聲
	Mat temp, temp2;
	//cv::threshold(srcImage, temp, 0, 255, 8);
	//srcImage = temp;
	Canny(srcImage, temp, 20, 30);      //進(jìn)行邊緣檢測
	temp2 = srcImage;
	srcImage = temp;
	std::vector<std::vector<Point>> contours;
	std::vector<Vec4i> hierarchy;
	findContours(srcImage, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point()); //找到關(guān)鍵的角點(diǎn)
	//遍歷每一個輪廓,把多余的輪廓去掉
	std::vector<std::vector<cv::Point> >::const_iterator it = contours.begin();
	while (it != contours.end()) {
		if (it->size() < 150)
			it = contours.erase(it);
		else
			++it;
	}
	int nYMin = srcImage.rows;
	int nXMin = srcImage.cols;
	int nYMax = 0;
	int nXMax = 0;
	int nIdY = 0;
	for (int i = 0; i < contours.size(); i++) {
		//contours[i]代表的是第i個輪廓,contours[i].size()代表的是第i個輪廓上所有的像素點(diǎn)數(shù)  
		for (int j = 0; j < contours[i].size(); j++) {
			if (contours[i][j].y < nYMin) {
				nYMin = contours[i][j].y;   //找到最低的y值
				point1 = contours[i][j];    //記錄  y值最低點(diǎn)坐標(biāo)
				nIdY = i;                   //記錄哪個區(qū)域內(nèi)的
			}
		}
	}
	int minY = srcImage.cols;
	for (int j = 0; j < contours[nIdY].size(); j++) { //在哪個區(qū)域內(nèi)繼續(xù)變量 找到x最大值
		if (contours[nIdY][j].x > nXMax) {
			nXMax = contours[nIdY][j].x;
		}
	}
	for (int j = 0; j < contours[nIdY].size(); j++) {//找到x中最大值上的最小值
		if (contours[nIdY][j].x == nXMax && contours[nIdY][j].y < minY) {
			point2 = contours[nIdY][j];
			minY = contours[nIdY][j].y;     //記錄X點(diǎn)的最大值
		}
	}
	//調(diào)試輸出
	DebugImg("2目標(biāo)點(diǎn)位置.png", temp2, Point(point1.x, point2.y));
	DebugImg("邊緣圖.png", srcImage, Point(point1.x, point2.y));
	return cv::Point(point1.x, point2.y);       //返回中點(diǎn)坐標(biāo)
}


//計算兩個點(diǎn)的距離
float GetDistance(Point& first_point, Point& next_point) {
	float A = first_point.x - next_point.x;
	float B = first_point.y - (next_point.y + 50);
	float result = pow(pow(A, 2) + pow(B, 2), 0.5);
	if (result > 600) {
		std::cout << "距離探測失誤" << std::endl;
		result = 230;
	}
	return result;
}

//模擬按壓屏幕跳躍
void Jump(float& g_distance) {
	std::cout << "distance:" << g_distance << std::endl;
	int time = std::ceil(g_distance * 4 * Tuning);
	std::string str_Time, str;
	//模擬長按屏幕
	ssm.clear();
	ssm << time;
	ssm >> str_Time;
	str = "adb shell input swipe 461 1203 461 1203 " + str_Time;
	std::cout << str << std::endl;
	system(str.c_str());
}

//主過程
void Process() {
	Point pBlackPeople;
	Point pFinish;
	float dis;
	for (int i = 0; i < MaxRound; i++) {
		refreshSrcImage();
		pBlackPeople = GetNowPoint(srcImage, blackPeopleTem);
		pFinish = GetNextPoint(srcImage);
		dis = GetDistance(pBlackPeople, pFinish);
		Jump(dis);
		Sleep(2000);
	}
}

int main() {
	/*srcImage = imread("C:/adb/Test/1.png");
	blackPeopleTem = imread("C:/adb/Resources/character3.png");
	GetNowPoint(srcImage, blackPeopleTem);*/

	//首先要鏈接端口
	system("adb connect 127.0.0.1:7555");
	refreshSrcImage();
	blackPeopleTem = imread("C:/adb/Resources/character3.png");
	//初始化到此結(jié)束
	Process();

	int x = 280; // 裁剪區(qū)域起始點(diǎn) x坐標(biāo)
	int y = 400; // 裁剪區(qū)域起始點(diǎn) y坐標(biāo)
	int width = 100; // 裁剪區(qū)域?qū)挾?
	int height = 100; // 裁剪區(qū)域高度

	//Rect area(x, y, width, height);
	//Mat guide_roi = srcImage(Rect(x, y, width, height));


	//測試代碼
	//namedWindow("test opencv setup", WINDOW_AUTOSIZE);
	//imshow("test opencv setup", srcImage);
	//waitKey(0);
	return 0;
}

//保存圖片和畫點(diǎn),用于調(diào)試
void DebugImg(const std::string& fileName, Mat& mat, const Point& point) {
	Mat temp = mat;
	//在圖片上面畫點(diǎn)
	circle(temp, point, 5, Scalar(0, 0, 255), -1);
	std::string path = "c:/adb/temp/", sR;
	sR = path + fileName;
	imwrite(sR, temp);
}

void DebugImg(const std::string& fileName, Mat& mat) {
	std::string path = "c:/adb/temp/", sR;
	sR = path + fileName;
	imwrite(sR, mat);
}
 

到此這篇關(guān)于C++ OpenCV模擬實(shí)現(xiàn)微信跳一跳的文章就介紹到這了,更多相關(guān)C++ OpenCV微信跳一跳內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C語言實(shí)現(xiàn)圖書管理系統(tǒng)課程設(shè)計

    C語言實(shí)現(xiàn)圖書管理系統(tǒng)課程設(shè)計

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)圖書管理系統(tǒng)課程設(shè)計,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • C++回溯算法之深度優(yōu)先搜索詳細(xì)介紹

    C++回溯算法之深度優(yōu)先搜索詳細(xì)介紹

    回溯在迷宮搜索中使用很常見,就是這條路走不通,然后返回前一個路口,繼續(xù)下一條路?;厮菟惴ㄕf白了就是窮舉法,下面讓我們一起來看看回溯算法中深度優(yōu)先搜索吧
    2023-01-01
  • C語言淺析指針的使用

    C語言淺析指針的使用

    C語言這門課程在計算機(jī)的基礎(chǔ)教學(xué)中一直占有比較重要的地位,然而要想突破C語言的學(xué)習(xí),對指針的掌握是非常重要的,本文將具體針對指針的基礎(chǔ)做詳盡的介紹
    2022-07-07
  • c語言顏色代碼詳解

    c語言顏色代碼詳解

    在本篇文章里小編給大家整理的是關(guān)于c語言顏色代碼的知識點(diǎn)內(nèi)容,需要的朋友們可以參考下。
    2020-02-02
  • VC小技巧匯總之控件技巧

    VC小技巧匯總之控件技巧

    這篇文章主要介紹了VC小技巧匯總之控件技巧,對于VC的開發(fā)很有借鑒價值,需要的朋友可以參考下
    2014-07-07
  • C語言超詳細(xì)講解函數(shù)棧幀的創(chuàng)建和銷毀

    C語言超詳細(xì)講解函數(shù)棧幀的創(chuàng)建和銷毀

    我們知道c語言中函數(shù)都是被調(diào)用的,main函數(shù)里面能調(diào)用其他函數(shù),其實(shí)main函數(shù)也是被別的函數(shù)調(diào)用的,下面通過本文給大家分享c語言函數(shù)棧幀的創(chuàng)建和銷毀過程,一起看看吧
    2022-05-05
  • OpenGL實(shí)現(xiàn)鼠標(biāo)移動方塊

    OpenGL實(shí)現(xiàn)鼠標(biāo)移動方塊

    這篇文章主要為大家詳細(xì)介紹了OpenGL實(shí)現(xiàn)鼠標(biāo)移動方塊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • C語言從零探索函數(shù)的知識

    C語言從零探索函數(shù)的知識

    函數(shù)是一組一起執(zhí)行一個任務(wù)的語句。每個 C 程序都至少有一個函數(shù),即主函數(shù) main() ,所有簡單的程序都可以定義其他額外的函數(shù),讓我們一起來了解它
    2022-04-04
  • C語言實(shí)現(xiàn)最簡單的剪刀石頭布小游戲示例

    C語言實(shí)現(xiàn)最簡單的剪刀石頭布小游戲示例

    這篇文章主要介紹了C語言實(shí)現(xiàn)最簡單的剪刀石頭布小游戲,涉及C語言數(shù)組、隨機(jī)數(shù)與數(shù)值運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下
    2017-09-09
  • c++ STL容器總結(jié)之:vertor與list的應(yīng)用

    c++ STL容器總結(jié)之:vertor與list的應(yīng)用

    本篇文章對c++中STL容器中的vertor與list的應(yīng)用進(jìn)行了詳細(xì)的分析解釋。需要的朋友參考下
    2013-05-05

最新評論