Declaration of function and use it



  • @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'.

  • Lifetime Qt Champion

    @gauravsharma0190 said:

    CannyThreshold

    this function ?
    CannyThreshold
    that you call with
    CannyThreshold(0, 0);

    and you do include the .h file where its defined?



  • @mrjj
    it is defined as

    ///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 );
    }
    

    .....
    thus i include ontrack.h in mainwindow.cpp code.
    but error occurs.
    Why??
    i can't understand.


  • Lifetime Qt Champion

    I dont understand either.
    Seems fine.
    try to define a test function
    as in
    ontrack.h
    void mytest();
    and call that from main.

    If that is still not known, it means that mainwinow do not really include ontrack.h for some reason.


  • Qt Champions 2018

    @gauravsharma0190 You call it like this CannyThreshold(0, 0); and in ontrack.cpp it is defined like void CannyThreshold(int, void*). But in ontrack.h it is void cannyThresold(int,void*); please fix the name of the function.


  • Lifetime Qt Champion

    @jsulm
    heh Good spotted. completely missed "old" :)



  • @mrjj
    I fix canny as Canny in .h file
    but again error occurs.



  • @jsulm
    Hey i fixed it .But again error.


  • Qt Champions 2018

    @gauravsharma0190 "But again error" - why don't you say what error you get now?



  • @jsulm
    yes it tells undefined reference to 'CannyThresold(int,void*)'.
    collect2:error ld returned 1 exit status.


  • Qt Champions 2018

    @gauravsharma0190 Is ontrack.cpp part of your project and is it built?
    "undefined reference to 'CannyThresold(int,void*)" - means linker cannot find CannyThresold(int,void*)



  • @jsulm
    Actually i put .h and .cpp file in my qt project folder.


  • Qt Champions 2018

    @gauravsharma0190 But did you add them to your project?
    They should be in the PRO file, like:

    SOURCES += main.cpp\
            mainwindow.cpp\
            ontrack.cpp
    
    HEADERS  += mainwindow.h\
            ontrack.h
    


  • @jsulm
    i added it but gives error as
    parse error onTrack.cpp
    Makefile error 3


  • Qt Champions 2018

    @gauravsharma0190 After changing PRO file you need to rerun qmake (right-click on the project in QtCreator and then "Run qmake". Then do a rebuild.



  • @jsulm
    I done it
    Now gives many error regarding onTrack.cpp file.


  • Qt Champions 2018

    @gauravsharma0190 Well, I guess you have many issues there...



  • @jsulm
    Yeap.
    are they function's issuses or anything.
    I can't undersatnd everything is all right so Why all these issuses are there.
    I will send you these issue.



  • @gauravsharma0190
    Here are all the errors
    ...

    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:9: error: 'blur' was not declared in this scope
         blur(gray, edge, Size(3,3));
                                   ^
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:6: error: 'Mat' does not name a type
     Mat image, gray, edge, cedge;
     ^
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:7: error: 'void CannyThreshold(int, void*)' was declared 'extern' and later 'static' [-fpermissive]
       static void CannyThreshold(int, void*)
                                            ^
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:-1: In function 'void CannyThreshold(int, void*)':
    
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:9: error: 'edge' was not declared in this scope
         blur(gray, edge, Size(3,3));
                    ^
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:9: error: 'edge' was not declared in this scope
         blur(gray, edge, Size(3,3));
                    ^
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:9: error: 'blur' was not declared in this scope
         blur(gray, edge, Size(3,3));
                                   ^
    
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:12: error: 'Canny' was not declared in this scope
         Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
                                                      ^
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:13: error: 'cedge' was not declared in this scope
         cedge = Scalar::all(0);
         ^
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:15: error: 'src' was not declared in this scope
         src.copyTo(cedge, edge);
         ^
    /home/pi/Desktop/qt/Desktop1/onTrackBall.cpp:16: error: 'imshow' was not declared in this scope
         imshow("Edge map", cedge);
                                 ^
    /usr/local/include/opencv2/highgui/highgui.hpp:78: note:   'cv::imshow'
     CV_EXPORTS_W void imshow(const string& winname, InputArray mat);
    


  • This post is deleted!


  • @jsulm
    Hey i have posted the error
    i can't undersatnd why i am getting these error.
    everything is all right.


  • Qt Champions 2018

    @gauravsharma0190 Nothing is all right with this code.
    "was not declared in this scope" - you have to check where are those declared or why they are not declared (blur, edge, Mat,...). For example:

    cedge = Scalar::all(0);
    

    where is cedge declared? You're trying to access a variable which was not declared.

    This one says that you first declared the function extern and later static. Why? Since it is just a function it neither has to be static nor extern!

    error: 'void CannyThreshold(int, void*)' was declared 'extern' and later 'static' [-fpermissive]
       static void CannyThreshold(int, void*)
    

    You really have to fix your code! And I really don't understand why you think your code is OK although there are really basic issues (not related to Qt at all)!



  • @jsulm
    i declare all these variable inside onTrach.cpp file.
    blur is function name which is in imgproc.hpp header.
    Canny is also function name which is declared in highgui.h header.


  • Qt Champions 2018

    @gauravsharma0190
    Can you post onTrach.cpp and onTrach.h?



  • @jsulm

    #include"onTrack.h"
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/core/core.hpp>
    #include<opencv2/imgproc/imgproc.hpp>
    int edgeThresh = 1;
    //Mat image,gray,edge,cedge; 
    
      void CannyThreshold(int, void*)
    {
    Mat image, gray, edge, cedge;
        blur(gray, edge, Size(3,3));
    
        // Run the edge detector on grayscale
        Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
        cedge = Scalar::all(0);
    
        src.copyTo(cedge, edge);
        imshow("Edge map", cedge);
    }
    
    

    .H file

    #define ONTRACKBALL_H_
      int CannyThreshold(int,void* );
    #endif
    //your code here
    

    Mat is opencv function which is declare in highgui.h
    header.
    all these functions are present in header which i added in code.


  • Qt Champions 2018

    @gauravsharma0190 What is Mat and where is it declared?


  • Qt Champions 2018

    @gauravsharma0190 Didn't you forget

    using namespace cv;
    

    in the cpp file?



  • @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



  • @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.


  • Qt Champions 2018

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



  • @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


  • Qt Champions 2018

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



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



  • @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.


  • Qt Champions 2018

    @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.


  • Qt Champions 2018

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



  • @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


  • Qt Champions 2018

    @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 );
    
    


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


  • Qt Champions 2018

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


Log in to reply