oreillymedia/Learning-OpenCV-3_examples

Would like to confirm with Example 2-5 (Page: 31)

rajhlinux opened this issue · 1 comments

In the book "Learning OpenCV 3", on Page 31, "A Simple Transformation", Example 2-5.

Loading and then smoothing an image before it is displayed on the screen.

The Example 2-5 code, shows:

void example2_5( const cv::Mat & image ) 
{
    // Create some windows to show the input and output images in:
    cv::namedWindow( "Example2_5-in", cv::WINDOW_AUTOSIZE );
    cv::namedWindow( "Example2_5-out", cv::WINDOW_AUTOSIZE );
    
    // Create a window to show our input image:
    cv::imshow( "Example2_5-in", image );
    
    // Create an image to hold the smoothed output:
    cv::Mat out;

    // Do the smoothing
    // ( Note: Could use GaussianBlur(), blur(), medianBlur() or bilateralFilter(). )
    cv::GaussianBlur(image, out, cv::Size(5,5), 3, 3);
    cv::GaussianBlur(out, out, cv::Size(5,5), 3, 3);

    // Show the smoothed image in the output window:
    cv::imshow( "Example2_5-out", out );

    // Wait for the user to hit a key, windows will self destruct:
    cv::waitKey( 0 );
}

Were we suppose to call it as a function or take this code and modify it as to the example shown in github?
If not how to solve it for the book?
Not sure how "argv" on int main can pass it to the void function of example 2-5.

The github example for Example 2-5 does not show the usage of the function "void example2_5( const cv::Mat & image )".

Thanks.

Alright I was able to compile the void function properly as intended stated from the book:

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <fstream>

using namespace std;
    cv::VideoCapture cap;


void example2_5( const cv::Mat & image ) 
{
    // Create some windows to show the input and output images in:
    cv::namedWindow( "Example2_5-in", cv::WINDOW_AUTOSIZE );
    cv::namedWindow( "Example2_5-out", cv::WINDOW_AUTOSIZE );
    
    // Create a window to show our input image:
    cv::imshow( "Example2_5-in", image );
    
    // Create an image to hold the smoothed output:
    cv::Mat out;

    // Do the smoothing
    // ( Note: Could use GaussianBlur(), blur(), medianBlur() or bilateralFilter(). )
    cv::GaussianBlur(image, out, cv::Size(5,5), 3, 3);
    cv::GaussianBlur(out, out, cv::Size(5,5), 3, 3);

    // Show the smoothed image in the output window:
    cv::imshow( "Example2_5-out", out );

    // Wait for the user to hit a key, windows will self destruct:
    cv::waitKey( 0 );
}


int main( int argc, char** argv ) 
{
    cap.open(string(argv[1]));

    cv::Mat frame;

    for(;;)
    {
        cap >> frame; 
        if(frame.empty()) break;
        example2_5(frame);
    }

    return(0);
}