Skip to content

Commit

Permalink
refactor: 彻底解耦识别器与MAA实例
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Sep 8, 2023
1 parent 2b30ff4 commit ccc5896
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
12 changes: 8 additions & 4 deletions source/MaaFramework/Task/Recognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ std::optional<Recognizer::Result> Recognizer::template_match(const cv::Mat& imag
return std::nullopt;
}

Matcher matcher(inst_, image);
Matcher matcher;
matcher.set_image(image);
matcher.set_name(name);
matcher.set_param(param);
matcher.set_cache(cache);
Expand Down Expand Up @@ -126,7 +127,8 @@ std::optional<Recognizer::Result> Recognizer::ocr(const cv::Mat& image, const MA
return std::nullopt;
}

OCRer ocrer(inst_, image);
OCRer ocrer;
ocrer.set_image(image);
ocrer.set_name(name);
ocrer.set_param(param);
ocrer.set_cache(cache);
Expand Down Expand Up @@ -163,7 +165,8 @@ std::optional<Recognizer::Result> Recognizer::classify(const cv::Mat& image,
return std::nullopt;
}

Classifier classifier(inst_, image);
Classifier classifier;
classifier.set_image(image);
classifier.set_name(name);
classifier.set_param(param);

Expand Down Expand Up @@ -193,7 +196,8 @@ std::optional<Recognizer::Result> Recognizer::detect(const cv::Mat& image, const
return std::nullopt;
}

Detector detector(inst_, image);
Detector detector;
detector.set_image(image);
detector.set_name(name);
detector.set_param(param);

Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Vision/CustomRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
MAA_VISION_NS_BEGIN

CustomRecognizer::CustomRecognizer(MaaCustomRecognizerHandle handle, InstanceInternalAPI* inst)
: VisionBase(nullptr), recognizer_(handle), inst_(inst)
: VisionBase(), recognizer_(handle), inst_(inst)
{}

CustomRecognizer::ResultsVec CustomRecognizer::analyze() const
Expand Down
1 change: 1 addition & 0 deletions source/MaaFramework/Vision/CustomRecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <meojson/json.hpp>

#include "Instance/InstanceInternalAPI.hpp"
#include "MaaFramework/MaaCustomRecognizer.h"
#include "VisionBase.h"
#include "VisionTypes.h"
Expand Down
7 changes: 0 additions & 7 deletions source/MaaFramework/Vision/VisionBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@

MAA_VISION_NS_BEGIN

VisionBase::VisionBase(InstanceInternalAPI* inst) : inst_(inst) {}

VisionBase::VisionBase(InstanceInternalAPI* inst, const cv::Mat& image) : inst_(inst)
{
set_image(image);
}

void VisionBase::set_image(const cv::Mat& image)
{
image_ = image;
Expand Down
8 changes: 0 additions & 8 deletions source/MaaFramework/Vision/VisionBase.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#pragma once

#include "Conf/Conf.h"
#include "Instance/InstanceInternalAPI.hpp"
#include "Utils/NoWarningCVMat.hpp"

MAA_VISION_NS_BEGIN

class VisionBase
{
public:
VisionBase(InstanceInternalAPI* inst);
VisionBase(InstanceInternalAPI* inst, const cv::Mat& image);

void set_image(const cv::Mat& image);
void set_cache(const cv::Rect& cache);
void set_name(std::string name);
Expand All @@ -20,8 +16,6 @@ class VisionBase
cv::Mat image_with_roi(const cv::Rect& roi) const;

protected:
MAA_RES_NS::ResourceMgr* resource() const { return inst_ ? inst_->inter_resource() : nullptr; }

cv::Mat draw_roi(const cv::Rect& roi) const;
void save_image(const cv::Mat& image) const;

Expand All @@ -30,8 +24,6 @@ class VisionBase
cv::Rect cache_ {};
std::string name_;

InstanceInternalAPI* inst_ = nullptr;

bool debug_draw_ = false;
bool save_draw_ = false;

Expand Down

0 comments on commit ccc5896

Please sign in to comment.