Commits

iorodeo committed be811c5

Got preliminary version of histogram display working.

Comments (0)

Files changed (3)

src/gui/camera_window.cpp

 
     void CameraWindow::updateImageDisplay()
     {
+        QPointer<QWidget> currTabPtr = tabWidgetPtr_ -> currentWidget();
+        bool isHistogramTab = (currTabPtr == histogramTabPtr_);
+
         // Get information from image dispatcher
+        // ---------------------------------------------------------------
         imageDispatcherPtr_ -> acquireLock();
-        cv::Mat mat = imageDispatcherPtr_ -> getImage();
-        QImage img = matToQImage(mat);
+
+        cv::Mat imgMat = imageDispatcherPtr_ -> getImage();
+        QImage img = matToQImage(imgMat);
         double fps = imageDispatcherPtr_ -> getFPS();
         double stamp = imageDispatcherPtr_ -> getTimeStamp();
         frameCount_ = imageDispatcherPtr_ -> getFrameCount();
+        cv::Mat histMat = (isHistogramTab) ? calcHistogram(imgMat) : cv::Mat();
 
-        // ---------------------------------
-        // TO DO ... temporary
-        //
-        // Calculate image histogram
-        // ---------------------------------
-        //int channels[] = {0};
-        //int histSize[] = {256};
-        //float dimRange[] = {0,256};
-        //const float *ranges[] = {dimRange};
-        //cv::Mat hist;
-        //cv::calcHist(&mat, 1, channels, cv::Mat(), hist, 1, histSize, ranges, true, false);
-        //cv::Size size = hist.size();
-
-        //for (int i=0; i<size.height; i++)
-        //{
-        //    std::cout << hist.at<float>(0,i) << " ";
-        //}
-        //std::cout << std::endl << std::endl;
-        // ---------------------------------
         imageDispatcherPtr_ -> releaseLock();
+        // ---------------------------------------------------------------
 
         // Update preview image
         if (!img.isNull()) 
 
         // TO DO ... Update plugin image
 
-        // TO DO .. Update histogram image
+        // Update histogram image
+        if (isHistogramTab)
+        {
+            updateHistogramPixmap(histMat);
+            updateImageLabel(histogramImageLabelPtr_, histogramPixmapOriginal_, false);
+        }
 
         // Update statusbar message
         QString statusMsg("Capturing,  logging = ");
         resizeImageLabel(histogramImageLabelPtr_, histogramPixmapOriginal_, false);
     }
 
+    void CameraWindow::updateHistogramPixmap(cv::Mat hist)
+    {
+        QImage dummyImage = QImage(DEFAULT_HISTOGRAM_IMAGE_SIZE,QImage::Format_RGB888);
+        dummyImage.fill(QColor(Qt::gray).rgb());
+        histogramPixmapOriginal_ = QPixmap::fromImage(dummyImage);
+
+        QPainter painter(&histogramPixmapOriginal_);
+        painter.setPen(QColor(50,50,50));
+        cv::Size histSize = hist.size();
+
+        float histImageMaxY = float(DEFAULT_HISTOGRAM_IMAGE_SIZE.height() - 1.0);
+
+        for (int i=0; i<histSize.height; i++) 
+        {
+            int y0 = int(histImageMaxY);
+            int y1 = int(histImageMaxY - hist.at<float>(0,i));
+            painter.drawLine(i,y0,i,y1);
+        }
+
+    }
+
     void CameraWindow::connectCamera() 
     {
         bool error = false;
         captureTimeLabelPtr_ -> setText(stampString);
     }
 
+    // Development
+    // ----------------------------------------------------------------------------------
+    cv::Mat CameraWindow::calcHistogram(cv::Mat mat)
+    {
+        // -----------------------------------------------------------------------------
+        // TO DO  - only for 8bit black and white cameras needs modification for color.
+        // -----------------------------------------------------------------------------
+        int channels[] = {0};
+        int histSize[] = {256};
+        float dimRange[] = {0,256}; // need to be set based on image type.
+        const float *ranges[] = {dimRange};
+        double minVal = 0;
+        double maxVal = 0;
+        double histImageMaxY = DEFAULT_HISTOGRAM_IMAGE_SIZE.height() - 1.0;
+
+        cv::Mat hist;
+        cv::calcHist(&mat, 1, channels, cv::Mat(), hist, 1, histSize, ranges, true, false);
+        minMaxLoc(hist,&minVal,&maxVal,NULL,NULL);
+        hist = hist*(float(histImageMaxY)/float(maxVal));
+        return hist;
+    }
+
 
     // Utility functions
     // ----------------------------------------------------------------------------------

src/gui/camera_window.hpp

 #include "camera_facade_fwd.hpp"
 
 
-// Qt forward declarations
+// External lib forward declarations
 class QTimer;
 class QThreadPool;
+namespace cv   { class Mat; }
 
 namespace bias 
 {
                     );
             void resizeAllImageLabels();
 
+            void updateHistogramPixmap(cv::Mat hist);
+
             void deleteMenuActions(QMenu *menuPtr);
             void setCameraInfoMessage(QString vendorName, QString modelName);
             void setMenuChildrenEnabled(QWidget *parentWidgetPtr, bool value);
             void setCaptureTimeLabel(double timeStamp);
 
+            // Development
+            cv::Mat calcHistogram(cv::Mat mat);
+
+
     }; // class CameraWindow
 
 
     // Utilitiy functions
     QString boolToOnOffQString(bool value);
     QString timeStampToQString(double timeStamp);
+
 }
 
 #endif // #ifndef BIAS_GUI_CAMERA_WINDOW_HPP

src/gui/camera_window.ui

             <height>50</height>
            </size>
           </property>
+          <property name="frameShape">
+           <enum>QFrame::NoFrame</enum>
+          </property>
+          <property name="frameShadow">
+           <enum>QFrame::Plain</enum>
+          </property>
           <property name="text">
            <string/>
           </property>
             <height>50</height>
            </size>
           </property>
+          <property name="frameShape">
+           <enum>QFrame::NoFrame</enum>
+          </property>
+          <property name="frameShadow">
+           <enum>QFrame::Plain</enum>
+          </property>
           <property name="text">
-           <string>Plugin Not Enabled</string>
+           <string/>
           </property>
           <property name="alignment">
            <set>Qt::AlignCenter</set>
           <property name="frameShape">
            <enum>QFrame::NoFrame</enum>
           </property>
+          <property name="frameShadow">
+           <enum>QFrame::Plain</enum>
+          </property>
           <property name="text">
            <string/>
           </property>