#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int test1(int argc, char** argv);
int test2();
int test3();

int main2(int argc, char** argv)
{
	return test3();
}

int test1(int argc, char** argv)
{
	if (argc != 2)
	{
		cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
		return -1;
	}

	Mat image;
	image = imread(argv[1], IMREAD_COLOR); // Read the file

	if (!image.data) // Check for invalid input
	{
		cout << "Could not open or find the image" << std::endl;
		return -1;
	}

	namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
	imshow("Display window", image); // Show our image inside it.

	waitKey(0); // Wait for a keystroke in the window
	return 0;
}

int test2()
{
		int c;
		IplImage* color_img;
		CvCapture* cv_cap = cvCaptureFromCAM(0);
		cvNamedWindow("Video", 0); // create window
		for (;;) {
			color_img = cvQueryFrame(cv_cap); // get frame
			if (color_img != 0)
				cvShowImage("Video", color_img); // show frame
			c = cvWaitKey(10); // wait 10 ms or for key stroke
			if (c == 27)
				break; // if ESC, break and quit
		}
		/* clean up */
		cvReleaseCapture(&cv_cap);
		cvDestroyWindow("Video");
		return 0;
}

int test3()
{
	VideoCapture stream1(0);   //0 is the id of video device.0 if you have only one camera.

	if (!stream1.isOpened()) { //check if video device has been initialised
		cout << "cannot open camera";
	}

	//unconditional loop
	while (true) {
		Mat cameraFrame;
		stream1.read(cameraFrame);
		imshow("cam", cameraFrame);
		if (waitKey(30) >= 0)
			break;
	}
	return 0;
}

