#include "MainFrame.h" constexpr auto g_Border = 2; CMainFrame::CMainFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title) { SetSize(wxSize(600, 300)); init(); } CMainFrame::~CMainFrame() { } void CMainFrame::init() { auto* panel = new wxPanel(this); auto* sizerTop = new wxBoxSizer(wxVERTICAL); auto* sizeA = new wxBoxSizer(wxHORIZONTAL); auto* pic_path = new wxTextCtrl(panel, wxID_ANY); auto* select_pic = new wxButton(panel, wxID_ANY, wxT("选择")); sizeA->Add(pic_path, 1, wxALL | wxEXPAND, g_Border); sizeA->Add(select_pic, 0, wxALL, g_Border); sizerTop->Add(sizeA, 0, wxALL | wxEXPAND, g_Border); win_img_ = new CImagePanel(panel); sizerTop->Add(win_img_, 1, wxALL | wxEXPAND, g_Border); img_ = cv::imread("D:/2.png"); win_img_->set_img(img_); auto* sizeB = new wxBoxSizer(wxHORIZONTAL); auto* btn2Blue = new wxButton(panel, wxID_ANY, wxT("蓝底")); auto* btn2White = new wxButton(panel, wxID_ANY, wxT("白底")); sizeB->Add(btn2Blue, 1, wxALL | wxEXPAND, g_Border); sizeB->Add(btn2White, 1, wxALL | wxEXPAND, g_Border); btn2Blue->Bind(wxEVT_BUTTON, &CMainFrame::turn2blue, this); btn2White->Bind(wxEVT_BUTTON, &CMainFrame::turn2white, this); sizerTop->Add(sizeB, 0, wxALL | wxEXPAND, g_Border); panel->SetSizer(sizerTop); panel->Layout(); } void CMainFrame::turn2blue(wxCommandEvent& event) { // 定义白色的阈值范围 cv::Scalar lowerWhite(200, 200, 200); // 白色下限 (B, G, R) cv::Scalar upperWhite(255, 255, 255); // 白色上限 (B, G, R) // 创建蓝色背景 cv::Mat mask; cv::inRange(img_, lowerWhite, upperWhite, mask); // 检测白色区域 // 将白色区域替换为蓝色 cv::Mat blueBackground(img_.size(), img_.type(), cv::Scalar(255, 0, 0)); // 蓝色 (B, G, R) blueBackground.copyTo(img_, mask); // 通过掩码复制蓝色区域到原图 win_img_->set_img(img_); } void CMainFrame::turn2white(wxCommandEvent& event) { }