Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv/cv.h>
- #include <opencv/highgui.h>
- #include <math.h>
- void Draw(int x, int y, Mat image){
- image = Mat(600, 800, CV_8UC1, Scalar(0));
- circle(image, cvPoint(x, y), 32.0, cvScalar(0, 0, 255), CV_FILLED, 8);
- imshow("Curve 2 - line", image);
- }
- void Move(int x, int y, Mat image){
- for (int i = x; i < 800; i = i + 4)
- {
- Draw(i, y, image);
- waitKey(1);
- }
- }
- using namespace cv;
- int main(){
- /*cvNamedWindow("window", CV_WINDOW_AUTOSIZE);
- int y, x;
- x = 100;
- y = 500;
- IplImage* image = cvCreateImage(cvSize(800, 600), IPL_DEPTH_8U, 3);
- while (true)
- {
- int key = cvWaitKey(0);
- if (key == 'w'){
- y -= 10;
- }
- else if (key == 's'){
- y += 10;
- }
- else if (key == 'a'){
- x -= 10;
- }
- else if (key == 'd'){
- x += 10;
- }
- else if (key == 27){
- cvDestroyWindow("1");
- return 0;
- }
- else if (key == 32){
- Move(x,y,image);
- }
- Draw(x, y, image);
- }*/
- Mat img(600, 800, CV_8UC1, Scalar(0));
- Mat img2 = img.clone();
- float a, b, c;
- a = b = c = 0;
- a = 0.01;
- b = 2.0;
- float start_point_x = 0;
- float end_point_x = 800;
- float przesuniecie_x = 400;
- float przesuniecie_y = 200;
- float wypłaszczenie = 1.0;
- vector<Point2f> curvePoints;
- while (true)
- {
- int key = cvWaitKey(0);
- if (key == 'w'){
- przesuniecie_y -= 10;
- }
- else if (key == 's'){
- przesuniecie_y += 10;
- }
- else if (key == 'a'){
- przesuniecie_x -= 10;
- }else if (key == 'd'){
- przesuniecie_x += 10;
- }
- else if (key == 'c'){
- c += 2.0;
- }
- else if (key == '1'){
- wypłaszczenie -= 0.1;
- }
- else if (key == '2'){
- wypłaszczenie += 0.1;
- }
- else if (key == 32){
- Move(x, y, img2);
- }
- img2 = Mat(600, 800, CV_8UC1, Scalar(0));
- //After this the Mat can be re-assigned another value for example:
- //img2 = Mat::zeros(600, 800, CV_8UC1);
- curvePoints.clear();
- //Define the curve through equation. In this example, a simple parabola
- for (float x = start_point_x; x <= end_point_x; x += 1){
- //float y = ((0.0425*x*x) + a) -( (4.25*x) + b) + (258 + c);
- float y = ((a*pow(x - przesuniecie_x, 2)) + przesuniecie_y)/wypłaszczenie;
- Point2f new_point = Point2f( x, y); //resized to better visualize
- curvePoints.push_back(new_point); //add point to vector/list
- }
- //Option 1: use polylines
- //Mat curve(curvePoints, true);
- //curve.convertTo(curve, CV_32S); //adapt type for polylines
- //polylines(img, curve, false, Scalar(255), 2, CV_AA);
- //Option 2: use line with each pair of consecutives points
- for (int i = 0; i < curvePoints.size() - 1; i++){
- line(img2, curvePoints[i], curvePoints[i + 1], Scalar(255), 2, CV_AA);
- }
- /*imshow("Curve 1 - polylines", img)*/;
- imshow("Curve 2 - line", img2);
- waitKey(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement