// ================= // || Worksheet 11 // || In this exercise, we are going be solving the 2d wave equation. d^2/dt^2 f(x,y,t) = - k (d^2/dx^2+d^2/dy^2) f(x,y,t) // ================= // see also, e.g. http://www.mtnmath.com/whatrh/node66.html #include "program.h" using namespace std; using namespace cv; int worksheeteleven(Mat& src) { Mat input = Mat::zeros(200,200, CV_32F ); // draw a little circle in the middle of our image. circle(input, Point(input.rows/2, input.cols/2), 25.0f, Scalar( 1.0, 1.0, 1.0 ),CV_FILLED); // a window to show our outputs cv::namedWindow( "current frame", WINDOW_AUTOSIZE ); int MAX_NUMBER_OF_FRAMES = 5000; // dissipation factor. float k = 0.01f; // this is of the initial data? is this all we need? Mat prev_frame = input.clone() ; Mat colorized_frame; Size imsize = prev_frame.size(); // repeat this for each of the frames. for (int n = 0; n < MAX_NUMBER_OF_FRAMES; n++) { Mat frame = prev_frame.clone(); for(int i = 1; i < imsize.height -1; i++ ) { for(int j = 1; j < imsize.width -1; j++ ) { // f(x,y,t-1) - 2 f(x,y,t) + f(x,y,t+1) = -k L f(x,y,t) //frame.at(i,j) += ?? } } // lets colorize our image too, so that it looks better. frame.convertTo(colorized_frame,CV_8UC1, 127,127); applyColorMap(colorized_frame, colorized_frame,COLORMAP_AUTUMN); // lets also make it 4 times the size, so we dont strain our eyes. resize(colorized_frame,colorized_frame,Size(colorized_frame.cols*4,colorized_frame.rows*4 ) ); // display the current frame. cv::imshow( "current frame", colorized_frame); // wait for a key press to continue; //cv::waitKey(); //wait for 'esc' key press for 300ms. If 'esc' key is pressed, break loop if (waitKey(10) == 27) { cout << "esc key is pressed by user" << endl; break; } prev_frame = frame.clone(); } return 0; }