diff --git a/CV/snake.cpp b/CV/snake.cpp index af9ea2a..e8a7d70 100644 --- a/CV/snake.cpp +++ b/CV/snake.cpp @@ -56,25 +56,28 @@ void snake::snake_operation(Mat image, vector& curve, int window_size, do int windowIndex = (window_size - 1) / 2; int numPoints = curve.size(); vector newCurve(numPoints); - for (int i = 0; i < numPoints; i++) { - Point pt = curve[i]; - Point prevPt = curve[(i-1+numPoints)%numPoints]; - Point nextPt = curve[(i+1)%numPoints]; - double minEnergy = DBL_MAX; // max value can a double variable hold - Point newPt = pt; - // Try moving the point in different directions and choose the one with the minimum energy - for (int dx = -windowIndex; dx <= windowIndex; dx++) { - for (int dy = -windowIndex; dy <= windowIndex; dy++) { - Point movePt(pt.x + dx, pt.y + dy); - double energy = calculate_point_enegy(image, movePt, prevPt, nextPt, alpha, beta, gamma); - if (energy < minEnergy) { - minEnergy = energy; - newPt = movePt; + + for (int i = 0; i < numPoints; i++) { + Point pt = curve[i]; + Point prevPt = curve[(i-1+numPoints)%numPoints]; + Point nextPt = curve[(i+1)%numPoints]; + double minEnergy = DBL_MAX; // max value can a double variable hold + Point newPt = pt; + // Try moving the point in different directions and choose the one with the minimum energy + for (int dx = -windowIndex; dx <= windowIndex; dx++) { + for (int dy = -windowIndex; dy <= windowIndex; dy++) { + Point movePt(pt.x + dx, pt.y + dy); + double energy = calculate_point_enegy(image, movePt, prevPt, nextPt, alpha, beta, gamma); + if (energy < minEnergy) { + minEnergy = energy; + newPt = movePt; + } } } + newCurve[i] = newPt; } - newCurve[i] = newPt; - } + + curve = newCurve; } @@ -147,7 +150,11 @@ void snake::draw_contours(Mat image, Mat &outputimage, vector snake_point vector snake::active_contour(Mat inputimage, Mat &outputimage, Point center, int radius, int numOfIterations, int numOfPoints, - int window_size, double alpha, double beta, double gamma, QLabel*label){ + int window_size, double alpha, double beta, double gamma){ + + cout << center << endl; + cout << (inputimage.cols / 2) << " " << (inputimage.rows / 2) << endl; + vector curve = initialize_contours(center, radius, numOfPoints); @@ -159,14 +166,9 @@ vector snake::active_contour(Mat inputimage, Mat &outputimage, // Iterate for multiple iterations for (int i = 0; i < numOfIterations; i++) { snake_operation(grayimage, curve, window_size, alpha, beta, gamma); - draw_contours(inputimage, outputimage, curve); - QImage qimage(outputimage.data, outputimage.cols, outputimage.rows,outputimage.step,QImage::Format_BGR888); - QPixmap* image = new QPixmap(QPixmap::fromImage(qimage)); - int w = label->width(); - int h = label->height(); - label->setPixmap(image->scaled(w,h,Qt::KeepAspectRatio)); } -// draw_contours(inputimage, outputimage, curve); + draw_contours(inputimage, outputimage, curve); + return curve; } diff --git a/CV/snake.h b/CV/snake.h index 813ed9d..1f57030 100644 --- a/CV/snake.h +++ b/CV/snake.h @@ -15,7 +15,7 @@ class snake static vector active_contour(Mat inputimage, Mat &outputimage, Point center, int radius, int numOfIterations, int numOfPoints, - int window_size, double alpha, double beta, double gamma,QLabel * label); + int window_size, double alpha, double beta, double gamma); static double calculate_contour_area(vector snake_points); static double calculate_contour_perimeter(vector snake_points); diff --git a/Plot/plotter.h b/Plot/plotter.h index d9a29dd..31dbf4c 100644 --- a/Plot/plotter.h +++ b/Plot/plotter.h @@ -1,8 +1,7 @@ #ifndef PLOTTER_H #define PLOTTER_H -#include "qcustomplot.h" #include - +#include "utilities/qcustomplot.h" class plotter { public: diff --git a/a01-team06.pro b/a01-team06.pro index 954e491..122373b 100644 --- a/a01-team06.pro +++ b/a01-team06.pro @@ -13,17 +13,17 @@ SOURCES += \ CV/histogram.cpp \ CV/filters.cpp \ CV/frequency.cpp \ -# Plot/plotter.cpp \ + Plot/plotter.cpp \ CV/hough.cpp \ CV/snake.cpp \ -# pages/page4.cpp \ -# qcustomplot.cpp \ - clickable.cpp \ - scene.cpp \ + pages/page4.cpp \ + utilities/qcustomplot.cpp \ + utilities/clickable.cpp \ + utilities/scene.cpp \ main.cpp \ pages/page3.cpp \ pages/mainwindow.cpp \ -# pages/page2.cpp \ + pages/page2.cpp \ pages/page1.cpp \ pages/page5.cpp \ pages/page6.cpp @@ -33,37 +33,37 @@ HEADERS += \ CV/histogram.h \ CV/filters.h \ CV/frequency.h \ -# Plot/plotter.h \ + Plot/plotter.h \ CV/hough.h \ CV/snake.h \ -# pages/page4.h \ -# qcustomplot.h \ - clickable.h \ + pages/page4.h \ + utilities/qcustomplot.h \ + utilities/clickable.h \ pages/page3.h \ pages/mainwindow.h \ -# pages/page2.h \ + pages/page2.h \ pages/page1.h \ pages/page5.h \ pages/page6.h \ - scene.h + utilities/scene.h FORMS += \ -# pages/page4.ui \ + pages/page4.ui \ pages/page3.ui \ pages/mainwindow.ui \ -# pages/page2.ui \ + pages/page2.ui \ pages/page1.ui \ pages/page5.ui \ pages/page6.ui -INCLUDEPATH += C:\opencv\build\include +INCLUDEPATH += C:\Users\kamel\OneDrive\Documents\libraries\opencv\opencv\build\include -LIBS += C:\opencv\release\bin\libopencv_core470.dll -LIBS += C:\opencv\release\bin\libopencv_highgui470.dll -LIBS += C:\opencv\release\bin\libopencv_imgcodecs470.dll -LIBS += C:\opencv\release\bin\libopencv_imgproc470.dll -LIBS += C:\opencv\release\bin\libopencv_features2d470.dll -LIBS += C:\opencv\release\bin\libopencv_calib3d470.dll +LIBS += C:\Users\kamel\OneDrive\Documents\libraries\opencv\opencv\release\bin\libopencv_core470.dll +LIBS += C:\Users\kamel\OneDrive\Documents\libraries\opencv\opencv\release\bin\libopencv_highgui470.dll +LIBS += C:\Users\kamel\OneDrive\Documents\libraries\opencv\opencv\release\bin\libopencv_imgcodecs470.dll +LIBS += C:\Users\kamel\OneDrive\Documents\libraries\opencv\opencv\release\bin\libopencv_imgproc470.dll +LIBS += C:\Users\kamel\OneDrive\Documents\libraries\opencv\opencv\release\bin\libopencv_features2d470.dll +LIBS += C:\Users\kamel\OneDrive\Documents\libraries\opencv\opencv\release\bin\libopencv_calib3d470.dll # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/images/0.png b/images/0.png new file mode 100644 index 0000000..1c163be Binary files /dev/null and b/images/0.png differ diff --git a/images/Screenshot 2023-02-28 231508.png b/images/Screenshot 2023-02-28 231508.png new file mode 100644 index 0000000..f6bc459 Binary files /dev/null and b/images/Screenshot 2023-02-28 231508.png differ diff --git a/images/WhatsApp Image 2023-03-24 at 10.31.57 PM (1).jpeg b/images/WhatsApp Image 2023-03-24 at 10.31.57 PM (1).jpeg new file mode 100644 index 0000000..e2b7e08 Binary files /dev/null and b/images/WhatsApp Image 2023-03-24 at 10.31.57 PM (1).jpeg differ diff --git a/images/WhatsApp Image 2023-03-24 at 10.31.57 PM.jpeg b/images/WhatsApp Image 2023-03-24 at 10.31.57 PM.jpeg new file mode 100644 index 0000000..34b3662 Binary files /dev/null and b/images/WhatsApp Image 2023-03-24 at 10.31.57 PM.jpeg differ diff --git a/images/WhatsApp Image 2023-03-24 at 10.31.58 PM.jpeg b/images/WhatsApp Image 2023-03-24 at 10.31.58 PM.jpeg new file mode 100644 index 0000000..8173c2a Binary files /dev/null and b/images/WhatsApp Image 2023-03-24 at 10.31.58 PM.jpeg differ diff --git a/images/ellipses.png b/images/ellipses.png new file mode 100644 index 0000000..388d8cb Binary files /dev/null and b/images/ellipses.png differ diff --git a/main.cpp b/main.cpp index 134c018..f452c18 100644 --- a/main.cpp +++ b/main.cpp @@ -3,42 +3,18 @@ #include #include #include -#include "clickable.h" +#include "utilities/clickable.h" -void changeLabelCursors(const QCursor &newCursor) -{ - // Iterate through all widgets in the application - foreach (QWidget *widget, QApplication::allWidgets()) - { - qDebug()<<"Here"; - // Check if the widget is a QLabel - QLabel *label = qobject_cast(widget); - if (label != nullptr) - { - // Set the new cursor for the QLabel - label->setCursor(newCursor); - } - } -} int main(int argc, char *argv[]) { QApplication a(argc, argv); -// QPixmap pixmap(":/resources/resources/handpointing.png"); -// QPoint hotSpot(11, 10); -// QCursor cursor(pixmap, hotSpot.x(), hotSpot.y()); -// changeLabelCursors(cursor); -// QApplication::setOverrideCursor(cursor); MainWindow w; w.show(); - a.exec(); - - QList widgets = a.allWidgets(); - qDebug()<setupUi(this); - QString fileName = "Cstartpage.qss"; - QString projectDirPath =__FILE__; - projectDirPath+="/../../style"; - QString filePath = QDir(projectDirPath).absoluteFilePath(fileName); - QFile f(filePath); + QFile f(":/resources/style/Cstartpage.qss"); if ( !f.exists() ) { qWarning() << "Unable to set dark stylesheet, file not found"; @@ -28,20 +24,13 @@ MainWindow::MainWindow(QWidget *parent) QPoint hotSpot(11, 10); QCursor cursor(pixmap, hotSpot.x(), hotSpot.y()); this->setCursor(cursor); - - - QButtonGroup *group = new QButtonGroup(); - group->addButton(ui->pushButton); - group->addButton(ui->pushButton2); - group->addButton(ui->pushButton_3); - group->addButton(ui->pushButton_4); - + this->setWindowTitle("CV ToolKit"); ui->stackedWidget->insertWidget(0,new page1()); -// ui->stackedWidget->insertWidget(1,new page2()); + ui->stackedWidget->insertWidget(1,new page2()); ui->stackedWidget->insertWidget(2,new page3()); - //ui->stackedWidget->insertWidget(3,new page4()); - ui->stackedWidget->insertWidget(4,new page5()); + ui->stackedWidget->insertWidget(3,new page4()); + ui->stackedWidget->insertWidget(4,new page5()); ui->stackedWidget->insertWidget(5,new Page6()); @@ -49,15 +38,15 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->pushButton, &QPushButton::clicked, ui->stackedWidget, [=]() { ui->stackedWidget->setCurrentIndex(0); }); -// connect(ui->pushButton2, &QPushButton::clicked, ui->stackedWidget, [=]() { -// ui->stackedWidget->setCurrentIndex(1); -// }); + connect(ui->pushButton2, &QPushButton::clicked, ui->stackedWidget, [=]() { + ui->stackedWidget->setCurrentIndex(1); + }); connect(ui->pushButton_3, &QPushButton::clicked, ui->stackedWidget, [=]() { ui->stackedWidget->setCurrentIndex(2); }); -// connect(ui->pushButton_4, &QPushButton::clicked, ui->stackedWidget, [=]() { -// ui->stackedWidget->setCurrentIndex(3); -// }); + connect(ui->pushButton_4, &QPushButton::clicked, ui->stackedWidget, [=]() { + ui->stackedWidget->setCurrentIndex(3); + }); connect(ui->pushButton_5, &QPushButton::clicked, ui->stackedWidget, [=]() { ui->stackedWidget->setCurrentIndex(4); }); diff --git a/pages/mainwindow.h b/pages/mainwindow.h index c70fedf..75898c3 100644 --- a/pages/mainwindow.h +++ b/pages/mainwindow.h @@ -8,7 +8,7 @@ #include"pages/page6.h" #include "pages/page4.h" #include"page5.h" -#include "clickable.h" +#include "utilities/clickable.h" #include #include #include diff --git a/pages/page5.cpp b/pages/page5.cpp index 8afeaa7..a0d7b92 100644 --- a/pages/page5.cpp +++ b/pages/page5.cpp @@ -31,7 +31,7 @@ void page5::on_window_size_valueChanged(int arg1) void page5::on_upload_btn_clicked() { - Img= QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpg *.bmp)"); + Img= QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpg *.bmp *.jpeg)"); QImage image(Img); scene = new Scene(); scene->setRad(ui->raduis->value()); @@ -46,7 +46,6 @@ void page5::updateImage(){ ui->graphicsView->setScene(scene); ui->graphicsView->fitInView(scene->sceneRect(),Qt::KeepAspectRatio); } - } @@ -73,12 +72,13 @@ void page5::resizeEvent(QResizeEvent *e) void page5::on_generate_btn_clicked() { + Mat imageCv= cv::imread(Img.toStdString(),IMREAD_COLOR); Mat output; Point center= Point_(scene->getCenter().x(), scene->getCenter().y()); vector s_vector =snake::active_contour(imageCv,output,center,ui->raduis->value(),ui->numItr->value(),ui->num_points->value(), - ui->window_size->value(),ui->alpha->value(),ui->beta->value(),ui->gamma->value(),ui->output_label); + ui->window_size->value(),ui->alpha->value(),ui->beta->value(),ui->gamma->value()); double area = snake::calculate_contour_area(s_vector); double perimeter=snake::calculate_contour_perimeter(s_vector); @@ -87,13 +87,10 @@ void page5::on_generate_btn_clicked() ui->area->setValue(area); ui->perimeter->setValue(perimeter); -// QImage qimage(output.data, output.cols, output.rows,output.step,QImage::Format_BGR888); -// QPixmap* image = new QPixmap(QPixmap::fromImage(qimage)); -// int w = ui->output_label->width(); -// int h = ui->output_label->height(); -// ui->output_label->setPixmap(image->scaled(w,h,Qt::KeepAspectRatio)); - - - + QImage qimage(output.data, output.cols, output.rows,output.step,QImage::Format_BGR888); + QPixmap* image = new QPixmap(QPixmap::fromImage(qimage)); + int w = ui->output_label->width(); + int h = ui->output_label->height(); + ui->output_label->setPixmap(image->scaled(w,h,Qt::KeepAspectRatio)); } diff --git a/pages/page5.h b/pages/page5.h index d9936eb..589bb67 100644 --- a/pages/page5.h +++ b/pages/page5.h @@ -2,7 +2,7 @@ #define PAGE5_H #include -#include "Scene.h" +#include "utilities/scene.h" #include #include #include "CV/snake.h" diff --git a/pages/page5.ui b/pages/page5.ui index 693cf52..4ccfc81 100644 --- a/pages/page5.ui +++ b/pages/page5.ui @@ -88,7 +88,7 @@ - 200 + 1000 50 @@ -222,6 +222,9 @@ 2 + + 11 + @@ -248,10 +251,18 @@ - + + + 3.000000000000000 + + - + + + 10.000000000000000 + + @@ -259,7 +270,7 @@ 1000 - 99 + 300 @@ -287,7 +298,11 @@ - + + + 1.000000000000000 + + diff --git a/resources.qrc b/resources.qrc index fa82b8a..1cfde10 100644 --- a/resources.qrc +++ b/resources.qrc @@ -5,6 +5,7 @@ resources/default.png resources/handpointing.png resources/textcursor.png + style/Cstartpage.qss resources/icons8-upload-32.png diff --git a/clickable.cpp b/utilities/clickable.cpp similarity index 100% rename from clickable.cpp rename to utilities/clickable.cpp diff --git a/clickable.h b/utilities/clickable.h similarity index 100% rename from clickable.h rename to utilities/clickable.h diff --git a/qcustomplot.cpp b/utilities/qcustomplot.cpp similarity index 100% rename from qcustomplot.cpp rename to utilities/qcustomplot.cpp diff --git a/qcustomplot.h b/utilities/qcustomplot.h similarity index 100% rename from qcustomplot.h rename to utilities/qcustomplot.h diff --git a/scene.cpp b/utilities/scene.cpp similarity index 82% rename from scene.cpp rename to utilities/scene.cpp index c53fad5..bca39a4 100644 --- a/scene.cpp +++ b/utilities/scene.cpp @@ -33,7 +33,7 @@ QPointF Scene::getCenter() void Scene::drawCircle() { - this->addEllipse(this->center.x()-0.5*this->rad, this->center.y()-0.5*this->rad, this->rad*1.0, this->rad*1.0, + this->addEllipse(this->center.x()-this->rad, this->center.y()-this->rad, this->rad*2.0, this->rad*2.0, QPen()); } diff --git a/scene.h b/utilities/scene.h similarity index 100% rename from scene.h rename to utilities/scene.h