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

Declaration of function and use it

Scheduled Pinned Locked Moved Unsolved General and Desktop
93 Posts 4 Posters 58.4k Views
  • 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
    19 Jul 2016, 10:50

    @jsulm
    Mat is basically a class with two data parts: the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for storing) . The matrix header size is constant, however the size of the matrix itself may vary from image to image and usually is larger by orders of magnitude

    G Offline
    G Offline
    gauravsharma0190
    wrote on 19 Jul 2016, 11:43 last edited by
    #70

    @gauravsharma0190
    Hey jslum
    thanks very mush i did it without error
    Now new problem arises when i clicked the push button it tells
    The program has unexpectedly finished.
    /home/pi/Desktop/qt /build-Desktop1-GCC Local/Desktop crashed.

    J 1 Reply Last reply 19 Jul 2016, 12:02
    0
    • G gauravsharma0190
      19 Jul 2016, 11:43

      @gauravsharma0190
      Hey jslum
      thanks very mush i did it without error
      Now new problem arises when i clicked the push button it tells
      The program has unexpectedly finished.
      /home/pi/Desktop/qt /build-Desktop1-GCC Local/Desktop crashed.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 19 Jul 2016, 12:02 last edited by
      #71

      @gauravsharma0190 Most probably it crashes because of an invalid pointer. Debug your application step by step to see where exactly it crashes.

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

      G 1 Reply Last reply 21 Jul 2016, 06:11
      0
      • J jsulm
        19 Jul 2016, 12:02

        @gauravsharma0190 Most probably it crashes because of an invalid pointer. Debug your application step by step to see where exactly it crashes.

        G Offline
        G Offline
        gauravsharma0190
        wrote on 21 Jul 2016, 06:11 last edited by
        #72

        @jsulm
        Hello sir
        i debug the programme but when i press button it tells
        the inferior stooped because it receives signal from OS
        Signal name SIGABRT
        Signal mean Aborted.
        Now how to solve it

        J 1 Reply Last reply 21 Jul 2016, 06:13
        0
        • G gauravsharma0190
          21 Jul 2016, 06:11

          @jsulm
          Hello sir
          i debug the programme but when i press button it tells
          the inferior stooped because it receives signal from OS
          Signal name SIGABRT
          Signal mean Aborted.
          Now how to solve it

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 21 Jul 2016, 06:13 last edited by jsulm
          #73

          @gauravsharma0190 Put a breakpoint in the slot which is called when you press the button and check where exactly it crashes.

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

          G 1 Reply Last reply 21 Jul 2016, 11:38
          1
          • G Offline
            G Offline
            gauravsharma0190
            wrote on 21 Jul 2016, 07:48 last edited by gauravsharma0190
            #74

            IT CRASHES WHERE FUNCTION ontrack()
            defination
            Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
            kernel_size issue i think.
            int kernel_size =3;
            here

            1 Reply Last reply
            0
            • J jsulm
              21 Jul 2016, 06:13

              @gauravsharma0190 Put a breakpoint in the slot which is called when you press the button and check where exactly it crashes.

              G Offline
              G Offline
              gauravsharma0190
              wrote on 21 Jul 2016, 11:38 last edited by
              #75

              @jsulm
              It crashes when i press the push button .
              I debugged it and found it creshes when my function call.
              Error found->it takes signal from OS.
              Now How to fix it.

              J 2 Replies Last reply 21 Jul 2016, 11:41
              0
              • G gauravsharma0190
                21 Jul 2016, 11:38

                @jsulm
                It crashes when i press the push button .
                I debugged it and found it creshes when my function call.
                Error found->it takes signal from OS.
                Now How to fix it.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 21 Jul 2016, 11:41 last edited by
                #76

                @gauravsharma0190 How to fix what?
                What do you mean by "Error found->it takes signal from OS" - what OS signal do you mean? Do you mean SIGABRT?
                I don't know how to fix it because I have no idea what the problem is. But usually such problems are caused by bugs in applications. You have to check your code and see what is wrong at the line where your application crashes.

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

                1 Reply Last reply
                0
                • G gauravsharma0190
                  21 Jul 2016, 11:38

                  @jsulm
                  It crashes when i press the push button .
                  I debugged it and found it creshes when my function call.
                  Error found->it takes signal from OS.
                  Now How to fix it.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 21 Jul 2016, 11:42 last edited by
                  #77

                  @gauravsharma0190 Can you post the code and mark the line where it crashes?

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

                  G 1 Reply Last reply 21 Jul 2016, 12:00
                  0
                  • J jsulm
                    21 Jul 2016, 11:42

                    @gauravsharma0190 Can you post the code and mark the line where it crashes?

                    G Offline
                    G Offline
                    gauravsharma0190
                    wrote on 21 Jul 2016, 12:00 last edited by gauravsharma0190
                    #78

                    @jsulm
                    Mainwindow.cpp

                    void MainWindow::on_onTrackball_clicked()
                    {
                        int threshold_value = 0;
                        int threshold_type = 3;
                        int const max_value = 255;
                        int const max_type = 4;
                       // int const max_BINARY_value = 255;
                    
                        Mat src, src_gray, dst;
                      //  char* window_name = "Threshold Demo";
                    
                        //char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted";
                        //char* trackbar_value = "Value";
                    
                    
                    
                    
                        /// Load image
                        src = imread( "/home/pi/Desktop/b4.jpg");
                    
                    
                          /// Convert the image to Gray
                          cvtColor( src, src_gray, CV_BGR2GRAY );
                    
                          /// Create a window to display results
                          namedWindow( "Threshold", CV_WINDOW_AUTOSIZE );
                    
                          /// Create Trackbar to choose type of Threshold
                          createTrackbar( "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted","Threshold", &threshold_type, max_type, Threshold_Demo );
                    
                          createTrackbar( "value","Threshold", &threshold_value, max_value, Threshold_Demo );
                    
                          /// Call the function to initialize
                    @@@   ***Threshold_Demo( 0, 0)***
                    
                    
                    }
                    

                    onTrack.h

                    #ifndef ONTRACKBALL_H_
                    #define ONTRACKBALL_H_
                      void Threshold_Demo( int, void* );
                    #endif
                    

                    ontrack.cpp

                    void Threshold_Demo( int, void* )
                    {
                      /* 0: Binary
                         1: Binary Inverted
                         2: Threshold Truncated
                         3: Threshold to Zero
                         4: Threshold to Zero Inverted
                       */
                    
                    @@threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
                    
                      imshow("Threshold", dst );
                    

                    Here @---> Error

                    J 1 Reply Last reply 21 Jul 2016, 12:04
                    0
                    • G gauravsharma0190
                      21 Jul 2016, 12:00

                      @jsulm
                      Mainwindow.cpp

                      void MainWindow::on_onTrackball_clicked()
                      {
                          int threshold_value = 0;
                          int threshold_type = 3;
                          int const max_value = 255;
                          int const max_type = 4;
                         // int const max_BINARY_value = 255;
                      
                          Mat src, src_gray, dst;
                        //  char* window_name = "Threshold Demo";
                      
                          //char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted";
                          //char* trackbar_value = "Value";
                      
                      
                      
                      
                          /// Load image
                          src = imread( "/home/pi/Desktop/b4.jpg");
                      
                      
                            /// Convert the image to Gray
                            cvtColor( src, src_gray, CV_BGR2GRAY );
                      
                            /// Create a window to display results
                            namedWindow( "Threshold", CV_WINDOW_AUTOSIZE );
                      
                            /// Create Trackbar to choose type of Threshold
                            createTrackbar( "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted","Threshold", &threshold_type, max_type, Threshold_Demo );
                      
                            createTrackbar( "value","Threshold", &threshold_value, max_value, Threshold_Demo );
                      
                            /// Call the function to initialize
                      @@@   ***Threshold_Demo( 0, 0)***
                      
                      
                      }
                      

                      onTrack.h

                      #ifndef ONTRACKBALL_H_
                      #define ONTRACKBALL_H_
                        void Threshold_Demo( int, void* );
                      #endif
                      

                      ontrack.cpp

                      void Threshold_Demo( int, void* )
                      {
                        /* 0: Binary
                           1: Binary Inverted
                           2: Threshold Truncated
                           3: Threshold to Zero
                           4: Threshold to Zero Inverted
                         */
                      
                      @@threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
                      
                        imshow("Threshold", dst );
                      

                      Here @---> Error

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 21 Jul 2016, 12:04 last edited by
                      #79

                      @gauravsharma0190 What are src_gray, dst, threshold_value, max_BINARY_value,threshold_type? Where are they defined and initialized? Please note: these are NOT same as in MainWindow::on_onTrackball_clicked()!

                      void Threshold_Demo( int, void* )
                      {
                        /* 0: Binary
                           1: Binary Inverted
                           2: Threshold Truncated
                           3: Threshold to Zero
                           4: Threshold to Zero Inverted
                         */
                      
                      @@threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
                      
                        imshow("Threshold", dst );
                      
                      

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

                      G 1 Reply Last reply 22 Jul 2016, 04:24
                      0
                      • J jsulm
                        21 Jul 2016, 12:04

                        @gauravsharma0190 What are src_gray, dst, threshold_value, max_BINARY_value,threshold_type? Where are they defined and initialized? Please note: these are NOT same as in MainWindow::on_onTrackball_clicked()!

                        void Threshold_Demo( int, void* )
                        {
                          /* 0: Binary
                             1: Binary Inverted
                             2: Threshold Truncated
                             3: Threshold to Zero
                             4: Threshold to Zero Inverted
                           */
                        
                        @@threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
                        
                          imshow("Threshold", dst );
                        
                        
                        G Offline
                        G Offline
                        gauravsharma0190
                        wrote on 22 Jul 2016, 04:24 last edited by
                        #80

                        @jsulm
                        Hey Good morning
                        These are defined in the same function .cpp files.
                        Yes These are not in mainwindow

                        J 1 Reply Last reply 22 Jul 2016, 04:27
                        0
                        • G gauravsharma0190
                          22 Jul 2016, 04:24

                          @jsulm
                          Hey Good morning
                          These are defined in the same function .cpp files.
                          Yes These are not in mainwindow

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 22 Jul 2016, 04:27 last edited by
                          #81

                          @gauravsharma0190 Did you initialize these variables? Do they have correct values when you call threshold()?

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

                          G 1 Reply Last reply 22 Jul 2016, 05:21
                          0
                          • J jsulm
                            22 Jul 2016, 04:27

                            @gauravsharma0190 Did you initialize these variables? Do they have correct values when you call threshold()?

                            G Offline
                            G Offline
                            gauravsharma0190
                            wrote on 22 Jul 2016, 05:21 last edited by
                            #82

                            @jsulm
                            Yes i initialize these with correct values.

                            J 1 Reply Last reply 22 Jul 2016, 05:29
                            0
                            • G gauravsharma0190
                              22 Jul 2016, 05:21

                              @jsulm
                              Yes i initialize these with correct values.

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 22 Jul 2016, 05:29 last edited by
                              #83

                              @gauravsharma0190 Are you sure? Did you verify using debugger? If they have correct values then I don't know why it's crashing...

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

                              G 1 Reply Last reply 22 Jul 2016, 06:00
                              1
                              • J jsulm
                                22 Jul 2016, 05:29

                                @gauravsharma0190 Are you sure? Did you verify using debugger? If they have correct values then I don't know why it's crashing...

                                G Offline
                                G Offline
                                gauravsharma0190
                                wrote on 22 Jul 2016, 06:00 last edited by
                                #84

                                @gauravsharma0190 said:

                                void MainWindow::on_onTrackball_clicked()
                                {
                                int threshold_value = 0;
                                int threshold_type = 3;
                                int const max_value = 255;
                                int const max_type = 4;
                                // int const max_BINARY_value = 255;

                                Mat src, src_gray, dst;
                                

                                // char* window_name = "Threshold Demo";

                                //char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted";
                                //char* trackbar_value = "Value";
                                
                                
                                
                                
                                /// Load image
                                src = imread( "/home/pi/Desktop/b4.jpg");
                                
                                
                                  /// Convert the image to Gray
                                  cvtColor( src, src_gray, CV_BGR2GRAY );
                                
                                  /// Create a window to display results
                                  namedWindow( "Threshold", CV_WINDOW_AUTOSIZE );
                                
                                  /// Create Trackbar to choose type of Threshold
                                  createTrackbar( "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted","Threshold", &threshold_type, max_type, Threshold_Demo );
                                
                                  createTrackbar( "value","Threshold", &threshold_value, max_value, Threshold_Demo );
                                
                                  /// Call the function to initialize
                                

                                @@@ Threshold_Demo( 0, 0)

                                }

                                When I Comment the line Threshold _demo everything went OK!!!
                                Results are coming but when i uncomment it everything crashes.

                                J 1 Reply Last reply 22 Jul 2016, 06:16
                                0
                                • mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 22 Jul 2016, 06:10 last edited by
                                  #85

                                  Hi
                                  I have a teory ;)

                                  namedWindow

                                  void namedWindow(const string& winname, int flags=WINDOW_AUTOSIZE )

                                  It wants a ref, so i assume that the crash is that
                                  // char* window_name = "Threshold Demo";

                                  will run out of scope

                                  where as
                                  namedWindow( "Threshold", CV_WINDOW_AUTOSIZE );
                                  There "Threshold" is managed by the compiler and wont run out.

                                  To test this, please move
                                  char* window_name = "Threshold Demo";

                                  OUTSIDE the function so it last longer than function call.

                                  1 Reply Last reply
                                  0
                                  • G gauravsharma0190
                                    22 Jul 2016, 06:00

                                    @gauravsharma0190 said:

                                    void MainWindow::on_onTrackball_clicked()
                                    {
                                    int threshold_value = 0;
                                    int threshold_type = 3;
                                    int const max_value = 255;
                                    int const max_type = 4;
                                    // int const max_BINARY_value = 255;

                                    Mat src, src_gray, dst;
                                    

                                    // char* window_name = "Threshold Demo";

                                    //char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted";
                                    //char* trackbar_value = "Value";
                                    
                                    
                                    
                                    
                                    /// Load image
                                    src = imread( "/home/pi/Desktop/b4.jpg");
                                    
                                    
                                      /// Convert the image to Gray
                                      cvtColor( src, src_gray, CV_BGR2GRAY );
                                    
                                      /// Create a window to display results
                                      namedWindow( "Threshold", CV_WINDOW_AUTOSIZE );
                                    
                                      /// Create Trackbar to choose type of Threshold
                                      createTrackbar( "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted","Threshold", &threshold_type, max_type, Threshold_Demo );
                                    
                                      createTrackbar( "value","Threshold", &threshold_value, max_value, Threshold_Demo );
                                    
                                      /// Call the function to initialize
                                    

                                    @@@ Threshold_Demo( 0, 0)

                                    }

                                    When I Comment the line Threshold _demo everything went OK!!!
                                    Results are coming but when i uncomment it everything crashes.

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 22 Jul 2016, 06:16 last edited by
                                    #86

                                    @gauravsharma0190 Please take a closer look at this code:

                                    void MainWindow::on_onTrackball_clicked()
                                    {
                                    int threshold_value = 0;
                                    int threshold_type = 3;
                                    int const max_value = 255;
                                    int const max_type = 4;
                                    // int const max_BINARY_value = 255;
                                    // These variables are LOCAL!
                                    Mat src, src_gray, dst;
                                    

                                    You use local variables in void MainWindow::on_onTrackball_clicked(). All these variables exist only in that function: Mat src, src_gray, dst;
                                    In Threshold_Demo() these variable are not visible (I have no idea why your code compiles? You probably defined these variables somewhere else again). I already pointed out this issue in one of my previous posts.

                                    void Threshold_Demo( int, void* )
                                    {
                                      /* 0: Binary
                                         1: Binary Inverted
                                         2: Threshold Truncated
                                         3: Threshold to Zero
                                         4: Threshold to Zero Inverted
                                       */
                                    // src_gray, dst, threshold_value, max_BINARY_value,threshold_type are GLOBAL! Where are they defined?
                                    @@threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
                                    

                                    Please make really sure src_gray, dst, threshold_value, max_BINARY_value,threshold_type have valid values when you call threshold( )! Use debugger for this.

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

                                    G 1 Reply Last reply 22 Jul 2016, 07:10
                                    1
                                    • J jsulm
                                      22 Jul 2016, 06:16

                                      @gauravsharma0190 Please take a closer look at this code:

                                      void MainWindow::on_onTrackball_clicked()
                                      {
                                      int threshold_value = 0;
                                      int threshold_type = 3;
                                      int const max_value = 255;
                                      int const max_type = 4;
                                      // int const max_BINARY_value = 255;
                                      // These variables are LOCAL!
                                      Mat src, src_gray, dst;
                                      

                                      You use local variables in void MainWindow::on_onTrackball_clicked(). All these variables exist only in that function: Mat src, src_gray, dst;
                                      In Threshold_Demo() these variable are not visible (I have no idea why your code compiles? You probably defined these variables somewhere else again). I already pointed out this issue in one of my previous posts.

                                      void Threshold_Demo( int, void* )
                                      {
                                        /* 0: Binary
                                           1: Binary Inverted
                                           2: Threshold Truncated
                                           3: Threshold to Zero
                                           4: Threshold to Zero Inverted
                                         */
                                      // src_gray, dst, threshold_value, max_BINARY_value,threshold_type are GLOBAL! Where are they defined?
                                      @@threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
                                      

                                      Please make really sure src_gray, dst, threshold_value, max_BINARY_value,threshold_type have valid values when you call threshold( )! Use debugger for this.

                                      G Offline
                                      G Offline
                                      gauravsharma0190
                                      wrote on 22 Jul 2016, 07:10 last edited by
                                      #87

                                      @jsulm
                                      Hey the ontrack.cpp file has these variable defined i havn't sent you full code
                                      here it is

                                      #include"onTrack.h"
                                      #include<imgproc.hpp>
                                       using namespace cv;
                                      using namespace std;
                                      int threshold_value=0;
                                      int threshold_type=3;
                                      int const max_BINARY_value=255;
                                      Mat src_gray,dst;
                                      
                                      void Threshold_Demo( int, void* )
                                      {
                                        /* 0: Binary
                                           1: Binary Inverted
                                           2: Threshold Truncated
                                           3: Threshold to Zero
                                           4: Threshold to Zero Inverted
                                         */
                                      
                                        threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
                                      
                                        imshow( window_name, dst );
                                      }
                                      ......
                                      J 1 Reply Last reply 22 Jul 2016, 07:28
                                      0
                                      • G gauravsharma0190
                                        22 Jul 2016, 07:10

                                        @jsulm
                                        Hey the ontrack.cpp file has these variable defined i havn't sent you full code
                                        here it is

                                        #include"onTrack.h"
                                        #include<imgproc.hpp>
                                         using namespace cv;
                                        using namespace std;
                                        int threshold_value=0;
                                        int threshold_type=3;
                                        int const max_BINARY_value=255;
                                        Mat src_gray,dst;
                                        
                                        void Threshold_Demo( int, void* )
                                        {
                                          /* 0: Binary
                                             1: Binary Inverted
                                             2: Threshold Truncated
                                             3: Threshold to Zero
                                             4: Threshold to Zero Inverted
                                           */
                                        
                                          threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
                                        
                                          imshow( window_name, dst );
                                        }
                                        ......
                                        J Offline
                                        J Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 22 Jul 2016, 07:28 last edited by
                                        #88

                                        @gauravsharma0190 That is the problem I'm talking all the time! You do not initialize src_gray,dst from ontrack.cpp, so you use not properly initialized variables in Threshold_Demo(). As I said in MainWindow::on_onTrackball_clicked() you use local variables rc_gray,dst, not the ones from ontrack.cpp!
                                        So, again where are these variables initialized?

                                        // Where are they initialized?
                                        Mat src_gray,dst;
                                        
                                        void Threshold_Demo( int, void* )
                                        {
                                          /* 0: Binary
                                             1: Binary Inverted
                                             2: Threshold Truncated
                                             3: Threshold to Zero
                                             4: Threshold to Zero Inverted
                                           */
                                        

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

                                        G 1 Reply Last reply 22 Jul 2016, 08:55
                                        0
                                        • J jsulm
                                          22 Jul 2016, 07:28

                                          @gauravsharma0190 That is the problem I'm talking all the time! You do not initialize src_gray,dst from ontrack.cpp, so you use not properly initialized variables in Threshold_Demo(). As I said in MainWindow::on_onTrackball_clicked() you use local variables rc_gray,dst, not the ones from ontrack.cpp!
                                          So, again where are these variables initialized?

                                          // Where are they initialized?
                                          Mat src_gray,dst;
                                          
                                          void Threshold_Demo( int, void* )
                                          {
                                            /* 0: Binary
                                               1: Binary Inverted
                                               2: Threshold Truncated
                                               3: Threshold to Zero
                                               4: Threshold to Zero Inverted
                                             */
                                          
                                          G Offline
                                          G Offline
                                          gauravsharma0190
                                          wrote on 22 Jul 2016, 08:55 last edited by
                                          #89

                                          @jsulm said:

                                          That is the problem I'm talking all the time! You do not initialize src_gray,dst from ontrack.cpp, so you use not properly initialized variables in Threshold_Demo(). As I said in MainWindow::on_onTrackball_clicked() you use local variables rc_gray,dst, not the ones from ontrack.cpp!
                                          So, again where are these variables initialized?

                                          // Where are they initialized?
                                          Mat src_gray,dst;

                                          void Threshold_Demo( int, void* )
                                          {
                                          /* 0: Binary
                                          1: Binary Inverted
                                          2: Threshold Truncated
                                          3: Threshold to Zero
                                          4: Threshold to Zero Inverted
                                          */

                                          I initalized it in Mainwindow::onTrackBall_clicked().
                                          I am sending you.
                                          mainWindow.cpp*******

                                          #include "mainwindow.h"
                                          #include "ui_mainwindow.h"
                                          #include<opencv2/opencv.hpp>
                                          #include <opencv2/highgui/highgui.hpp>
                                          #include <opencv2/core/core.hpp>
                                          #include <opencv2/imgproc/imgproc.hpp>
                                          #include<QFileDialog>
                                          #include<QMessageBox>
                                          #include <iostream>
                                          #include<QProcess>
                                          #include "onTrackBall.h"
                                          #include<syscall.h>
                                          #include<signal.h>
                                          #include <string>
                                          #include<stdlib.h>
                                          #include<sys/ioctl.h>
                                          #include <fstream>
                                          #include<time.h>
                                          #include<QTimer>
                                          #include<QDateTime>
                                          //#include"onTrackBall.h"
                                          //#include"onTrackBall.c"
                                          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);
                                          
                                          }
                                          void MainWindow::on_onTrackball_clicked()
                                          {
                                              int threshold_value = 0;
                                              int threshold_type = 3;
                                              int const max_value = 255;
                                              int const max_type = 4;
                                             // int const max_BINARY_value = 255;
                                          
                                              Mat src, src_gray;
                                          
                                          
                                          
                                          
                                          
                                              /// Load image
                                              src = imread( "/home/pi/Desktop/b4.jpg");
                                          
                                          
                                                /// Convert the image to Gray
                                                cvtColor( src, src_gray, CV_BGR2GRAY );
                                          
                                                /// Create a window to display results
                                                namedWindow( "Threshold", CV_WINDOW_NORMAL );
                                          
                                                /// Create Trackbar to choose type of Threshold
                                                createTrackbar( "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted","Threshold", &threshold_type, max_type, Threshold_Demo );
                                          
                                                createTrackbar( "value","Threshold", &threshold_value, max_value, Threshold_Demo );
                                          
                                                /// Call the function to initialize
                                              Threshold_Demo( 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_NORMAL );
                                              imshow("calcHist Demo", histImage );
                                            imwrite("calcHist Demo2.jpg", histImage);
                                          waitKey(-1);
                                          
                                          
                                            }
                                          ...
                                          J 1 Reply Last reply 22 Jul 2016, 09:26
                                          0

                                          79/93

                                          21 Jul 2016, 12:04

                                          • Login

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