
        
// Auto-generated C Code - S2i Mosaicode
/*
*	In order to compile this source code run, in a terminal window, the following command:
*	gcc sourceCodeName.c `pkg-config --libs --cflags opencv` -o outputProgramName
*
*	the `pkg-config ... opencv` parameter is a inline command that returns the path to both
*	the libraries and the headers necessary when using opencv. The command also returns other necessary compiler options.
*/

#ifdef _CH_
#pragma package <opencv>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"

using namespace cv;
using namespace std;

#define FRAMERATE 1000.0 / 25.0


int main(int argc, char ** argv){
    char key = ' ';
            
    Mat image_file_35_output_image;
        
    Mat canny_45_input_image;
    Mat canny_45_output_image;
    int canny_45_input_aperturesize = 5;
    int canny_45_input_threshold1 = 16;
    int canny_45_input_threshold2 = 33;
        
    Mat show_image_43_input_image;
    if(strcmp("WINDOW_NORMAL", "WINDOW_AUTOSIZE") == 0)
        namedWindow("My Image", WINDOW_NORMAL);
    else
        namedWindow("My Image", WINDOW_AUTOSIZE);

    while((key = (char)waitKey(FRAMERATE)) != 27){
        
    image_file_35_output_image = imread("/usr/share/mosaicode/extensions/examples/c/opencv/lenna.png", IMREAD_COLOR);
        
        if(!image_file_35_output_image.empty()) 
        	canny_45_input_image = image_file_35_output_image.clone();
        
    if(!canny_45_input_image.empty()){
        if(canny_45_input_aperturesize < 1) canny_45_input_aperturesize = 1;
        if(canny_45_input_threshold1 < 1) canny_45_input_threshold1 = 1;
        if(canny_45_input_threshold2 < 1) canny_45_input_threshold2 = 1;
        if(canny_45_input_aperturesize > 10) canny_45_input_aperturesize = 10;
        if(canny_45_input_threshold1 > 100) canny_45_input_threshold1 = 100;
        if(canny_45_input_threshold2 > 100) canny_45_input_threshold2 = 100;
        canny_45_output_image = canny_45_input_image.clone();
        Mat tmpImg45(canny_45_input_image.rows,canny_45_input_image.cols,CV_8U);
        if(canny_45_input_image.channels() == 3){
            cvtColor(canny_45_input_image, tmpImg45, COLOR_RGB2GRAY);
        }else{
            tmpImg45 = canny_45_input_image = Mat::zeros(canny_45_input_image.cols, canny_45_input_image.rows, CV_8UC1);
        }
        Canny(tmpImg45, tmpImg45, canny_45_input_threshold1, canny_45_input_threshold2, canny_45_input_aperturesize);
        if(canny_45_input_image.channels() == 3){
            cvtColor(tmpImg45, canny_45_output_image,COLOR_GRAY2RGB);
        }else{
            canny_45_output_image = tmpImg45.clone();
        }
        tmpImg45.release();
    }
        
        if(!canny_45_output_image.empty()) 
        	show_image_43_input_image = canny_45_output_image.clone();

    if(!show_image_43_input_image.empty()){
        imshow("My Image", show_image_43_input_image);
    }

                
    image_file_35_output_image.release();
        
    canny_45_input_image.release();
    canny_45_output_image.release();
        
    show_image_43_input_image.release();

    }

    destroyAllWindows();
    return 0;
}
