diff --git a/QT Source/RUBO.rc b/QT Source/RUBO.rc new file mode 100644 index 0000000..6ea288b --- /dev/null +++ b/QT Source/RUBO.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "RUBO1-tou.png" \ No newline at end of file diff --git a/QT Source/RUBO1-small.png b/QT Source/RUBO1-small.png new file mode 100644 index 0000000..39102b2 Binary files /dev/null and b/QT Source/RUBO1-small.png differ diff --git a/QT Source/RUBO1-tou.ico b/QT Source/RUBO1-tou.ico new file mode 100644 index 0000000..44ef937 Binary files /dev/null and b/QT Source/RUBO1-tou.ico differ diff --git a/QT Source/RUBO1-tou.png b/QT Source/RUBO1-tou.png new file mode 100644 index 0000000..898969f Binary files /dev/null and b/QT Source/RUBO1-tou.png differ diff --git a/QT Source/RUBO1.png b/QT Source/RUBO1.png new file mode 100644 index 0000000..39102b2 Binary files /dev/null and b/QT Source/RUBO1.png differ diff --git a/QT Source/RUBO2.png b/QT Source/RUBO2.png new file mode 100644 index 0000000..a83dcb2 Binary files /dev/null and b/QT Source/RUBO2.png differ diff --git a/QT Source/change-view.cpp b/QT Source/change-view.cpp new file mode 100644 index 0000000..6ce4067 --- /dev/null +++ b/QT Source/change-view.cpp @@ -0,0 +1,125 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "change-view.h" +using namespace std; +using namespace cv; +#define num_type unsigned char +int width; +int high; +int width_end; +int high_end; +float point[4][2]; +int point_center_y;//0~high_end +int see_len; +bool flag = false; +Mat src; +int test_flag = 1; //0进行透视变换 1获取矩阵 +int val1; +int cnt = 0; +int x31, + x41, + x11, y11 +, x21, y21, + x12, y12, + x22, y22; +int point_center_x; +QString Mat2QString(const Mat &src1) { + if (src1.empty()) return QString(); + stringstream stream; + stream << src1; + return QString::fromStdString(stream.str()); +} +void read_pic(string path) { + src = imread(path); + width = src.cols; + high = src.rows; + cvtColor(src, src, COLOR_RGB2GRAY, 0); +} +void init_para() { + pic.PIC_OPEN = 1; + pic.click_cnt = 0; + pic.change = 0; +} +void change_view() { + point_center_x = width_end / 2; + vector src_coners(4); + int y31, y41; + x31 = point[0][0], + x41 = point[1][0], + x11 = point[2][0], y11 = point[2][1], y21 = point[3][1]; + x21 = point[3][0], y31 = point[0][1], y41 = point[1][1]; + x12 = point_center_x - see_len / 2, y12 = point_center_y - see_len / 2, + x22 = point_center_x + see_len / 2, y22 = point_center_y + see_len / 2; + /* + * (x11,y11)******************(x21,y11) (x12,y12)**************(x22,y12) + * * * * * + * * 原图(梯形) * --------> * 结果(正方形)* + * * * * * + * (x31,y21)******************************(x41,y21) (x12,y22)**************(x22,y22) + * test_flag=1时:(坐标手点,从X31开始,逆时针点四次) (坐标自己在代码上修改) ----> 将打印出的矩阵放入代码 + * test_flag=0时: 右键图片查看效果 + * + * + */ + + src_coners[0] = Point2f(x31, y31); + src_coners[1] = Point2f(x41, y41); + src_coners[2] = Point2f(x11, y11); + src_coners[3] = Point2f(x21, y21); + vector dst_coners(4); + dst_coners[0] = Point2f(x12, y22); + dst_coners[1] = Point2f(x22, y22); + dst_coners[2] = Point2f(x12, y12); + dst_coners[3] = Point2f(x22, y12); + Mat warpMatrix; + warpMatrix = getPerspectiveTransform(src_coners, dst_coners); + double change_Mat[3][3]; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + change_Mat[i][j] = warpMatrix.at(i, j); + num_type src_tmp1[high][width]; + double change_un_Mat[3][3]; + for (int i = 0; i < high; i++) + for (int j = 0; j < width; j++) + src_tmp1[i][j] = src.at(i, j); + Mat un_warpMatrix; //逆矩阵 + + invert(warpMatrix, un_warpMatrix, DECOMP_LU); + cout << "逆矩阵" << endl << un_warpMatrix << endl; + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(Mat2QString(un_warpMatrix)); + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + change_un_Mat[i][j] = un_warpMatrix.at(i, j); + unsigned char *b[high_end][width_end]; + /******************指针地址映射*******************/ + unsigned char back_color = 255; + for (int i = 0; i < width_end; i++) { + for (int j = 0; j < high_end; j++) { + int local_x = (int) ((change_un_Mat[0][0] * i + change_un_Mat[0][1] * j + change_un_Mat[0][2]) / + (change_un_Mat[2][0] * i + change_un_Mat[2][1] * j + change_un_Mat[2][2])); + int local_y = (int) ((change_un_Mat[1][0] * i + change_un_Mat[1][1] * j + change_un_Mat[1][2]) / + (change_un_Mat[2][0] * i + change_un_Mat[2][1] * j + change_un_Mat[2][2])); + if (local_x >= 0 && local_y >= 0 && local_y < high && local_x < width) { + b[j][i] = &src_tmp1[local_y][local_x]; + } else b[j][i] = &back_color; + } + } + + /**********数组获取指针值&显示图片***********************/ + Mat src1; + src1 = (Mat::ones(high_end, width_end, CV_8U)); + unsigned char bb[high_end][width_end];//图 + memset(bb, 0, sizeof(bb)); + for (int i = 1; i < high_end - 1; i++) + for (int j = 1; j < width_end - 1; j++) + bb[i][j] = *b[i][j]; + for (int i = 0; i < high_end; i++) + for (int j = 0; j < width_end; j++) + src1.at(i, j) = bb[i][j]; + namedWindow("result", 0); + int n1 = screenX / 5 * 3 / width_end; + int n2 = screenY / 5 * 3 / high_end; + resizeWindow("result", width_end * min(n1, n2), high_end * min(n1, n2)); + imshow("result", src1); +} diff --git a/QT Source/change-view.h b/QT Source/change-view.h new file mode 100644 index 0000000..51f879e --- /dev/null +++ b/QT Source/change-view.h @@ -0,0 +1,20 @@ +#ifndef CHANGEVIEW_H +#define CHANGEVIEW_H +#include "opencv2/opencv.hpp" + +using namespace std; +using namespace cv; + +extern Mat src; + +void read_pic(string path); +void init_para(); +void change_view(); +extern int width ; +extern int high ; +extern int width_end ; +extern int high_end ; +extern float point[4][2]; +extern int point_center_y ;//0~high_end +extern int see_len ; +#endif // CHANGEVIEW_H diff --git a/QT Source/change-view.pro b/QT Source/change-view.pro new file mode 100644 index 0000000..3efe58b --- /dev/null +++ b/QT Source/change-view.pro @@ -0,0 +1,93 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2022-07-26T15:03:02 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = change-view +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +CONFIG += c++11 + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + change-view.cpp \ + rubo_label.cpp + +HEADERS += \ + mainwindow.h \ + change-view.h \ + rubo_label.h + +FORMS += \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + + +INCLUDEPATH += C:\OPENCV\make-qt\install\include +C:\OPENCV\opencv\opencv\build\include\opencv2 +C:\OPENCV\opencv\opencv\build\bin +LIBS += C:\OPENCV\make-qt\install\x64\mingw\bin\libopencv_*.dll +-lopencv_world401 +-lopencv_world401d +LIBS += -lpthread libwsock32 libws2_32 + +#CONFIG += console + + + +#可执行文件名称 +TARGET="RUBO IPM" + + +#版本信息 +VERSION = 1.0.0 + +#图标 + +#公司名称 +QMAKE_TARGET_COMPANY = "RUBO" + +#产品名称 +QMAKE_TARGET_PRODUCT = "RUBO IPM" + +#文件说明 +QMAKE_TARGET_DESCRIPTION = "MADE BY RUBO" + +#版权信息 +QMAKE_TARGET_COPYRIGHT = "RUBO" + +#中文(简体) +RC_LANG = 0x0004 + +RESOURCES += \ + rubo.qrc + + + + +RC_ICONS = RUBO1-tou.ico + + + + diff --git a/QT Source/change-view.pro.user b/QT Source/change-view.pro.user new file mode 100644 index 0000000..ca0165a --- /dev/null +++ b/QT Source/change-view.pro.user @@ -0,0 +1,577 @@ + + + + + + EnvironmentId + {75065ab1-f329-4ded-97fe-89865eac0c8e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.12.0 MinGW 64-bit + Desktop Qt 5.12.0 MinGW 64-bit + qt.qt5.5120.win64_mingw73_kit + 1 + 0 + 0 + + C:/Users/Administrator/Documents/build-change-view-Desktop_Qt_5_12_0_MinGW_64_bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/Administrator/Documents/build-change-view-Desktop_Qt_5_12_0_MinGW_64_bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/Administrator/Documents/build-change-view-Desktop_Qt_5_12_0_MinGW_64_bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + change-view + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Administrator/Documents/change-view/change-view.pro + change-view.pro + + 3768 + false + true + true + false + false + true + false + + C:/Users/Administrator/Documents/build-change-view-Desktop_Qt_5_12_0_MinGW_64_bit-Release + + 1 + + + + ProjectExplorer.Project.Target.1 + + 未命名 + 未命名 + {579e4723-bbb2-4c26-b129-5b8b0f1ef97e} + 0 + 0 + 0 + + C:/Users/Administrator/Documents/build-change-view-unknown-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/Administrator/Documents/build-change-view-unknown-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/Administrator/Documents/build-change-view-unknown-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + change-view + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Administrator/Documents/change-view/change-view.pro + change-view.pro + + 3768 + false + true + true + false + false + true + false + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 20 + + + Version + 20 + + diff --git a/QT Source/main.cpp b/QT Source/main.cpp new file mode 100644 index 0000000..d89c41a --- /dev/null +++ b/QT Source/main.cpp @@ -0,0 +1,13 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + + QApplication a(argc, argv); + + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/QT Source/mainwindow.cpp b/QT Source/mainwindow.cpp new file mode 100644 index 0000000..fec6fc0 --- /dev/null +++ b/QT Source/mainwindow.cpp @@ -0,0 +1,276 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "rubo_label.h" +using namespace std; +using namespace cv; +int screenX, screenY; +pic_show pic; +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) { + this->setWindowIcon(QIcon(":RUBO1-tou.png")); + ui->setupUi(this); + mouse_init(); + /*************定时器*********************/ + id1 = startTimer(1000); + QTimer *timer = new QTimer(this); /* 创建一个新的定时器 */ + connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate())); + timer->start(1); /* 设置溢出时间为1秒,并启动定时器 */ + qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); + open_mainwindows_updata_windows(); +} +bool MainWindow::judge_int(QString a) { + if (!a.contains(QRegExp("^\\d+$"))) { + QMessageBox::critical(this, "错误", "参数输入错误!"); + return 0; + } + return 1; +} +MainWindow::~MainWindow() { + delete ui; +} +void MainWindow::open_pic_update_windows() { + init_windows(pic.show_width, pic.show_high); + ui->label_tips->setText("用鼠标右键点击,从方形左下-右下-左上-右上选取四个点:"); + ui->label_pic1->setGeometry(ui->label_pic1->x(), ui->label_pic1->y(), pic.show_width, pic.show_high); +} +void MainWindow::open_mainwindows_updata_windows() { + QDesktopWidget *desktopWidget = QApplication::desktop(); + //获取设备屏幕大小 + QRect screenRect = desktopWidget->screenGeometry(); + screenX = screenRect.width(); + screenY = screenRect.height(); + int init_width = 114, init_high = 100; + int n1 = screenX / 5 * 3 / init_width; + int n2 = screenY / 5 * 3 / init_high; + pic.zoom = min(n1, n2); + pic.show_width = pic.zoom * init_width; + pic.show_high = pic.zoom * init_high; + init_windows(pic.show_width, pic.show_high); //1200--940 600-600 + ui->button_change->setEnabled(0); + ui->label_tips->setText("请打开图片"); + pic.PIC_OPEN = 0; + pic.change = 0; +} +void MainWindow::QString_to_string(QString a, string *b) { + *b = a.toStdString(); +} +void MainWindow::init_model1_windows(int start_x, int start_y) { + ui->label_width->setGeometry(start_x, start_y, ui->label_width->width(), ui->label_width->height()); + ui->label_high->setGeometry(start_x, start_y + 50, ui->label_high->width(), ui->label_high->height()); + ui->label_ysite->setGeometry(start_x - 50, start_y + 50 * 2, ui->label_ysite->width(), ui->label_ysite->height()); + ui->label_len->setGeometry(start_x, start_y + 50 * 3, ui->label_len->width(), ui->label_len->height()); + ui->text_width->setGeometry(start_x + 100, start_y - 10, ui->text_width->width(), ui->text_width->height()); + ui->text_high->setGeometry(start_x + 100, start_y + 50 - 10, ui->text_high->width(), ui->text_high->height()); + ui->text_ysite->setGeometry(start_x + 100, start_y + 50 * 2 - 10, ui->text_ysite->width(), + ui->text_ysite->height()); + ui->text_len->setGeometry(start_x + 100, start_y + 50 * 3 - 10, ui->text_len->width(), ui->text_len->height()); +} +void MainWindow::init_model2_windows(int start_x, int start_y) { + ui->label_x1->setGeometry(start_x, start_y, ui->label_x1->width(), ui->label_x1->height()); + ui->label_x2->setGeometry(start_x, start_y + 50, ui->label_x2->width(), ui->label_x2->height()); + ui->label_x3->setGeometry(start_x, start_y + 50 * 2, ui->label_x3->width(), ui->label_x3->height()); + ui->label_x4->setGeometry(start_x, start_y + 50 * 3, ui->label_x4->width(), ui->label_x4->height()); + ui->label_y1->setGeometry(start_x + 100, start_y, ui->label_y1->width(), ui->label_y1->height()); + ui->label_y2->setGeometry(start_x + 100, start_y + 50, ui->label_y2->width(), ui->label_y2->height()); + ui->label_y3->setGeometry(start_x + 100, start_y + 50 * 2, ui->label_y3->width(), ui->label_y3->height()); + ui->label_y4->setGeometry(start_x + 100, start_y + 50 * 3, ui->label_y4->width(), ui->label_y4->height()); + ui->text_x1->setGeometry(start_x + 30, start_y - 10, ui->text_x1->width(), ui->text_x1->height()); + ui->text_x2->setGeometry(start_x + 30, start_y + 50 - 10, ui->text_x2->width(), ui->text_x2->height()); + ui->text_x3->setGeometry(start_x + 30, start_y + 50 * 2 - 10, ui->text_x3->width(), ui->text_x3->height()); + ui->text_x4->setGeometry(start_x + 30, start_y + 50 * 3 - 10, ui->text_x4->width(), ui->text_x4->height()); + ui->text_y1->setGeometry(start_x + 100 + 30, start_y - 10, ui->text_y1->width(), ui->text_y1->height()); + ui->text_y2->setGeometry(start_x + 100 + 30, start_y + 50 - 10, ui->text_y2->width(), ui->text_y2->height()); + ui->text_y3->setGeometry(start_x + 100 + 30, start_y + 50 * 2 - 10, ui->text_y3->width(), ui->text_y3->height()); + ui->text_y4->setGeometry(start_x + 100 + 30, start_y + 50 * 3 - 10, ui->text_y4->width(), ui->text_y4->height()); +} +void MainWindow::init_model3_windows(int start_x, int start_y) { + ui->button_clear->setGeometry(start_x + 60, start_y, ui->button_clear->width(), ui->button_clear->height()); + ui->button_openpic->setGeometry(start_x + 60, start_y + 40, ui->button_openpic->width(), + ui->button_openpic->height()); + ui->button_change->setGeometry(start_x + 60, start_y + 80, ui->button_change->width(), ui->button_change->height()); +} +void MainWindow::init_model4_windows(int start_x, int start_y) { + ui->label_pic1->setGeometry(start_x, start_y, ui->label_pic1->width(), ui->label_pic1->height()); +} +void MainWindow::init_model5_windows(int start_x, int start_y) { + ui->label_tips->setGeometry(start_x, start_y, ui->label_tips->width(), ui->label_tips->height()); +} +void MainWindow::init_windows(int start_width, int start_high) { + /****************main_window*******************/ + setFixedSize(this->width(), this->height()); + /****************modle1***************/ + int model1_start_x = start_width + 60, model1_start_y = 30; + init_model1_windows(model1_start_x, model1_start_y); + int model2_start_x = start_width + 60, model2_start_y = 230; + init_model2_windows(model2_start_x, model2_start_y); + int model3_start_x = start_width + 60 - 10, model3_start_y = 420; + init_model3_windows(model3_start_x, model3_start_y); + int model4_start_x = 0, model4_start_y = 0; + init_model4_windows(model4_start_x, model4_start_y); + setFixedSize(start_width + 260, max(start_high + 50, 550)); + int model5_start_x = 0, model5_start_y = start_high + 5; + init_model5_windows(model5_start_x, model5_start_y); +} +void MainWindow::update_windows() { +} +void MainWindow::active_windows() { + Qt::WindowStates winStatus = Qt::WindowNoState; + if (windowState() & Qt::WindowMaximized) { + winStatus = Qt::WindowMaximized; + } + setWindowState(Qt::WindowMinimized); + setWindowState(Qt::WindowActive | winStatus); + setGeometry(geometry()); + activateWindow(); + raise(); +} +void MainWindow::on_button_openpic_clicked() { + QString filename = QFileDialog::getOpenFileName(this, tr("选择图像"), "", tr("Images (*.png *.bmp *.jpg)")); + if (filename.isEmpty()) return; + QImage img; + if (!(img.load(filename))) //加载图像 + { + QMessageBox::information(this, tr("打开图像失败"), tr("打开图像失败!")); + return; + } + string path; + QString_to_string(filename, &path); + read_pic(path); + update_windows(); + int n1 = screenX / 5 * 3 / img.width(); + int n2 = screenY / 5 * 3 / img.height(); + pic.width = img.width(); + pic.high = img.height(); + pic.zoom = min(n1, n2); + pic.show_width = pic.zoom * pic.width; + pic.show_high = pic.zoom * pic.high; + open_pic_update_windows(); + init_para(); + on_button_clear_clicked(); + ui->label_pic1->setPixmap(QPixmap::fromImage(img.scaled(ui->label_pic1->size()))); + ui->button_change->setEnabled(1); + active_windows(); +} +void MainWindow::on_button_clear_clicked() { + ui->text_x1->clear(); + ui->text_y1->clear(); + ui->text_x2->clear(); + ui->text_y2->clear(); + ui->text_x3->clear(); + ui->text_y3->clear(); + ui->text_x4->clear(); + ui->text_y4->clear(); + pic.click_cnt = 0; + pic.change = 0; +} +void MainWindow::timerUpdate() { /* 定时器溢出处理 */ + if (!pic.PIC_OPEN)return; + if (pic.change) { + QString str = "透视变换成功,已复制至剪切板"; + ui->label_tips->setText(str); + return; + } + if (mouse_flag.enter) { + if (mouse_flag.click == 2) { + if (pic.click_cnt == 1) { + QString str = "选中第一个点x:" + QString::number(mouse_flag.x, 10) + " " + "y:" + + QString::number(mouse_flag.y, 10); + ui->label_tips->setText(str); + ui->text_x1->append(QString::number(mouse_flag.x, 10)); + ui->text_y1->append(QString::number(mouse_flag.y, 10)); + } + if (pic.click_cnt == 2) { + QString str = "选中第二个点x:" + QString::number(mouse_flag.x, 10) + " " + "y:" + + QString::number(mouse_flag.y, 10); + ui->label_tips->setText(str); + ui->text_x2->append(QString::number(mouse_flag.x, 10)); + ui->text_y2->append(QString::number(mouse_flag.y, 10)); + } + if (pic.click_cnt == 3) { + QString str = "选中第三个点x:" + QString::number(mouse_flag.x, 10) + " " + "y:" + + QString::number(mouse_flag.y, 10); + ui->label_tips->setText(str); + ui->text_x3->append(QString::number(mouse_flag.x, 10)); + ui->text_y3->append(QString::number(mouse_flag.y, 10)); + } + if (pic.click_cnt == 4) { + QString str = "选中第四个点x:" + QString::number(mouse_flag.x, 10) + " " + "y:" + + QString::number(mouse_flag.y, 10); + ui->label_tips->setText(str); + ui->text_x4->append(QString::number(mouse_flag.x, 10)); + ui->text_y4->append(QString::number(mouse_flag.y, 10)); + } + mouse_flag.click = 0; + mouse_flag.move = 0; + return; + } + if (mouse_flag.move && pic.change == 0) { + mouse_flag.move = 0; + QString str = "x:" + QString::number(mouse_flag.x, 10) + " " + "y:" + QString::number(mouse_flag.y, 10); + ui->label_tips->setText(str); + } + } else { + ui->label_tips->setText("用鼠标右键点击,从方形左下-右下-左上-右上选取四个点"); + } +} +void MainWindow::on_button_change_clicked() { + QString num_tmp; + /**********************结果图基本信息***********************/ + num_tmp = ui->text_width->toPlainText(); + if (!judge_int(num_tmp))return; + width_end = num_tmp.toInt(); + num_tmp = ui->text_high->toPlainText(); + if (!judge_int(num_tmp))return; + high_end = num_tmp.toInt(); + num_tmp = ui->text_ysite->toPlainText(); + if (!judge_int(num_tmp))return; + point_center_y = num_tmp.toInt(); + num_tmp = ui->text_len->toPlainText(); + if (!judge_int(num_tmp))return; + see_len = num_tmp.toInt(); + + /***********************透视坐标***************************/ + num_tmp = ui->text_x1->toPlainText(); + if (!judge_int(num_tmp))return; + point[0][0] = (float) (num_tmp.toFloat()); + num_tmp = ui->text_y1->toPlainText(); + if (!judge_int(num_tmp))return; + point[0][1] = (float) (num_tmp.toFloat()); + num_tmp = ui->text_x2->toPlainText(); + if (!judge_int(num_tmp))return; + point[1][0] = (float) (num_tmp.toFloat()); + num_tmp = ui->text_y2->toPlainText(); + if (!judge_int(num_tmp))return; + point[1][1] = (float) (num_tmp.toFloat()); + num_tmp = ui->text_x3->toPlainText(); + if (!judge_int(num_tmp))return; + point[2][0] = (float) (num_tmp.toFloat()); + num_tmp = ui->text_y3->toPlainText(); + if (!judge_int(num_tmp))return; + point[2][1] = (float) (num_tmp.toFloat()); + num_tmp = ui->text_x4->toPlainText(); + if (!judge_int(num_tmp))return; + point[3][0] = (float) (num_tmp.toFloat()); + num_tmp = ui->text_y4->toPlainText(); + if (!judge_int(num_tmp))return; + point[3][1] = (float) (num_tmp.toFloat()); + change_view(); + pic.change = 1; +} +void MainWindow::on_action_2_triggered() { + qApp->quit(); +} +void MainWindow::on_about_triggered() { + QMessageBox MBox; + MBox.setWindowTitle("About RUBO IPM"); + MBox.setText("RUBO IPM 1.0.0"); + MBox.setInformativeText( + "Based on Qt 5.12.0 (MinGW 7.3.0 64 bit)\n\nBuilt on Aug 2 2022 10:33:33\n\nFrom revision 0.9.9\n\nChecked by RUBO\n\nTHIS PROGRAM IS ONLY PROVIDED FOR LEARNING AND\nCOMMUNICATION, AND HAS NOTHING TO DOWITH ANY\nSCHOOL OR ORGANIZATION. ANY FORM OF COMMERCIAL\nUSE IS PROHIBITED."); + MBox.setIconPixmap(QPixmap(":RUBO1-small.png")); + QPushButton *agreeBut = MBox.addButton("Close", QMessageBox::AcceptRole); + MBox.exec(); +} +void MainWindow::on_open_triggered() { + on_button_openpic_clicked(); +} diff --git a/QT Source/mainwindow.h b/QT Source/mainwindow.h new file mode 100644 index 0000000..f8b49fd --- /dev/null +++ b/QT Source/mainwindow.h @@ -0,0 +1,99 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "opencv2/opencv.hpp" +#include "qlabel.h" +#include "qdebug.h" +#include "bits/stdc++.h" +#include "qtimer.h" +#include"QFileDialog.h" +#include +#include +#include +#include +#include +#include +#include +#include "rubo_label.h" +#include +#include +#include +#include +#include +#include +#include +#include + +/***********************************RUBO HEADFILE*********************************/ +#include "change-view.h" +using namespace std; +using namespace cv; +namespace Ui { +class MainWindow; + +} +class myLabel; +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + Ui::MainWindow *ui; + myLabel* mylabel; + +private slots: + void on_button_openpic_clicked(); + void QString_to_string(QString a,string *b); + void init_windows(int start_width,int start_high); + void update_windows(); + void init_model1_windows(int start_x,int start_y); + void init_model2_windows(int start_x,int start_y); + void init_model3_windows(int start_x,int start_y); + void init_model4_windows(int model4_start_x,int model4_start_y); + void init_model5_windows(int model5_start_x,int model5_start_y); + void open_pic_update_windows(); + void open_mainwindows_updata_windows(); + void active_windows(); + bool judge_int(QString a); + + void on_button_clear_clicked(); +protected: +private slots: + void timerUpdate(); + + + void on_action_2_triggered(); + + void on_button_change_clicked(); + +// void on_action_2_triggered(); + + void on_about_triggered(); + + void on_open_triggered(); + +private: + int id1; + + +}; +struct pic_show{ + int width; + int high; + int show_width; + int show_high; + int zoom; + int click_cnt; + bool PIC_OPEN; + bool change; +}; +extern int screenX,screenY; + +extern pic_show pic; +#if defined(_MSC_VER) && (_MSC_VER >= 1600) +# pragma execution_character_set("utf-8") +#endif +#endif // MAINWINDOW_H diff --git a/QT Source/mainwindow.ui b/QT Source/mainwindow.ui new file mode 100644 index 0000000..2b6543a --- /dev/null +++ b/QT Source/mainwindow.ui @@ -0,0 +1,457 @@ + + + MainWindow + + + + 0 + 0 + 1200 + 650 + + + + RUBO IPM + + + QToolBar{border-color: rgb(0, 0, 0);border:1px solid;} + + + true + + + + + + 1050 + 460 + 93 + 28 + + + + 打开图片 + + + + + + 1050 + 500 + 93 + 28 + + + + 透视变换 + + + + + + 1100 + 70 + 60 + 30 + + + + + + + 1000 + 80 + 91 + 16 + + + + 结果图高度: + + + + + + 950 + 130 + 141 + 16 + + + + 方形中心距顶部像素: + + + + + + 1100 + 120 + 60 + 30 + + + + + + + 1100 + 20 + 60 + 30 + + + + + + + 1000 + 30 + 91 + 16 + + + + 结果图宽度: + + + + + + 1000 + 180 + 141 + 16 + + + + 方形像素边长: + + + + + + 1100 + 170 + 60 + 30 + + + + + + + 1000 + 230 + 21 + 16 + + + + X1: + + + + + + 1100 + 230 + 21 + 16 + + + + Y1: + + + + + + 1030 + 220 + 60 + 30 + + + + + + + 1130 + 220 + 60 + 30 + + + + + + + 1130 + 270 + 60 + 30 + + + + + + + 1030 + 270 + 60 + 30 + + + + + + + 1030 + 320 + 60 + 30 + + + + + + + 1030 + 370 + 60 + 30 + + + + + + + 1130 + 320 + 60 + 30 + + + + + + + 1130 + 370 + 60 + 30 + + + + + + + 1000 + 280 + 21 + 16 + + + + X2: + + + + + + 1000 + 330 + 21 + 16 + + + + X3: + + + + + + 1000 + 380 + 21 + 16 + + + + X4: + + + + + + 1100 + 280 + 21 + 16 + + + + Y2: + + + + + + 1100 + 330 + 21 + 16 + + + + Y3: + + + + + + 1100 + 380 + 20 + 20 + + + + Y4: + + + + + + 0 + 0 + 940 + 600 + + + + + + + Qt::PlainText + + + + + + 1050 + 420 + 93 + 28 + + + + 清除 + + + + + + 0 + 605 + 1200 + 16 + + + + 提示: + + + label_pic1 + button_openpic + button_change + text_high + label_high + label_ysite + text_ysite + text_width + label_width + label_len + text_len + label_x1 + label_y1 + text_x1 + text_y1 + text_y2 + text_x2 + text_x3 + text_x4 + text_y3 + text_y4 + label_x2 + label_x3 + label_x4 + label_y2 + label_y3 + label_y4 + button_clear + label_tips + + + + + 0 + 0 + 1200 + 26 + + + + + 文件 + + + + + + + + + + 打开图片 + + + 打开图片 + + + Ctrl+O + + + + + 关于 + + + 关于 + + + Ctrl+A + + + + + 退出 + + + Ctrl+Q + + + + + + + myLabel + QLabel +
rubo_label.h
+
+
+ + +
diff --git a/QT Source/rubo.qrc b/QT Source/rubo.qrc new file mode 100644 index 0000000..ca0473e --- /dev/null +++ b/QT Source/rubo.qrc @@ -0,0 +1,9 @@ + + + RUBO1.png + RUBO2.png + RUBO1-small.png + RUBO1-tou.png + RUBO1-tou.ico + + diff --git a/QT Source/rubo_label.cpp b/QT Source/rubo_label.cpp new file mode 100644 index 0000000..f59b78f --- /dev/null +++ b/QT Source/rubo_label.cpp @@ -0,0 +1,66 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include +mouse mouse_flag ; +void mouse_init() +{ + mouse_flag.click=0; + mouse_flag.enter=0; + mouse_flag.x=0; + mouse_flag.y=0; + mouse_flag.move=0; + pic.click_cnt=0; + + +} +myLabel::myLabel(QWidget *parent) :QLabel(parent) + +{ + setMouseTracking(true); + +} + +void myLabel::mousePressEvent(QMouseEvent *ev) +{ + if(!pic.PIC_OPEN)return; + mouse_flag.move=0; + + if(ev->button()==Qt::LeftButton) + { + + mouse_flag.click=1; + } + if(ev->button()==Qt::RightButton) + { + if( pic.click_cnt<=4) pic.click_cnt++; + + + mouse_flag.click=2; + + } + +} +//鼠标进入事件 +void myLabel::enterEvent(QEvent *event) +{ + mouse_flag.enter=1; + +} +//鼠标离开事件 +void myLabel::leaveEvent(QEvent * ) +{ + mouse_flag.enter=0; +} + +void myLabel::mouseMoveEvent(QMouseEvent *ev) +{ + if(!pic.PIC_OPEN)return; + if(mouse_flag.click==2)return; + mouse_flag.x=ev->x()/pic.zoom; + mouse_flag.y=ev->y()/pic.zoom; + mouse_flag.move=1; + + +} + diff --git a/QT Source/rubo_label.h b/QT Source/rubo_label.h new file mode 100644 index 0000000..07996ee --- /dev/null +++ b/QT Source/rubo_label.h @@ -0,0 +1,37 @@ +#ifndef RUBO_LABEL_H +#define RUBO_LABEL_H +#include +#include "mainwindow.h" + +class MainWindow; + +class myLabel : public QLabel +{ + Q_OBJECT +public: + + myLabel(QWidget *parent = nullptr); + + //鼠标进入事件 + void enterEvent(QEvent *event); + //鼠标离开事件 + void leaveEvent(QEvent *event); + void mousePressEvent(QMouseEvent *ev); + + void mouseMoveEvent(QMouseEvent *ev); + +signals: +}; +void mouse_init(); + + +struct mouse +{ + bool enter; + int x,y; + int click; //0 1l 2r + bool move; +}; +extern mouse mouse_flag ; + +#endif // RUBO_LABEL_H diff --git a/QT Source/rubo_window.h b/QT Source/rubo_window.h new file mode 100644 index 0000000..2ef2379 --- /dev/null +++ b/QT Source/rubo_window.h @@ -0,0 +1,9 @@ +#ifndef RUBO_WINDOW_H +#define RUBO_WINDOW_H +#include "mainwindow.h" +#include "ui_mainwindow.h" +using namespace std; +using namespace cv; + + +#endif // RUBO_WINDOW_H diff --git "a/smartcar Demo/\351\200\217\350\247\206\345\217\230\346\215\242\344\270\213\344\275\215\346\234\272.txt" "b/smartcar Demo/\351\200\217\350\247\206\345\217\230\346\215\242\344\270\213\344\275\215\346\234\272.txt" new file mode 100644 index 0000000..4641499 --- /dev/null +++ "b/smartcar Demo/\351\200\217\350\247\206\345\217\230\346\215\242\344\270\213\344\275\215\346\234\272.txt" @@ -0,0 +1,42 @@ +#define RESULT_ROW 100//结果图行列 +#define RESULT_COL 114 +#define USED_ROW 120 //用于透视图的行列 +#define USED_COL 188 +#define PER_IMG SimBinImage//SimBinImage:用于透视变换的图像 +#define ImageUsed *PerImg_ip//*PerImg_ip定义使用的图像,ImageUsed为用于巡线和识别的图像 +typedef unsigned char uint8_t; // 无符号 8 bits +uint8_t *PerImg_ip[RESULT_ROW][RESULT_COL]; + +void ImagePerspective_Init(void) { + + static uint8_t BlackColor = 0; + double change_un_Mat[3][3] = { //114w*100h + { -0.01609759704190238, 0.01932561893613478, -2.040617594981866 }, { + 0.0004352209945470896, -0.000367865364438621, + -0.7035606436969671 }, { 1.115951268069474e-005, + 0.0001970185393508392, -0.03104642853440032 }, }; + for (int i = 0; i < RESULT_COL ;i++) { + for (int j = 0; j < RESULT_ROW ;j++) { + int local_x = (int) ((change_un_Mat[0][0] * i + + change_un_Mat[0][1] * j + change_un_Mat[0][2]) + / (change_un_Mat[2][0] * i + change_un_Mat[2][1] * j + + change_un_Mat[2][2])); + int local_y = (int) ((change_un_Mat[1][0] * i + + change_un_Mat[1][1] * j + change_un_Mat[1][2]) + / (change_un_Mat[2][0] * i + change_un_Mat[2][1] * j + + change_un_Mat[2][2])); + if (local_x + >= 0&& local_y >= 0 && local_y < USED_ROW && local_x < USED_COL){ + PerImg_ip[j][i] = &PER_IMG[local_y][local_x]; + } + else { + PerImg_ip[j][i] = &BlackColor; //&PER_IMG[0][0]; + } + + } + } + +} + + +/*完成摄像头初始化后,调用一次ImagePerspective_Init,此后,直接调用ImageUsed 即为透视结果*/ \ No newline at end of file