Skip to content

Commit

Permalink
finish roc curve
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef-shaban committed May 16, 2023
1 parent 250282a commit 39bab81
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 13 deletions.
17 changes: 8 additions & 9 deletions CV-Toolbox.pro
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ FORMS += \
pages/thresholding_page.ui


INCLUDEPATH += C:\Users\youss\Documents\libraries\opencv\build\include

INCLUDEPATH += C:\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:\opencv\release\bin\libopencv_objdetect470.dll
LIBS += C:\Users\youss\Documents\libraries\opencv\release\bin\libopencv_core470.dll
LIBS += C:\Users\youss\Documents\libraries\opencv\release\bin\libopencv_highgui470.dll
LIBS += C:\Users\youss\Documents\libraries\opencv\release\bin\libopencv_imgcodecs470.dll
LIBS += C:\Users\youss\Documents\libraries\opencv\release\bin\libopencv_imgproc470.dll
LIBS += C:\Users\youss\Documents\libraries\opencv\release\bin\libopencv_features2d470.dll
LIBS += C:\Users\youss\Documents\libraries\opencv\release\bin\libopencv_calib3d470.dll
LIBS += C:\Users\youss\Documents\libraries\opencv\release\bin\libopencv_objdetect470.dll


# Default rules for deployment.
Expand Down
56 changes: 54 additions & 2 deletions Plot/plotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,60 @@ void plotter::plotROC(QCustomPlot* graph,std::pair<std::vector<float>,std::vecto
graph->addGraph();
plot->setData(FPRs,TPRs);

graph->yAxis->setRange(0,1.5);
graph->xAxis->setRange(0,1.5);
graph->yAxis->setRange(0,1);
graph->xAxis->setRange(0,1);
graph->xAxis->setLabel("False positive Rate");
graph->yAxis->setLabel("True Positive Rate");
QCPItemLine *line = new QCPItemLine(graph);
line->start->setCoords(0,0);
line->end->setCoords(1,1);
QPen pen2(Qt::red);
pen2.setStyle(Qt::DashLine);
line->setPen(pen2);



graph->replot();
}

void plotter::plotAllROC(QCustomPlot *graph, std::vector<std::pair<std::vector<float>, std::vector<float> > > ROC, std::unordered_map<int, std::string> LabelToPerson)
{
graph->clearPlottables();
for(int i = 0; i < ROC.size(); i++){
QVector<double> FPRs;
for (const auto& value : ROC[i].first) {
FPRs.append(value);
}

QVector<double> TPRs;
for (const auto& value : ROC[i].second) {
TPRs.append(value);
}

int red = QRandomGenerator::global()->bounded(256);
int green = QRandomGenerator::global()->bounded(256);
int blue = QRandomGenerator::global()->bounded(256);

QColor plotColor = QColor(red, green, blue);

QCPGraph *plot = new QCPGraph(graph->xAxis, graph->yAxis);
QPen pen(plotColor);
plot->setPen(pen);
plot->setData(FPRs,TPRs);
plot->setName(QString::fromStdString(LabelToPerson[i]));
}


graph->yAxis->setRange(0,1);
graph->xAxis->setRange(0,1);
graph->xAxis->setLabel("False positive Rate");
graph->yAxis->setLabel("True Positive Rate");
QCPItemLine *line = new QCPItemLine(graph);
line->start->setCoords(0,0);
line->end->setCoords(1,1);
QPen pen2(Qt::red);
pen2.setStyle(Qt::DashLine);
line->setPen(pen2);
graph->legend->setVisible(true);
graph->replot();
}
1 change: 1 addition & 0 deletions Plot/plotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class plotter
public:
static void plotHist(QCustomPlot* graph, QVector<double>& data, Qt::GlobalColor color);
static void plotROC(QCustomPlot* graph,std::pair<std::vector<float>,std::vector<float>>ROC);
static void plotAllROC(QCustomPlot* graph,std::vector<std::pair<std::vector<float>,std::vector<float>>> ROC, std::unordered_map<int, std::string> LabelToPerson);
};

#endif // PLOTTER_H
21 changes: 19 additions & 2 deletions pages/page11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ void page11::readImages(std::string folderPath, cv::Mat& images, std::vector<std
{
comboItems.push_front(QString::fromStdString(it->first));
}
comboItems.sort();
ui->comboBox_2->addItems(comboItems);
ui->comboBox_2->addItem("All");

}
images.convertTo(images, CV_32F);
Expand Down Expand Up @@ -213,9 +215,24 @@ void page11::on_testUploadBtn_clicked()

void page11::on_comboBox_2_currentIndexChanged(int index)
{
if(!testFolderPath.isEmpty()){
plotter::plotROC(ui->widget,ROC[index]);
if(!testFolderPath.isEmpty() ){
if(ui->comboBox_2->currentText().toStdString() != "All"){
std::pair<std::vector<float>, std::vector<float>> curve = ROC[fr->personToLabelmapper[ui->comboBox_2->currentText().toStdString()]];
plotter::plotROC(ui->widget,curve);

double area = 0.0;
int n = curve.first.size();

for (int i = 1; i < n; ++i) {
double base = curve.second[i] - curve.second[i - 1];
double height = (curve.first[i] + curve.first[i - 1]) / 2.0;
area += base * height;
}
ui->aucLabel->setText(QString::fromStdString("AUC = " + std::to_string((1 + area)*100 ) + "%"));}

else {
plotter::plotAllROC(ui->widget, ROC, fr->labelToPersonMapper);
}
}
// fr->personToLabelmapper
}
Expand Down
7 changes: 7 additions & 0 deletions pages/page11.ui
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
<item>
<widget class="QComboBox" name="comboBox_2"/>
</item>
<item>
<widget class="QLabel" name="aucLabel">
<property name="text">
<string>AUC = </string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down

0 comments on commit 39bab81

Please sign in to comment.