matcher uses alpha channel as mask
BIN
imgs/Accept.png
Before Width: | Height: | Size: 13 KiB |
BIN
imgs/accept.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 894 B After Width: | Height: | Size: 380 B |
BIN
imgs/ban.png
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 1.7 KiB |
BIN
imgs/pick.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
|
@ -5,6 +5,7 @@
|
|||
class Matcher {
|
||||
private:
|
||||
cv::Mat templ;
|
||||
cv::Mat mask;
|
||||
int32_t posx = -1;
|
||||
int32_t posy = -1;
|
||||
|
||||
|
@ -31,4 +32,7 @@ public:
|
|||
private:
|
||||
Match matchAll(const cv::Mat& img);
|
||||
Match matchPos(const cv::Mat& img);
|
||||
|
||||
// when the template has a alpha channel try to create a mask from that
|
||||
void maskFromTemplate();
|
||||
};
|
|
@ -171,7 +171,7 @@ void LolAutoAccept::innerRun() {
|
|||
cv::resize(img, img, cv::Size(ScreenShot::DEFAULTWIDTH, ScreenShot::DEFAULTHEIGHT));
|
||||
|
||||
for(size_t i = 0; i < stages.size(); ++i) {
|
||||
Log::trace << "processing stage" << i;
|
||||
// Log::trace << "processing stage " << i;
|
||||
Stage* stage = stages.at(i);
|
||||
if(stage->process(*this, img)) {
|
||||
Log::debug << "stage successful: " << i;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "lolautoaccept.h"
|
||||
|
||||
LolAutoAccept::AcceptStage::AcceptStage() : Stage("imgs/Accept.png") {
|
||||
LolAutoAccept::AcceptStage::AcceptStage() : Stage("imgs/accept.png") {
|
||||
matcher.setOffset(539, 529);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
#include "util.h"
|
||||
|
||||
Matcher::Matcher(const std::string& filename) {
|
||||
templ = cv::imread(filename, cv::IMREAD_COLOR);
|
||||
templ = cv::imread(filename, cv::IMREAD_UNCHANGED); // unchanged so alpha channel does not get dropped
|
||||
maskFromTemplate();
|
||||
}
|
||||
Matcher::Matcher(const cv::Mat& templ) {
|
||||
templ.copyTo(this->templ);
|
||||
maskFromTemplate();
|
||||
}
|
||||
Matcher::~Matcher() {}
|
||||
|
||||
|
@ -47,7 +49,7 @@ Matcher::Match Matcher::matchAll(const cv::Mat& img) {
|
|||
Log::info << "match size: " << result_cols << " " << result_cols;
|
||||
|
||||
// match
|
||||
cv::matchTemplate(img, templ, out, cv::TM_CCORR_NORMED);
|
||||
cv::matchTemplate(img, templ, out, cv::TM_CCORR_NORMED, mask);
|
||||
|
||||
double minVal; double maxVal;
|
||||
cv::Point minLoc; cv::Point maxLoc;
|
||||
|
@ -67,7 +69,7 @@ Matcher::Match Matcher::matchPos(const cv::Mat& img) {
|
|||
cv::Mat out(1, 1, CV_32FC1);
|
||||
|
||||
// match
|
||||
cv::matchTemplate(matchpart, templ, out, cv::TM_CCORR_NORMED);
|
||||
cv::matchTemplate(matchpart, templ, out, cv::TM_CCORR_NORMED, mask);
|
||||
|
||||
float val = out.at<float>({0, 0});
|
||||
bool matched = val > 0.95;
|
||||
|
@ -76,3 +78,19 @@ Matcher::Match Matcher::matchPos(const cv::Mat& img) {
|
|||
|
||||
return {matched, posx, posy, templ.cols, templ.rows};
|
||||
}
|
||||
|
||||
void Matcher::maskFromTemplate() {
|
||||
if(templ.channels() == 4) {
|
||||
// split channels
|
||||
std::vector<cv::Mat> split;
|
||||
cv::split(templ, split);
|
||||
|
||||
// template without alpha channel
|
||||
cv::merge(std::vector(split.begin(), split.end()-1), templ);
|
||||
|
||||
// 3*alpha channel
|
||||
cv::Mat alphaChannel = split.at(3);
|
||||
alphaChannel.convertTo(alphaChannel, CV_8U);
|
||||
cv::merge(std::vector(3, alphaChannel), mask);
|
||||
}
|
||||
}
|
||||
|
|