Skip to content

zakaria-chahboun/QtOpencvHistograms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QtOpenCvHistograms Easy

ZAKARIA CHAHBOUN

QtOpenCvHistogram is a C++ class for make a beautiful histograms without complication!

Using Qt5 framework and OpenCv 3.x.

And of course for both histograms type : Cumulative & Normal.

You can put a colored (BGR/RGB) or a grayscale image! 👍

  • Requirement:
#include <cvtoqt.h>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>

cvtoqt class is my class for convert image from OpenCv to QImage or QPixmap 😉


The QtCvHistogram class - has two static methods:

static QVector<cv::Mat> calculation(cv::Mat im1, bool cumul = false);
static QVector<QPixmap> draw(QVector<cv::Mat> hist, QSize imSize = QSize(512,400), bool fill=true, QColor backColor = QColor(255,255,255));

Explanation:

  • First static method for Calculing the histogram image:

    • Parameter 1: The input image.
    • Parameter 2: (Optional) is Cumulative or Not?.
    • Return a QVector of cv::Mat.
  • Second static method for Drawing the histogram image:

    • Parameter 1: The Histogram vector from Calculation function.
    • Parameter 2: (Optional) Size of output image(s)
    • Parameter 3: (Optional) Histogram curve filled or not.
    • Parameter 4: (Optional) Background color.
    • Return a QVector of QPixmap:

The functions return: 3 objects for colored image (Three channels R-G-B), or 1 object for grayscale image.

Checking Errors:

If calculation mathod return a void vector: calculation(...).size() == 0 it's an error! ⛔

Examples:

    // Load Your Image
    cv::Mat image = cv::imread("/home/zaki/Pictures/05.jpg");
    // Calculate the histograms
    QVector<cv::Mat> calc = QtCvHistogram::calculation(image,true);
    // Get histograms images
    QVector<QPixmap> draw = QtCvHistogram::draw(calc);

    /* Checking Errors */
    if(calc.size() == 0){
      qDebug() << "Error!!";
      return;
    }
    
    /* If a single channel image (Grayscale) */
    if(calc.size() == 1)
      ui->label->setPixmap(draw[0]);
    
    /* If a normal colord image (RBG)*/
    else{
      ui->label->setPixmap(draw[0]); //Red
      ui->label_2->setPixmap(draw[1]); //Blue
      ui->label_3->setPixmap(draw[2]); //Green
      ui->label_4->setPixmap(draw[3]); // All curves in one image :)
      }
You can simplify steps using auto in modern C++
    auto calc = QtCvHistogram::calculation(image,true);
    auto draw = QtCvHistogram::draw(calc);

ScreenShots:

  • Colored Image: Cumulative Histogram and Filled

  • Colored Image: Normal Histogram and not Filled

  • Grayscale Image:

  • an Other style: Black background!


ZAKI | ZAKARIA CHAHBOUN
19/05/2018 | 15:11
22/08/2018 | 03:35

Tesed on Windows and Manjaro Linux ❤️

@Zaki_Chahboun
Zakaria Chahboun
Zakaria.Chahboun.1996@Gmail.Com

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages