Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Declaration of function and use it
Forum Updated to NodeBB v4.3 + New Features

Declaration of function and use it

Scheduled Pinned Locked Moved Unsolved General and Desktop
93 Posts 4 Posters 60.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G gauravsharma0190

    @jsulm Yes sir see i have a c code of opencv which process the image.
    Now my problem is i want to use this code with qt as when button is pressed my push button calls the function of that C code in which main part of Process is defined.
    Here is the C code.
    #include "opencv2/imgproc/imgproc.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include <stdlib.h>
    #include <stdio.h>

    using namespace cv;

    /// Global variables

    Mat src, src_gray;
    Mat dst, detected_edges;

    int edgeThresh = 1;
    int lowThreshold;
    int const max_lowThreshold = 100;
    int ratio = 3;
    int kernel_size = 3;
    char* window_name = "Edge Map";

    /**

    @function CannyThreshold
    @brief Trackbar callback - Canny thresholds input with a ratio 1:3
    /
    void CannyThreshold(int, void)
    {
    /// Reduce noise with a kernel 3x3
    blur( src_gray, detected_edges, Size(3,3) );
    /// Canny detector
    Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

    /// Using Canny's output as a mask, we display our result
    dst = Scalar::all(0);

    src.copyTo( dst, detected_edges);
    imshow( window_name, dst );
    }

    /** @function main /
    int main( int argc, char* argv )
    {
    /// Load an image
    src = imread( argv[1] );

    if( !src.data )
    { return -1; }

    /// Create a matrix of the same type and size as src (for dst)
    dst.create( src.size(), src.type() );

    /// Convert the image to grayscale
    cvtColor( src, src_gray, CV_BGR2GRAY );

    /// Create a window
    namedWindow( window_name, CV_WINDOW_AUTOSIZE );

    /// Create a Trackbar for user to enter threshold
    createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );

    /// Show the image
    CannyThreshold(0, 0);

    /// Wait until user exit program by pressing a key
    waitKey(0);

    return 0;
    }
    Now i make a Push button Name Process_image in MainWindow.ui and connect to slot as clicked() by right clicking of mouse.
    here comes the slot to mainwindow.cpp
    void mainwidow::Process_image_clicke()
    {
    }
    Now i don't understand how to make function of my C code and use it in Pusebutton.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #23

    @gauravsharma0190 Well, you can put that C code in

    void mainwidow::Process_image_clicke()
    {
        // Put C code here
    }
    

    But I'm not sure whether you should remove waitKey(0); as it could be problematic in a Qt program.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    G 1 Reply Last reply
    2
    • jsulmJ jsulm

      @gauravsharma0190 Well, you can put that C code in

      void mainwidow::Process_image_clicke()
      {
          // Put C code here
      }
      

      But I'm not sure whether you should remove waitKey(0); as it could be problematic in a Qt program.

      G Offline
      G Offline
      gauravsharma0190
      wrote on last edited by
      #24

      @jsulm
      i put it into Process_image_click()
      {
      //code
      }
      but error occurs.
      as ontrackball function not declare

      jsulmJ 1 Reply Last reply
      0
      • G gauravsharma0190

        @jsulm
        i put it into Process_image_click()
        {
        //code
        }
        but error occurs.
        as ontrackball function not declare

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #25

        @gauravsharma0190 What is ontrackball? Where is it declared? Do you have to include a header file where it is declared?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        G 1 Reply Last reply
        0
        • G Offline
          G Offline
          gauravsharma0190
          wrote on last edited by
          #26

          Yes it is function which is declare in the Opencv C code.
          Here is the function.
          @brief Trackbar callback - Canny thresholds input with a ratio 1:3
          /
          void onTrackball(int, void)
          {
          /// Reduce noise with a kernel 3x3
          blur( src_gray, detected_edges, Size(3,3) );
          /// Canny detector
          Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

          /// Using Canny's output as a mask, we display our result
          dst = Scalar::all(0);

          src.copyTo( dst, detected_edges);
          imshow( window_name, dst );
          }

          1 Reply Last reply
          0
          • jsulmJ jsulm

            @gauravsharma0190 What is ontrackball? Where is it declared? Do you have to include a header file where it is declared?

            G Offline
            G Offline
            gauravsharma0190
            wrote on last edited by
            #27

            @jsulm Yes it is function which is declare in the Opencv C code.
            Here is the function.
            @brief Trackbar callback - Canny thresholds input with a ratio 1:3
            /
            void onTrackball(int, void)
            {
            /// Reduce noise with a kernel 3x3
            blur( src_gray, detected_edges, Size(3,3) );
            /// Canny detector
            Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

            /// Using Canny's output as a mask, we display our result
            dst = Scalar::all(0);

            src.copyTo( dst, detected_edges);
            imshow( window_name, dst );
            }

            less than a minute ago

            jsulmJ 1 Reply Last reply
            0
            • G gauravsharma0190

              @jsulm Yes it is function which is declare in the Opencv C code.
              Here is the function.
              @brief Trackbar callback - Canny thresholds input with a ratio 1:3
              /
              void onTrackball(int, void)
              {
              /// Reduce noise with a kernel 3x3
              blur( src_gray, detected_edges, Size(3,3) );
              /// Canny detector
              Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

              /// Using Canny's output as a mask, we display our result
              dst = Scalar::all(0);

              src.copyTo( dst, detected_edges);
              imshow( window_name, dst );
              }

              less than a minute ago

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #28

              @gauravsharma0190 Where is this function declared? In which header file? "function not declared" means the function is not known. You have to make it visible including the header file. It is the same story as in C.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              G 2 Replies Last reply
              0
              • jsulmJ jsulm

                @gauravsharma0190 Where is this function declared? In which header file? "function not declared" means the function is not known. You have to make it visible including the header file. It is the same story as in C.

                G Offline
                G Offline
                gauravsharma0190
                wrote on last edited by
                #29

                @jsulm i Declare it in mainwindow.h
                file as void onTrackball.
                and i will send you all my code which i did .

                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @gauravsharma0190 Where is this function declared? In which header file? "function not declared" means the function is not known. You have to make it visible including the header file. It is the same story as in C.

                  G Offline
                  G Offline
                  gauravsharma0190
                  wrote on last edited by
                  #30

                  @jsulm
                  Here i am sending you my all code.
                  **

                  • /////main.cpp///**
                    #include "mainwindow.h"
                    #include <QApplication>
                    #include<QSplashScreen>
                    #include<QTimer>
                    #include<opencv2/highgui/highgui.hpp>
                    #include<opencv2/core/core.hpp>
                    #include<opencv2/opencv.hpp>
                    using namespace cv;
                    using namespace std;
                    int main(int argc, char *argv[])
                    {

                    QApplication a(argc, argv);
                    QSplashScreen *splash =new QSplashScreen;
                    splash->setPixmap(QPixmap("/home/pi/Desktop/ceeri1.jpg"));
                    splash->show();

                    MainWindow w;
                    QTimer::singleShot(3500,splash,SLOT(close()));

                    QTimer::singleShot(3500,&w,SLOT(show()));

                    //w.show();

                    return a.exec();
                    }
                    ////mainwindow.h
                    #ifndef MAINWINDOW_H
                    #define MAINWINDOW_H

                  #include <QMainWindow>
                  //using namespace cv;
                  namespace Ui {
                  class MainWindow;
                  }

                  class MainWindow : public QMainWindow
                  {
                  Q_OBJECT

                  public:
                  explicit MainWindow(QWidget *parent = 0);
                  ~MainWindow();

                  private slots:
                  void showTime();

                  void on_pushButton_5_clicked();
                  

                  void onTrackball_clicked(int,void*);

                  private:
                  Ui::MainWindow *ui;
                  };

                  #endif // MAINWINDOW_H
                  ///mainwindow.c

                  #include "mainwindow.h"
                  #include "ui_mainwindow.h"
                  #include<opencv2/opencv.hpp>
                  #include <opencv2/highgui/highgui.hpp>
                  #include <opencv2/core/core.hpp>
                  #include<QFileDialog>
                  #include<QMessageBox>
                  #include <iostream>
                  #include <string>
                  #include <fstream>
                  #include<time.h>
                  #include<QTimer>
                  #include<QDateTime>
                  using namespace cv;
                  using namespace std;
                  MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
                  {
                  ui->setupUi(this);
                  QTimer *timer=new QTimer(this);
                  connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));
                  timer->start();
                  QDateTime dateTime=QDateTime::currentDateTime();
                  QString datetimetext=dateTime.toString();
                  ui->DateTime->setText(datetimetext);

                  }
                  ////////Time///////////////
                  void MainWindow:: showTime()
                  {
                  QTime time=QTime::currentTime();
                  QString time_text=time.toString("hh : mm : ss");
                  if((time.second() % 2)==0)
                  {
                  time_text[3] =' ';
                  time_text[8] =' ';
                  }
                  ui->Digital->setText(time_text);

                  }

                  MainWindow::~MainWindow()
                  {
                  delete ui;
                  }

                  void MainWindow::on_pushButton_4_clicked()
                  {

                  }

                  void MainWindow::on_pushButton_5_clicked()
                  {
                  QString filename=QFileDialog::getOpenFileName(
                  this,
                  tr("Open file") ,
                  "/home/pi/Desktop",
                  tr("All files(*.png *.jpg)"));

                  QMessageBox::information(this,tr("Filename"),filename);
                  if(QString::compare(filename,QString())!=0)
                  {
                      QImage image;
                      bool valid=image.load(filename);
                      if(valid)
                      {
                          image=image.scaledToWidth(ui->Picture->width(),Qt::SmoothTransformation);
                          ui->Picture->setPixmap(QPixmap::fromImage(image));
                  
                      }
                  

                  void MainWindow::onTrackball_clicked(int,void*)
                  {
                  //Here wite the all function//
                  ///Now how to put this code in this.

                  ////////This is the code i have to input in this push button////
                  Mat src, src_gray;
                  Mat dst, detected_edges;

                  int edgeThresh = 1;
                  int lowThreshold;
                  int const max_lowThreshold = 100;
                  int ratio = 3;
                  int kernel_size = 3;
                  char* window_name = "Edge Map";

                  /**

                  @function CannyThreshold
                  @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                  /
                  void CannyThreshold(int, void)
                  {
                  /// Reduce noise with a kernel 3x3
                  blur( src_gray, detected_edges, Size(3,3) );
                  /// Canny detector
                  Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

                  /// Using Canny's output as a mask, we display our result
                  dst = Scalar::all(0);

                  src.copyTo( dst, detected_edges);
                  imshow( window_name, dst );
                  }

                  /** @function main /
                  int main( int argc, char* argv )
                  {
                  /// Load an image
                  src = imread( argv[1] );

                  if( !src.data )
                  { return -1; }

                  /// Create a matrix of the same type and size as src (for dst)
                  dst.create( src.size(), src.type() );

                  /// Convert the image to grayscale
                  cvtColor( src, src_gray, CV_BGR2GRAY );

                  /// Create a window
                  namedWindow( window_name, CV_WINDOW_AUTOSIZE );

                  /// Create a Trackbar for user to enter threshold
                  createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );

                  /// Show the image
                  CannyThreshold(0, 0);

                  /// Wait until user exit program by pressing a key
                  waitKey(0);

                  return 0;
                  }

                  }
                  }
                  
                  1 Reply Last reply
                  0
                  • jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #31

                    Sorry, but the code you posted is invalid C/C++! First of all: why do you have 2 main functions?
                    Why did you put other functions inside void MainWindow::onTrackball_clicked(int,void*)? This is not going to compile and I'm not going to fix it for you. How familiar are you actually with C/C++?
                    What you have to do is: do not put the C function definitions inside void MainWindow::onTrackball_clicked(int,void*), instead put them inside another source code file and header, include the header file in MainWindow and then call the functions in void MainWindow::onTrackball_clicked(int,void*). As an alternative you can have those C functions in MainWindow.cpp but not inside void MainWindow::onTrackball_clicked(int,void*) !

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    G 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      Sorry, but the code you posted is invalid C/C++! First of all: why do you have 2 main functions?
                      Why did you put other functions inside void MainWindow::onTrackball_clicked(int,void*)? This is not going to compile and I'm not going to fix it for you. How familiar are you actually with C/C++?
                      What you have to do is: do not put the C function definitions inside void MainWindow::onTrackball_clicked(int,void*), instead put them inside another source code file and header, include the header file in MainWindow and then call the functions in void MainWindow::onTrackball_clicked(int,void*). As an alternative you can have those C functions in MainWindow.cpp but not inside void MainWindow::onTrackball_clicked(int,void*) !

                      G Offline
                      G Offline
                      gauravsharma0190
                      wrote on last edited by
                      #32

                      @jsulm
                      i don't put these function definition inside voidmainwindow::ontrackball
                      but i am asking you how can i call that function inside my void mainwindow::ontrackball

                      void CannyThreshold(int, void)
                      {
                      /// Reduce noise with a kernel 3x3
                      blur( src_gray, detected_edges, Size(3,3) );
                      /// Canny detector
                      Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
                      
                      /// Using Canny's output as a mask, we display our result
                      dst = Scalar::all(0);
                      
                      src.copyTo( dst, detected_edges);
                      imshow( window_name, dst );
                      }
                      

                      Mean i hyave done .cpp and .h file of this and include in my code both.

                      jsulmJ 2 Replies Last reply
                      0
                      • G gauravsharma0190

                        @jsulm
                        i don't put these function definition inside voidmainwindow::ontrackball
                        but i am asking you how can i call that function inside my void mainwindow::ontrackball

                        void CannyThreshold(int, void)
                        {
                        /// Reduce noise with a kernel 3x3
                        blur( src_gray, detected_edges, Size(3,3) );
                        /// Canny detector
                        Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
                        
                        /// Using Canny's output as a mask, we display our result
                        dst = Scalar::all(0);
                        
                        src.copyTo( dst, detected_edges);
                        imshow( window_name, dst );
                        }
                        

                        Mean i hyave done .cpp and .h file of this and include in my code both.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #33

                        @gauravsharma0190 Like this?

                        CannyThreshold(1, nullptr);
                        

                        So, what exactly is the problem?
                        In the code you posted you DID put these function definitions inside void MainWindow::onTrackball_clicked(int,void*) (just check what you posted).

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • G gauravsharma0190

                          @jsulm
                          i don't put these function definition inside voidmainwindow::ontrackball
                          but i am asking you how can i call that function inside my void mainwindow::ontrackball

                          void CannyThreshold(int, void)
                          {
                          /// Reduce noise with a kernel 3x3
                          blur( src_gray, detected_edges, Size(3,3) );
                          /// Canny detector
                          Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
                          
                          /// Using Canny's output as a mask, we display our result
                          dst = Scalar::all(0);
                          
                          src.copyTo( dst, detected_edges);
                          imshow( window_name, dst );
                          }
                          

                          Mean i hyave done .cpp and .h file of this and include in my code both.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #34

                          @gauravsharma0190 Shouldn't

                          void CannyThreshold(int, void)
                          

                          be

                          void CannyThreshold(int, void*)
                          

                          ?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          G 1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            gauravsharma0190
                            wrote on last edited by
                            #35

                            ok now i will send you refresh code just wait.
                            Thank you.
                            i will send you refresh code and errors.

                            1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @gauravsharma0190 Shouldn't

                              void CannyThreshold(int, void)
                              

                              be

                              void CannyThreshold(int, void*)
                              

                              ?

                              G Offline
                              G Offline
                              gauravsharma0190
                              wrote on last edited by
                              #36

                              @jsulm
                              hey here is the code i have done with that.
                              /////main.cpp////

                              #include<opencv2/highgui/highgui.hpp>
                              #include<opencv2/core/core.hpp>
                              #include<opencv2/opencv.hpp>
                              using namespace cv;
                              using namespace std;
                              int main(int argc, char *argv[])
                              {
                              
                                  QApplication a(argc, argv);
                                  QSplashScreen *splash =new QSplashScreen;
                                  splash->setPixmap(QPixmap("/home/pi/Desktop/ceeri1.jpg"));
                                  splash->show();
                              
                                  MainWindow w;
                                  QTimer::singleShot(3500,splash,SLOT(close()));
                              
                                  QTimer::singleShot(3500,&w,SLOT(show()));
                              
                                //w.show();
                              
                                  return a.exec();
                              }
                              

                              ///mainwindow.h///

                              #ifndef MAINWINDOW_H
                              #define MAINWINDOW_H
                              
                              #include <QMainWindow>
                              //using namespace cv;
                              namespace Ui {
                              class MainWindow;
                              }
                              
                              class MainWindow : public QMainWindow
                              {
                              Q_OBJECT
                              
                              public:
                              explicit MainWindow(QWidget *parent = 0);
                              ~MainWindow();
                              
                              private slots:
                              void showTime();
                              
                              void on_pushButton_5_clicked();
                              void onTrackball_clicked(int,void*);
                              
                              private:
                              Ui::MainWindow *ui;
                              };
                              
                              #endif // MAINWINDOW_H
                              

                              ///ontrack.h///

                              #ifndef __ONTRACK_h
                              #define __ONTRACK_h
                              void cannyThresold(int,void*);
                              #endif
                              

                              ///ontrack.cpp

                              #include "ontrack.h"
                              #include<opencv2/opencv.hpp>
                              #include <opencv2/highgui/highgui.hpp>
                              #include <opencv2/core/core.hpp>
                              void CannyThreshold(int, void)
                              {
                              /// Reduce noise with a kernel 3x3
                              blur( src_gray, detected_edges, Size(3,3) );
                              /// Canny detector
                              Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
                              
                              /// Using Canny's output as a mask, we display our result
                              dst = Scalar::all(0);
                              
                              src.copyTo( dst, detected_edges);
                              imshow( window_name, dst );
                              }
                              

                              //Here Comes Mainwindow.cpp///

                              #include "ui_mainwindow.h"
                              #include<opencv2/opencv.hpp>
                              #include <opencv2/highgui/highgui.hpp>
                              #include <opencv2/core/core.hpp>
                              #include "ontrack.h"
                              #include<QFileDialog>
                              #include<QMessageBox>
                              #include <iostream>
                              #include <string>
                              #include <fstream>
                              #include<time.h>
                              #include<QTimer>
                              #include<QDateTime>
                              using namespace cv;
                              using namespace std;
                              MainWindow::MainWindow(QWidget *parent) :
                              QMainWindow(parent),
                              ui(new Ui::MainWindow)
                              {
                              ui->setupUi(this);
                              QTimer *timer=new QTimer(this);
                              connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));
                              timer->start();
                              QDateTime dateTime=QDateTime::currentDateTime();
                              QString datetimetext=dateTime.toString();
                              ui->DateTime->setText(datetimetext);
                              
                              }
                              ////////Time///////////////
                              void MainWindow:: showTime()
                              {
                              QTime time=QTime::currentTime();
                              QString time_text=time.toString("hh : mm : ss");
                              if((time.second() % 2)==0)
                              {
                              time_text[3] =' ';
                              time_text[8] =' ';
                              }
                              ui->Digital->setText(time_text);
                              
                              }
                              
                              MainWindow::~MainWindow()
                              {
                              delete ui;
                              }
                              
                              void MainWindow::on_pushButton_4_clicked()
                              {
                              
                              }
                              
                              void MainWindow::on_pushButton_5_clicked()
                              {
                              QString filename=QFileDialog::getOpenFileName(
                              this,
                              tr("Open file") ,
                              "/home/pi/Desktop",
                              tr("All files(*.png *.jpg)"));
                              
                              QMessageBox::information(this,tr("Filename"),filename);
                              if(QString::compare(filename,QString())!=0)
                              {
                                  QImage image;
                                  bool valid=image.load(filename);
                                  if(valid)
                                  {
                                      image=image.scaledToWidth(ui->Picture->width(),Qt::SmoothTransformation);
                                      ui->Picture->setPixmap(QPixmap::fromImage(image));
                              
                                  }
                              void MainWindow::onTrackball_clicked(int,void*)
                              {
                              
                              
                              Mat src, src_gray;
                              Mat dst, detected_edges;
                              
                              int edgeThresh = 1;
                              int lowThreshold;
                              int const max_lowThreshold = 100;
                              int ratio = 3;
                              int kernel_size = 3;
                              char* window_name = "Edge Map";
                              
                              
                              
                              @function CannyThreshold
                              @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                              /
                              
                              
                              /// Load an image
                              src = imread( argv[1] );
                              
                              if( !src.data )
                              { return -1; }
                              
                              /// Create a matrix of the same type and size as src (for dst)
                              dst.create( src.size(), src.type() );
                              
                              /// Convert the image to grayscale
                              cvtColor( src, src_gray, CV_BGR2GRAY );
                              
                              /// Create a window
                              namedWindow( window_name, CV_WINDOW_AUTOSIZE );
                              
                              /// Create a Trackbar for user to enter threshold
                              createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );
                              
                              /// Show the image
                              CannyThreshold(0, 0);
                              
                              }
                              }
                              ...
                              But error occurs defination of function outside the class.
                              G 1 Reply Last reply
                              0
                              • G gauravsharma0190

                                @jsulm
                                hey here is the code i have done with that.
                                /////main.cpp////

                                #include<opencv2/highgui/highgui.hpp>
                                #include<opencv2/core/core.hpp>
                                #include<opencv2/opencv.hpp>
                                using namespace cv;
                                using namespace std;
                                int main(int argc, char *argv[])
                                {
                                
                                    QApplication a(argc, argv);
                                    QSplashScreen *splash =new QSplashScreen;
                                    splash->setPixmap(QPixmap("/home/pi/Desktop/ceeri1.jpg"));
                                    splash->show();
                                
                                    MainWindow w;
                                    QTimer::singleShot(3500,splash,SLOT(close()));
                                
                                    QTimer::singleShot(3500,&w,SLOT(show()));
                                
                                  //w.show();
                                
                                    return a.exec();
                                }
                                

                                ///mainwindow.h///

                                #ifndef MAINWINDOW_H
                                #define MAINWINDOW_H
                                
                                #include <QMainWindow>
                                //using namespace cv;
                                namespace Ui {
                                class MainWindow;
                                }
                                
                                class MainWindow : public QMainWindow
                                {
                                Q_OBJECT
                                
                                public:
                                explicit MainWindow(QWidget *parent = 0);
                                ~MainWindow();
                                
                                private slots:
                                void showTime();
                                
                                void on_pushButton_5_clicked();
                                void onTrackball_clicked(int,void*);
                                
                                private:
                                Ui::MainWindow *ui;
                                };
                                
                                #endif // MAINWINDOW_H
                                

                                ///ontrack.h///

                                #ifndef __ONTRACK_h
                                #define __ONTRACK_h
                                void cannyThresold(int,void*);
                                #endif
                                

                                ///ontrack.cpp

                                #include "ontrack.h"
                                #include<opencv2/opencv.hpp>
                                #include <opencv2/highgui/highgui.hpp>
                                #include <opencv2/core/core.hpp>
                                void CannyThreshold(int, void)
                                {
                                /// Reduce noise with a kernel 3x3
                                blur( src_gray, detected_edges, Size(3,3) );
                                /// Canny detector
                                Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
                                
                                /// Using Canny's output as a mask, we display our result
                                dst = Scalar::all(0);
                                
                                src.copyTo( dst, detected_edges);
                                imshow( window_name, dst );
                                }
                                

                                //Here Comes Mainwindow.cpp///

                                #include "ui_mainwindow.h"
                                #include<opencv2/opencv.hpp>
                                #include <opencv2/highgui/highgui.hpp>
                                #include <opencv2/core/core.hpp>
                                #include "ontrack.h"
                                #include<QFileDialog>
                                #include<QMessageBox>
                                #include <iostream>
                                #include <string>
                                #include <fstream>
                                #include<time.h>
                                #include<QTimer>
                                #include<QDateTime>
                                using namespace cv;
                                using namespace std;
                                MainWindow::MainWindow(QWidget *parent) :
                                QMainWindow(parent),
                                ui(new Ui::MainWindow)
                                {
                                ui->setupUi(this);
                                QTimer *timer=new QTimer(this);
                                connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));
                                timer->start();
                                QDateTime dateTime=QDateTime::currentDateTime();
                                QString datetimetext=dateTime.toString();
                                ui->DateTime->setText(datetimetext);
                                
                                }
                                ////////Time///////////////
                                void MainWindow:: showTime()
                                {
                                QTime time=QTime::currentTime();
                                QString time_text=time.toString("hh : mm : ss");
                                if((time.second() % 2)==0)
                                {
                                time_text[3] =' ';
                                time_text[8] =' ';
                                }
                                ui->Digital->setText(time_text);
                                
                                }
                                
                                MainWindow::~MainWindow()
                                {
                                delete ui;
                                }
                                
                                void MainWindow::on_pushButton_4_clicked()
                                {
                                
                                }
                                
                                void MainWindow::on_pushButton_5_clicked()
                                {
                                QString filename=QFileDialog::getOpenFileName(
                                this,
                                tr("Open file") ,
                                "/home/pi/Desktop",
                                tr("All files(*.png *.jpg)"));
                                
                                QMessageBox::information(this,tr("Filename"),filename);
                                if(QString::compare(filename,QString())!=0)
                                {
                                    QImage image;
                                    bool valid=image.load(filename);
                                    if(valid)
                                    {
                                        image=image.scaledToWidth(ui->Picture->width(),Qt::SmoothTransformation);
                                        ui->Picture->setPixmap(QPixmap::fromImage(image));
                                
                                    }
                                void MainWindow::onTrackball_clicked(int,void*)
                                {
                                
                                
                                Mat src, src_gray;
                                Mat dst, detected_edges;
                                
                                int edgeThresh = 1;
                                int lowThreshold;
                                int const max_lowThreshold = 100;
                                int ratio = 3;
                                int kernel_size = 3;
                                char* window_name = "Edge Map";
                                
                                
                                
                                @function CannyThreshold
                                @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                                /
                                
                                
                                /// Load an image
                                src = imread( argv[1] );
                                
                                if( !src.data )
                                { return -1; }
                                
                                /// Create a matrix of the same type and size as src (for dst)
                                dst.create( src.size(), src.type() );
                                
                                /// Convert the image to grayscale
                                cvtColor( src, src_gray, CV_BGR2GRAY );
                                
                                /// Create a window
                                namedWindow( window_name, CV_WINDOW_AUTOSIZE );
                                
                                /// Create a Trackbar for user to enter threshold
                                createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );
                                
                                /// Show the image
                                CannyThreshold(0, 0);
                                
                                }
                                }
                                ...
                                But error occurs defination of function outside the class.
                                G Offline
                                G Offline
                                gauravsharma0190
                                wrote on last edited by
                                #37

                                @gauravsharma0190 said:

                                Sorry in ontrack.cpp i again add
                                Mat src, src_gray;
                                Mat dst, detected_edges;

                                jsulmJ 2 Replies Last reply
                                0
                                • G gauravsharma0190

                                  @gauravsharma0190 said:

                                  Sorry in ontrack.cpp i again add
                                  Mat src, src_gray;
                                  Mat dst, detected_edges;

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #38

                                  @gauravsharma0190 Can you post the whole error message?
                                  Why do you have int and void* parameter in onTrackball_clicked which you do not use?

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  1
                                  • G gauravsharma0190

                                    @gauravsharma0190 said:

                                    Sorry in ontrack.cpp i again add
                                    Mat src, src_gray;
                                    Mat dst, detected_edges;

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #39

                                    @gauravsharma0190 Take a look at this:

                                    
                                    void MainWindow::on_pushButton_5_clicked()
                                    {
                                    QString filename=QFileDialog::getOpenFileName(
                                    this,
                                    tr("Open file") ,
                                    "/home/pi/Desktop",
                                    tr("All files(*.png *.jpg)"));
                                    
                                    QMessageBox::information(this,tr("Filename"),filename);
                                    if(QString::compare(filename,QString())!=0)
                                    {
                                        QImage image;
                                        bool valid=image.load(filename);
                                        if(valid)
                                        {
                                            image=image.scaledToWidth(ui->Picture->width(),Qt::SmoothTransformation);
                                            ui->Picture->setPixmap(QPixmap::fromImage(image));
                                    
                                        }
                                    void MainWindow::onTrackball_clicked(int,void*)
                                    {
                                    

                                    void MainWindow::onTrackball_clicked(int,void*) is inside void MainWindow::on_pushButton_5_clicked() - this is invalid!

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    G 1 Reply Last reply
                                    1
                                    • jsulmJ jsulm

                                      @gauravsharma0190 Take a look at this:

                                      
                                      void MainWindow::on_pushButton_5_clicked()
                                      {
                                      QString filename=QFileDialog::getOpenFileName(
                                      this,
                                      tr("Open file") ,
                                      "/home/pi/Desktop",
                                      tr("All files(*.png *.jpg)"));
                                      
                                      QMessageBox::information(this,tr("Filename"),filename);
                                      if(QString::compare(filename,QString())!=0)
                                      {
                                          QImage image;
                                          bool valid=image.load(filename);
                                          if(valid)
                                          {
                                              image=image.scaledToWidth(ui->Picture->width(),Qt::SmoothTransformation);
                                              ui->Picture->setPixmap(QPixmap::fromImage(image));
                                      
                                          }
                                      void MainWindow::onTrackball_clicked(int,void*)
                                      {
                                      

                                      void MainWindow::onTrackball_clicked(int,void*) is inside void MainWindow::on_pushButton_5_clicked() - this is invalid!

                                      G Offline
                                      G Offline
                                      gauravsharma0190
                                      wrote on last edited by
                                      #40

                                      @jsulm
                                      but i am not defining ontrack_clicked in push button its different.

                                      mrjjM 1 Reply Last reply
                                      0
                                      • G gauravsharma0190

                                        @jsulm
                                        but i am not defining ontrack_clicked in push button its different.

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #41

                                        @gauravsharma0190

                                        Are you sure ?
                                        it really, really looks like you do :)

                                        G 1 Reply Last reply
                                        1
                                        • mrjjM mrjj

                                          @gauravsharma0190

                                          Are you sure ?
                                          it really, really looks like you do :)

                                          G Offline
                                          G Offline
                                          gauravsharma0190
                                          wrote on last edited by
                                          #42

                                          @mrjj
                                          sir i again improving it.
                                          as

                                          void MainWindow::on_pushButton_6_clicked()
                                          {
                                             /* Mat src , dst;
                                          
                                          
                                           //   char* source_window = "Source image";
                                             // char* equalized_window = "Equalized Image";
                                          
                                              /// Load image
                                              src = imread( "/home/pi/Desktop/b4.jpg" );
                                          
                                          
                                          
                                              /// Convert to grayscale
                                              cvtColor( src, src, CV_BGR2GRAY );
                                          
                                              /// Apply Histogram Equalization
                                              equalizeHist( src, dst );
                                          
                                              /// Display results
                                              namedWindow( "source", CV_WINDOW_NORMAL );
                                              namedWindow( "equalized", CV_WINDOW_NORMAL );
                                          
                                              imshow( "source", src );
                                              imshow( "equalized", dst );
                                          
                                              /// Wait until user exits the program
                                            //  waitKey(0);*/
                                          
                                          
                                          
                                              Mat src_base, hsv_base;
                                              Mat src_test1, hsv_test1;
                                              Mat src_test2, hsv_test2;
                                              Mat hsv_half_down;
                                          
                                              /// Load three images with different environment settings
                                          
                                              src_base = imread( "/home/pi/Desktop/b4.jpg" );
                                              src_test1 = imread( "/home/pi/Desktop/b4.jpg" );
                                              src_test2 = imread( "/home/pi/Desktop/b3.jpg" );
                                          
                                              /// Convert to HSV
                                              cvtColor( src_base, hsv_base, COLOR_BGR2HSV );
                                              cvtColor( src_test1, hsv_test1, COLOR_BGR2HSV );
                                              cvtColor( src_test2, hsv_test2, COLOR_BGR2HSV );
                                          
                                              hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) );
                                          
                                              /// Using 50 bins for hue and 60 for saturation
                                              int h_bins = 50; int s_bins = 60;
                                              int histSize[] = { h_bins, s_bins };
                                          
                                              // hue varies from 0 to 179, saturation from 0 to 255
                                              float h_ranges[] = { 0, 180 };
                                              float s_ranges[] = { 0, 256 };
                                          
                                              const float* ranges[] = { h_ranges, s_ranges };
                                          
                                              // Use the o-th and 1-st channels
                                              int channels[] = { 0, 1 };
                                          
                                          
                                              /// Histograms
                                              MatND hist_base;
                                              MatND hist_half_down;
                                              MatND hist_test1;
                                              MatND hist_test2;
                                          
                                              /// Calculate the histograms for the HSV images
                                              calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false );
                                              normalize( hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat() );
                                          
                                              calcHist( &hsv_half_down, 1, channels, Mat(), hist_half_down, 2, histSize, ranges, true, false );
                                              normalize( hist_half_down, hist_half_down, 0, 1, NORM_MINMAX, -1, Mat() );
                                          
                                              calcHist( &hsv_test1, 1, channels, Mat(), hist_test1, 2, histSize, ranges, true, false );
                                              normalize( hist_test1, hist_test1, 0, 1, NORM_MINMAX, -1, Mat() );
                                          
                                              calcHist( &hsv_test2, 1, channels, Mat(), hist_test2, 2, histSize, ranges, true, false );
                                              normalize( hist_test2, hist_test2, 0, 1, NORM_MINMAX, -1, Mat() );
                                          
                                              /// Apply the histogram comparison methods
                                              for( int i = 0; i < 4; i++ )
                                              {
                                                  int compare_method = i;
                                                  double base_base = compareHist( hist_base, hist_base, compare_method );
                                                  double base_half = compareHist( hist_base, hist_half_down, compare_method );
                                                  double base_test1 = compareHist( hist_base, hist_test1, compare_method );
                                                  double base_test2 = compareHist( hist_base, hist_test2, compare_method );
                                          
                                                  printf( " Method [%d] Perfect, Base-Half, Base-Test(1), Base-Test(2) : %f, %f, %f, %f \n", i, base_base, base_half , base_test1, base_test2 );
                                              }
                                          
                                          
                                          
                                          
                                              }
                                          
                                          
                                          
                                          void MainWindow::on_onTrackball_clicked()
                                          {
                                          
                                              Mat src, src_gray;
                                              Mat dst, detected_edges;
                                          
                                              int edgeThresh = 1;
                                              int lowThreshold;
                                              int const max_lowThreshold = 100;
                                              int ratio = 3;
                                              int kernel_size = 3;
                                              char* window_name = "Edge Map";
                                          
                                          
                                          
                                              /// Load image
                                              src = imread( "/home/pi/Desktop/b4.jpg");
                                               /// Create a matrix of the same type and size as src (for dst)
                                          
                                          
                                          
                                              dst.create( src.size(), src.type() );
                                          
                                              /// Convert the image to grayscale
                                              cvtColor( src, src_gray, CV_BGR2GRAY );
                                          
                                              /// Create a window
                                              namedWindow( window_name, CV_WINDOW_NORMAL );
                                          
                                              /// Create a Trackbar for user to enter threshold
                                            //  createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );
                                          
                                              /// Show the image
                                              CannyThreshold(0, 0);
                                          
                                          
                                              /// Separate the image in 3 places ( B, G and R )
                                              vector<Mat> bgr_planes;
                                              split( src, bgr_planes );
                                          
                                              /// Establish the number of bins
                                              int histSize = 256;
                                          
                                              /// Set the ranges ( for B,G,R) )
                                              float range[] = { 0, 256 } ;
                                              const float* histRange = { range };
                                          
                                              bool uniform = true;
                                              bool accumulate = false;
                                          
                                              Mat b_hist, g_hist, r_hist;
                                          
                                              /// Compute the histograms:
                                              calcHist( &bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );
                                              calcHist( &bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );
                                              calcHist( &bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );
                                          
                                              // Draw the histograms for B, G and R
                                              int hist_w = 512; int hist_h = 400;
                                             int bin_w = cvRound( (double) hist_w/histSize );
                                          
                                              Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) );
                                          
                                              /// Normalize the result to [ 0, histImage.rows ]
                                              normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
                                              normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
                                              normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
                                          
                                              /// Draw for each channel
                                              for( int i = 1; i < histSize; i++ )
                                              {
                                                  line( histImage, Point( bin_w*(i-1), hist_h - cvRound(b_hist.at<float>(i-1)) ) ,
                                                                   Point( bin_w*(i), hist_h - cvRound(b_hist.at<float>(i)) ),
                                                                   Scalar( 255, 0, 0), 2, 8, 0  );
                                                  line( histImage, Point( bin_w*(i-1), hist_h - cvRound(g_hist.at<float>(i-1)) ) ,
                                                                   Point( bin_w*(i), hist_h - cvRound(g_hist.at<float>(i)) ),
                                                                   Scalar( 0, 255, 0), 2, 8, 0  );
                                                  line( histImage, Point( bin_w*(i-1), hist_h - cvRound(r_hist.at<float>(i-1)) ) ,
                                                                   Point( bin_w*(i), hist_h - cvRound(r_hist.at<float>(i)) ),
                                                                   Scalar( 0, 0, 255), 2, 8, 0  );
                                              }
                                          
                                              /// Display
                                              namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE );
                                              imshow("calcHist Demo", histImage );
                                            imwrite("calcHist Demo2.jpg", histImage);
                                              waitKey(-1);
                                          
                                          
                                            }
                                          
                                          
                                          ...
                                          This is new improved code .but there are error or build issue
                                          1.In member function'void mainwindow::on_on_trackball_clicked()
                                          ****canny Thresol was not declered in this scope .(function which i declare and define in .h and .c file.
                                          unsed variable 'edgeThresh'.
                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved