
#include <cv.h>
#include <highgui.h>


/*
	Program to demonstrate the use of trackbars.
	@author: Gavin Page, gsp8334@cs.rit.edu
	@date: 08 November 2005
*/

//working images
IplImage* org;
IplImage* hw;

int sx = 100;
int sy = 100;

int ex = 200;
int ey = 200;


//Callback function for the trackbars
void CHANGE_DIMS(int a)
{   
	cvReleaseImage(&hw);
	//get a copy of the original image
	hw = cvCloneImage(org);
	//draw the rectangle
    cvRectangle( hw, cvPoint(sx, sy), cvPoint(ex, ey), CV_RGB(0, 255, 0), 2, 8, 0);
	//send the image to the container
    cvShowImage("Trackbar Test", hw);
}

int main( int argc, char** argv ) {
    //declare for the height and width of the image
	int height = 320;
	int width = 240;

	//specify the point to place the text
	CvPoint pt = cvPoint( height/4, width/2 );

	//Create an 8 bit, 3 plane image
	org = cvCreateImage(cvSize(height, width), 8, 3);


	//create the window container
	cvNamedWindow("Trackbar Test", 0);

	CHANGE_DIMS(1);

	//The next two lines pass a reference to the callback function.
	//the reference is adjusted via the trackbar and the new value is returned
	ex = cvCreateTrackbar("End X", 
		"Trackbar Test", &ex, 320, CHANGE_DIMS);
	ey = cvCreateTrackbar("End Y", 
		"Trackbar Test", &ey, 240, CHANGE_DIMS);


	hw = cvCloneImage(org);
	//display the image in the container
	cvShowImage("TrackBar Test", hw);

	//hold the output windows
	cvWaitKey(0);

	//clean up images
	cvReleaseImage(&org);
	cvReleaseImage(&hw);

	//remove windows
	cvDestroyWindow("Trackbar Test");


	return 0;

}
