#ifndef FENETREPRINCIPALE_H
#define FENETREPRINCIPALE_H
#include <QtWidgets>
{
Q_OBJECT
public :
FenetrePrincipale();
public slots :
void ouvrir();
void traiterOtsu();
private:
};
#endif // FENETREPRINCIPALE_H
#ifndef FENETREPRINCIPALE_H
#define FENETREPRINCIPALE_H
#include <QtWidgets>
class FenetrePrincipale : public QMainWindow
{
Q_OBJECT
public :
FenetrePrincipale();
public slots :
void ouvrir();
void traiterOtsu();
private:
QImage *image;
QLabel *label;
QString nomFichier;
QWidget fentroi;
QWidget fenSec;
};
#endif // FENETREPRINCIPALE_H
To copy to clipboard, switch view to plain text mode
fenetrePrincipale.cpp
#include "otsu.h"
#include "fenetreprincipale.h"
{
label->setGeometry(100,100,400,400);
QMenu *menuFichier
= menuBar
()->addMenu
("Fichier");
menuFichier->addAction(actionOuvrir);
menuFichier->addAction(actionQuitter);
QMenu *menuTraitement
= menuBar
()->addMenu
("Traitement");
menuTraitement->addAction(actionBinarisation);
QObject::connect(actionOuvrir,
SIGNAL(triggered
(bool)),
this,
SLOT(ouvrir
()));
QObject::connect(actionQuitter,
SIGNAL(triggered
(bool)),
this,
SLOT(close
()));
QObject::connect(actionBinarisation,
SIGNAL(triggered
(bool)),
this,
SLOT(traiterOtsu
()));
}
void FenetrePrincipale::ouvrir()
{
nomFichier
= QFileDialog::getOpenFileName(this, tr
("Open File"),
"C:/Users/amine/Downloads");
image
= new QImage(nomFichier
);
pixmap.convertFromImage(*image);
label->setPixmap(pixmap);
fentroi.show(); // fentroi (fenetre qui affiche l'image) attribut de fenetre principale
label->update();
}
void FenetrePrincipale::traiterOtsu()
{
QVector<Position> v;
OtsuAlgo traitement(nomFichier);
traitement.traiter(nomFichier);
traitement.binarisation();
label1->setGeometry(100,100, 400, 400);
label1
->setPixmap
(QPixmap::fromImage(*im
));
lcd->move(70,70);
lcd->display(traitement.getSeuil());
fenSec.show();
traitement.detection();
traitement.centrer();
v = traitement.getCentres();
QFile monFichier
("C:/Users/amine/Downloads/essai.txt");
if (!monFichier.
open(QIODevice::WriteOnly|QIODevice
::Text)) return;
for(int i=0;i< v.size();i++)
{
flux << "i " << v[i].getI() << " " << "j " << v[i].getJ() << endl;
}
for (int i=0;i<v.size();i++)
{
painter.setPen(pen);
painter.begin(image);
painter.drawPoint(v[i].getI(),v[i].getJ());
painter.end();
}
}
#include "otsu.h"
#include "fenetreprincipale.h"
FenetrePrincipale::FenetrePrincipale(): QMainWindow()
{
label =new QLabel(&fentroi);
label->setGeometry(100,100,400,400);
QMenu *menuFichier = menuBar()->addMenu("Fichier");
QAction *actionOuvrir = new QAction("Ouvrir", this);
QAction *actionQuitter = new QAction("Quitter", this);
menuFichier->addAction(actionOuvrir);
menuFichier->addAction(actionQuitter);
QMenu *menuTraitement = menuBar()->addMenu("Traitement");
QAction *actionBinarisation = new QAction("Binarisation", this);
menuTraitement->addAction(actionBinarisation);
QObject::connect(actionOuvrir, SIGNAL(triggered(bool)), this, SLOT(ouvrir()));
QObject::connect(actionQuitter, SIGNAL(triggered(bool)), this, SLOT(close()));
QObject::connect(actionBinarisation, SIGNAL(triggered(bool)), this, SLOT(traiterOtsu()));
}
void FenetrePrincipale::ouvrir()
{
nomFichier = QFileDialog::getOpenFileName(this, tr("Open File"),"C:/Users/amine/Downloads");
image = new QImage(nomFichier);
QPixmap pixmap;
pixmap.convertFromImage(*image);
label->setPixmap(pixmap);
fentroi.show(); // fentroi (fenetre qui affiche l'image) attribut de fenetre principale
label->update();
}
void FenetrePrincipale::traiterOtsu()
{
QVector<Position> v;
OtsuAlgo traitement(nomFichier);
traitement.traiter(nomFichier);
traitement.binarisation();
QImage *im = new QImage(traitement.getImage());
QLabel *label1 = new QLabel(&fenSec);
label1->setGeometry(100,100, 400, 400);
label1->setPixmap(QPixmap::fromImage(*im));
QLCDNumber *lcd = new QLCDNumber(&fenSec);
lcd->move(70,70);
lcd->setSegmentStyle(QLCDNumber::Flat);
lcd->display(traitement.getSeuil());
fenSec.show();
traitement.detection();
traitement.centrer();
v = traitement.getCentres();
QFile monFichier("C:/Users/amine/Downloads/essai.txt");
if (!monFichier.open(QIODevice::WriteOnly|QIODevice::Text))
return;
QTextStream flux(&monFichier);
for(int i=0;i< v.size();i++)
{
flux << "i " << v[i].getI() << " " << "j " << v[i].getJ() << endl;
}
for (int i=0;i<v.size();i++)
{
QPainter painter;
QPen pen(Qt::blue);
painter.setPen(pen);
painter.begin(image);
painter.drawPoint(v[i].getI(),v[i].getJ());
painter.end();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks