void MainWindow::load_img()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "/home", tr("Images (*.png *.xpm *.jpg)"));
    QImage img(16, 16, QImage::Format_RGB32);
    img.load(fileName);
    ui->label->setPixmap(QPixmap::fromImage(img));
    ui->label->show();
    std::vector<double> data;
    for ( int row = 0; row < img.height(); ++row )
        for ( int col = 0; col < img.width(); ++col )
        {
            QColor clrCurrent( img.pixel( row, col ) );
            if ((clrCurrent.red()==255)&&(clrCurrent.green()==255)&&(clrCurrent.blue()==255))
                data.push_back(1);
            else
                data.push_back(0);
        }
    std::vector<char> return_classify = perceptron_->classify(data);
    int result;
    for (size_t i = 0; i < return_classify.size();++i)
        if (return_classify[i] == 1)
            result = i;
    QString valueAsString = QString::number(result);
    ui->textEdit->append(valueAsString);
}
Exemple #2
0
int main(int argc, char **argv)
{
    QApplication a(argc, argv);
    QString fileName = QFileDialog::getOpenFileName(0, "Select image from file", QDir::homePath(), "Files (*.png *.jpg *.jpeg *.bmp)");
    QImage image = QImage(fileName, "PNM");
    image = ConvertToBlackWhite(image);

    std::vector<double> peoples;  
    for (int y = 0; y <image.height(); y++)
    {
       for (int x = 0; x < image.width(); x++)
       {
            QColor clrCurrent(image.pixel(x, y));
            if((int)clrCurrent.blue() == 0)
            {
                HumanSilhouetteProbability * humanSilhouettes = new HumanSilhouetteProbability(&image);
                humanSilhouettes->SetObjectCoordinate(x,y);
                humanSilhouettes->CalculateHumanHeadProbability();
                humanSilhouettes->CalculateHumanCorpusProbability();
                humanSilhouettes->CalculateHumanLegsProbability();
                double percentageSimilarity = humanSilhouettes->GetResult();
                if(percentageSimilarity!=0)
                {
                     peoples.push_back(percentageSimilarity);
                }
                delete humanSilhouettes;
            }
       }
    }
    ShowPeoples(peoples);
    return a.exec();
}
Exemple #3
0
QImage  ConvertToBlackWhite(QImage image)
{
    QImage imageExit=QImage(image.width(),image.height(),QImage::Format_ARGB32_Premultiplied);
    for (int y = 0; y <image.height(); y++)
    {
       for (int x = 0; x < image.width(); x++)
       {
          QColor clrCurrent(image.pixel(x, y));
            if((int)clrCurrent.red()<122 || (int)clrCurrent.green()<122 || (int)clrCurrent.blue()<122)
            {
                 imageExit.setPixel(x,y, QColor(Qt::black).rgb());
            }
            else
            {
                 imageExit.setPixel(x,y, QColor(Qt::white).rgb());
            }
       }
   }
    return imageExit;
}
/* Bianrisation seuillage automatique: Otsu */
QImage binarisationautre(QImage image) {

    for ( int row = 0; row < image.height(); row++ ) {
        for ( int col = 0; col < image.width(); col++ )
        {
            QColor clrCurrent( image.pixel( col, row ) );

            int red = clrCurrent.red();
            int green = clrCurrent.green();
            int blue = clrCurrent.blue();

            if (red >100 && green>100 && blue>100) {
                image.setPixel(col, row, qRgb(255,255,255));
            }
            else image.setPixel(col, row, qRgb(0,0,0));
        }
    }

    return image;
}
QImage Utils::applyHomography(MatrixXd H, QImage inputImage, QList<Dot*> region)
{
    MatrixXd x(3,1);
    MatrixXd y(3,1);
    vector<double> x_values;
    vector<double> y_values;

    int height_output = 454;
    int width_output = 604;

    // Calculate output image corners
    x << region.at(0)->x(), region.at(0)->y(), 1;
    y = H*x;
    x_values.push_back(y(0,0)/y(2,0));
    y_values.push_back(y(1,0)/y(2,0));

    x << region.at(1)->x(), region.at(1)->y(), 1;
    y = H*x;
    x_values.push_back(y(0,0)/y(2,0));
    y_values.push_back(y(1,0)/y(2,0));

    x << region.at(2)->x(), region.at(2)->y(), 1;
    y = H*x;
    x_values.push_back(y(0,0)/y(2,0));
    y_values.push_back(y(1,0)/y(2,0));

    x << region.at(3)->x(), region.at(3)->y(), 1;
    y = H*x;
    x_values.push_back(y(0,0)/y(2,0));
    y_values.push_back(y(1,0)/y(2,0));

    double max_x = (*max_element(x_values.begin(), x_values.end()));
    double min_x = (*min_element(x_values.begin(), x_values.end()));
    double max_y = (*max_element(y_values.begin(), y_values.end()));
    double min_y = (*min_element(y_values.begin(), y_values.end()));
    height_output = width_output / ((max_x-min_x)/(max_y-min_y));

    QImage outputImage(width_output, height_output, QImage::Format_ARGB32);
    QPainter painter;
    painter.begin(&outputImage);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBackgroundMode(Qt::TransparentMode);
    QPen pen;

    H = H.inverse().eval();

    double step = (max_x - min_x) / width_output;

    for (int i=0; i < height_output; i++)
    {
        for (int j=0; j<width_output; j++)
        {
            x << min_x+j*step, min_y+i*step, 1;
            y = H*x;

            y << y(0,0)/y(2,0), y(1,0)/y(2,0), 1;

            if (y(0,0) >= 0 && y(0,0) <= inputImage.width() - 1
                    && y(1,0) >= 0 && y(1,0) <= inputImage.height() - 1)
            {
                // Point lies inside the input Image

                // Do interpolation
                QColor c = interpolate(inputImage, y);
                //QRgb clrCurrent( inputImage.pixel( y(0,0), y(1,0) ) );
                pen.setColor(c);
                pen.setWidth(1);
                pen.setCapStyle(Qt::RoundCap);
                painter.setPen(pen);
                painter.drawPoint(j, i);

            }
            else
            {
                // Point lies outside the input Image
                QColor clrCurrent(0,0,0);
                pen.setColor(clrCurrent);
                pen.setWidth(1);
                pen.setCapStyle(Qt::RoundCap);
                painter.setPen(pen);
                painter.drawPoint(j, i);
            }
        }
    }
    painter.end();
    return outputImage;
}
QImage Triangledetection::detect(const QImage &source, const QImage &imageBase)
{
    //QImage binary = detectionContour(extraireRouge(source));
    QImage binary = detectionContour(source);
    QImage detection = binary.convertToFormat(QImage::Format_RGB888);

    QVector<QPoint> ligne = hough(detection);
    std::cout << "-> Nombre de ligne detecté : " << ligne.size() << std::endl;

    QVector<QPoint> ligne_angle0,ligne_angle60,ligne_angle120;
    QPoint inter1,inter2,inter3;
    int l1,l2,l3;



    //Avoir les lignes avec des angles pouvant appartenir à un panneau (+ ou - 1°)
    avoirLigneAngle(ligne,ligne_angle0,90,1);
    avoirLigneAngle(ligne,ligne_angle0,270,1);

    avoirLigneAngle(ligne,ligne_angle60,150,1);
    avoirLigneAngle(ligne,ligne_angle60,330,1);

    avoirLigneAngle(ligne,ligne_angle120,210,1);
    avoirLigneAngle(ligne,ligne_angle120,30,1);

    //On determine les intersections et les longueurs des segments
    for(int i=0;i<ligne_angle0.size();i++)
    {
        for(int j=0;j<ligne_angle60.size();j++)
        {
            for(int k=0;k<ligne_angle120.size();k++)
            {

                inter1 = intersection(ligne_angle0[i],ligne_angle60[j]);
                inter2 = intersection(ligne_angle60[j],ligne_angle120[k]);
                inter3 = intersection(ligne_angle120[k],ligne_angle0[i]);

                l1 = distance(inter1,inter2);
                l2 = distance(inter2,inter3);
                l3 = distance(inter3,inter1);

                //Si les distance sont les mêmes et que tous les points sont dans l'image => on a un triangle
                if(l1 == l2 && l2 == l3 && l1 > 30 && l1 < 100 && estPointImage(detection,inter1) && estPointImage(detection,inter2) && estPointImage(detection,inter3))
                {
                    Triangle a;
                    a.p1 = inter1;
                    a.p2 = inter2;
                    a.p3 = inter3;
                    liste_triangle.push_back(a);
                }
            }
        }
    }

    std::cout<<"-> Nombre de triangle detectés avant élimination des doublons : " << liste_triangle.size() << std::endl;

    //On supprime les triangle doublons
    supprimerDoublon();

    //Dessiner les triangles à l'écran
    for(int i=0;i<liste_triangle.size();i++)
        dessiner(detection,liste_triangle[i],qRgb(0,255,127));


    //Generer les images avec les cercles reconnus
    for(int i=0;i<liste_triangle.size();i++)
    {
        int minX = liste_triangle[i].p1.x();
        int minY = liste_triangle[i].p1.y();
        int maxX = liste_triangle[i].p1.x();
        int maxY = liste_triangle[i].p1.y();
        if (liste_triangle[i].p2.x()<minX) minX = liste_triangle[i].p2.x();
        if (liste_triangle[i].p2.y()<minY) minY = liste_triangle[i].p2.y();
        if (liste_triangle[i].p2.x()>maxX) maxX = liste_triangle[i].p2.x();
        if (liste_triangle[i].p2.y()>maxY) maxY = liste_triangle[i].p2.y();
        if (liste_triangle[i].p3.x()<minX) minX = liste_triangle[i].p3.x();
        if (liste_triangle[i].p3.y()<minY) minY = liste_triangle[i].p3.y();
        if (liste_triangle[i].p3.x()>maxX) maxX = liste_triangle[i].p3.x();
        if (liste_triangle[i].p3.y()>maxY) maxY = liste_triangle[i].p3.y();


        QImage BlueRoadSigns = QImage(maxX-minX, maxY-minY, QImage::Format_RGB32);

        for(int row = 0;row<maxY-minY;row++)
        {
            for (int col=0;col<maxX-minX;col++)
            {
                QColor clrCurrent(imageBase.pixel(col+minX,row+minY));

                int red = clrCurrent.red();
                int green = clrCurrent.green();
                int blue = clrCurrent.blue();

                BlueRoadSigns.setPixel(col, row, qRgb(red,green,blue));
            }
        }

        liste_TrianglesReconnu.push_back(BlueRoadSigns);
    }

    std::cout<<"-> Nombre de triangle detectés : " << liste_triangle.size() << std::endl;

    return detection;
}