
        
// 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
		
    Scalar get_scalar_color(const char * rgbColor){
    	if(strlen(rgbColor) < 13 || rgbColor[0] != '#')
        	return Scalar(0,0,0,0);

        char r[4], g[4], b[4];
        strncpy(r, rgbColor+1, 4);
        strncpy(g, rgbColor+5, 4);
        strncpy(b, rgbColor+9, 4);
        
        int ri, gi, bi = 0;
        ri = (int)strtol(r, NULL, 16);
        gi = (int)strtol(g, NULL, 16);
        bi = (int)strtol(b, NULL, 16);
        
        ri /= 257;
        gi /= 257;
        bi /= 257;
        
        return Scalar(bi, gi, ri, 0);
    }


int main(int argc, char ** argv){
    char key = ' ';
            
    Mat image_file_14_output_image;

	Mat face_detection_24_input_image;
	Mat face_detection_24_output_image;
	CascadeClassifier face_cascade_24;
	vector<Rect> faces_24;
        
    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()) 
        	face_detection_24_input_image = image_file_14_output_image.clone();
		
	if(!face_detection_24_input_image.empty()){
		Scalar color = get_scalar_color("#DDDDDD");
		face_cascade_24.load("/opt/opencv/data/haarcascades/haarcascade_frontalface_alt.xml");
		face_cascade_24.detectMultiScale(face_detection_24_input_image, faces_24, 1.1, 3, 0|CV_HAAR_SCALE_IMAGE, Size(0, 0));
		for(int i = 0; i < faces_24.size(); i++){
			if("Rectangle" == "Ellipse"){
				Point center(faces_24[i].x + faces_24[i].width*0.5, faces_24[i].y + faces_24[i].height*0.5);
				ellipse(face_detection_24_input_image, center, Size(faces_24[i].width*1.0, faces_24[i].height*1.0), 0, 0, 360, color, 5, 8, 0);
			}
			else if("Rectangle" == "Rectangle")
				rectangle(face_detection_24_input_image, faces_24[i], color, 5, 8, 0);	
		}
		face_detection_24_output_image = face_detection_24_input_image.clone();
	}
        
        if(!face_detection_24_output_image.empty()) 
        	show_image_4_input_image = face_detection_24_output_image.clone();

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

                
    image_file_14_output_image.release();
		
	face_detection_24_input_image.release();
	face_detection_24_output_image.release();
        
    show_image_4_input_image.release();

    }

    destroyAllWindows();
    return 0;
}
