
        
// 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_14_output_image;

	Mat harris_corner_detector_25_input_image;
	Mat harris_corner_detector_25_output_image;
	Mat Mat_tmp_25;
        
    Mat show_image_4_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_14_output_image = imread("/usr/share/mosaicode/extensions/examples/c/opencv/lenna.png", IMREAD_COLOR);
        
        if(!image_file_14_output_image.empty()) 
        	harris_corner_detector_25_input_image = image_file_14_output_image.clone();
		
	if(!harris_corner_detector_25_input_image.empty()){
		cvtColor(harris_corner_detector_25_input_image, harris_corner_detector_25_input_image, COLOR_BGR2GRAY);
		harris_corner_detector_25_output_image = Mat::zeros(harris_corner_detector_25_input_image.size(), CV_32FC1);
		cornerHarris(harris_corner_detector_25_input_image, Mat_tmp_25, 2, 3, 0.04, BORDER_DEFAULT);
		normalize(Mat_tmp_25, Mat_tmp_25, 0, 255, NORM_MINMAX, CV_32FC1, Mat());
		convertScaleAbs(Mat_tmp_25, harris_corner_detector_25_output_image);
		for(int j = 0; j < Mat_tmp_25.rows ; j++){ 
			for(int i = 0; i < Mat_tmp_25.cols; i++){
            	if((int) Mat_tmp_25.at<float>(j,i) > 150){
            		circle( harris_corner_detector_25_output_image, Point(i, j), 5, Scalar(0), 2, 8, 0);
              	}
          	}
		}
	}
        
        if(!harris_corner_detector_25_output_image.empty()) 
        	show_image_4_input_image = harris_corner_detector_25_output_image.clone();

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

                
    image_file_14_output_image.release();

	harris_corner_detector_25_input_image.release();
	harris_corner_detector_25_output_image.release();
        
    show_image_4_input_image.release();

    }

    destroyAllWindows();
    return 0;
}
