normalized matcher

This commit is contained in:
mrbesen 2022-03-06 01:08:32 +01:00
parent 84795aa725
commit 8b3177ce67
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
5 changed files with 17 additions and 24 deletions

View File

@ -51,10 +51,10 @@ public:
}
constexpr double getXScale() const {
return wattrib.width / DEFAULTWIDTH;
return wattrib.width / (double) DEFAULTWIDTH;
}
constexpr double getYScale() const {
return wattrib.height / DEFAULTHEIGHT;
return wattrib.height / (double) DEFAULTHEIGHT;
}
};

View File

@ -63,7 +63,7 @@ void LolAutoAccept::checkForGame() {
void LolAutoAccept::performClick(uint32_t nr) {
inputs.setOffset(screen->getXOffset(), screen->getYOffset());
inputs.setScale(1 / screen->getXScale(), 1 / screen->getYScale());
inputs.setScale(screen->getXScale(), screen->getYScale());
auto p = inputs.get(nr);
Log::info << "click " << nr << " @ " << p.x << " " << p.y;
@ -94,6 +94,7 @@ void LolAutoAccept::pickFirst(const std::string& search) {
}
LolAutoAccept::LolAutoAccept() : acceptmatcher("imgs/Accept.png"), arrowmatcher("imgs/arrowdown.png"), sim(XInputSimulator::getInstance()) {
// click positions in 1280x720 scale
inputs.addPoint({645, 560}); // accept game
inputs.addPoint({775, 105}); // search box
inputs.addPoint({180, 160}); // first champ
@ -109,6 +110,9 @@ void LolAutoAccept::run() {
screen = (wins.at(0)); // just take the first
// testing: whole screen:
// screen = new ScreenShot();
//delete other screens
for(uint32_t i = 1; i < wins.size(); ++i) {
ScreenShot* ss = wins.at(i);

View File

@ -12,19 +12,6 @@ int main(int argc, const char** argv) {
Log::info << "Hello, World!";
Matcher test1("imgs/arrowdown.png");
Matcher test2("imgs/blitzcranktest.png");
auto testimg = cv::imread("imgs/Bildschirmfoto vom 2022-02-28 19-27-59.png");
auto testimg2 = cv::imread("imgs/Bildschirmfoto vom 2022-02-28 19-27-44.png");
test1.match(testimg);
test2.match(testimg);
test1.match(testimg2);
test2.match(testimg2);
return 0;
LolAutoAccept lolaa;
lolaa.run();

View File

@ -19,6 +19,7 @@ bool Matcher::Match::operator!=(const Match& other) const {
}
// https://stackoverflow.com/a/43133263/4399859
Matcher::Match Matcher::match(const cv::Mat& img) {
// create out mat
int result_cols = img.cols - templ.cols + 1;
@ -30,19 +31,15 @@ Matcher::Match Matcher::match(const cv::Mat& img) {
cv::cvtColor(img, converted, cv::COLOR_RGBA2RGB);
// match
cv::matchTemplate(converted, templ, out, cv::TM_SQDIFF);
double minValbn; double maxValbn;
cv::minMaxLoc( out, &minValbn, &maxValbn, NULL, NULL, cv::Mat() );
cv::normalize(out, out, 0, 1, cv::NORM_MINMAX, -1, cv::Mat());
cv::matchTemplate(converted, templ, out, cv::TM_CCORR_NORMED);
double minVal; double maxVal;
cv::Point minLoc; cv::Point maxLoc;
cv::minMaxLoc( out, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat() );
Log::debug << "pixelcount: " << (templ.cols * templ.rows) << " minValbn: " << minValbn << " maxValbn: " << maxValbn << " minVal: " << minVal << " maxVal: " << maxVal << " minLoc: " << minLoc.x << " " << minLoc.y << " maxLoc: " << maxLoc.x << " " << maxLoc.y;
Log::debug << "pixelcount: " << (templ.cols * templ.rows) << /* " minValbn: " << minValbn << " maxValbn: " << maxValbn << */ " minVal: " << minVal << " maxVal: " << maxVal << " minLoc: " << minLoc.x << " " << minLoc.y << " maxLoc: " << maxLoc.x << " " << maxLoc.y;
bool matched = minValbn < 2e7;
bool matched = maxVal > 0.95;
return {matched, minLoc.x, minLoc.y, templ.cols, templ.rows};
return {matched, maxLoc.x, maxLoc.y, templ.cols, templ.rows};
}

View File

@ -1,5 +1,7 @@
#include "scaleableinputs.h"
#include <Log.h>
void ScaleableInputs::addPoint(Point p) {
points.push_back(p);
}
@ -16,5 +18,8 @@ void ScaleableInputs::setOffset(double x, double y) {
ScaleableInputs::Point ScaleableInputs::get(uint32_t nr) const {
Point p = points.at(nr);
Log::debug << "scaling: " << p.x << " " << p.y << " with: " << xOffset << " " << yOffset << " scale: " << xScale << " " << yScale;
return {(uint32_t) ((p.x * xScale) + xOffset), (uint32_t) ((p.y * yScale) + yOffset)};
}