Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1.  
  2.  
  3. #include <opencv/cv.h>
  4. #include <opencv/highgui.h>
  5. #include <math.h>
  6.  
  7. void Draw(int x, int y, Mat image){
  8. image = Mat(600, 800, CV_8UC1, Scalar(0));
  9. circle(image, cvPoint(x, y), 32.0, cvScalar(0, 0, 255), CV_FILLED, 8);
  10. imshow("Curve 2 - line", image);
  11.  
  12. }
  13.  
  14. void Move(int x, int y, Mat image){
  15. for (int i = x; i < 800; i = i + 4)
  16. {
  17. Draw(i, y, image);
  18. waitKey(1);
  19.  
  20. }
  21.  
  22.  
  23. }
  24. using namespace cv;
  25. int main(){
  26.  
  27.  
  28. /*cvNamedWindow("window", CV_WINDOW_AUTOSIZE);
  29. int y, x;
  30. x = 100;
  31. y = 500;
  32. IplImage* image = cvCreateImage(cvSize(800, 600), IPL_DEPTH_8U, 3);
  33. while (true)
  34. {
  35. int key = cvWaitKey(0);
  36. if (key == 'w'){
  37. y -= 10;
  38.  
  39.  
  40. }
  41. else if (key == 's'){
  42. y += 10;
  43.  
  44. }
  45. else if (key == 'a'){
  46. x -= 10;
  47.  
  48.  
  49. }
  50. else if (key == 'd'){
  51. x += 10;
  52.  
  53.  
  54. }
  55. else if (key == 27){
  56. cvDestroyWindow("1");
  57. return 0;
  58.  
  59.  
  60. }
  61. else if (key == 32){
  62.  
  63. Move(x,y,image);
  64.  
  65. }
  66. Draw(x, y, image);
  67.  
  68.  
  69.  
  70. }*/
  71.  
  72.  
  73. Mat img(600, 800, CV_8UC1, Scalar(0));
  74. Mat img2 = img.clone();
  75. float a, b, c;
  76. a = b = c = 0;
  77. a = 0.01;
  78. b = 2.0;
  79. float start_point_x = 0;
  80. float end_point_x = 800;
  81. float przesuniecie_x = 400;
  82. float przesuniecie_y = 200;
  83. float wypłaszczenie = 1.0;
  84. vector<Point2f> curvePoints;
  85.  
  86. while (true)
  87. {
  88. int key = cvWaitKey(0);
  89. if (key == 'w'){
  90. przesuniecie_y -= 10;
  91.  
  92.  
  93. }
  94. else if (key == 's'){
  95. przesuniecie_y += 10;
  96.  
  97. }
  98. else if (key == 'a'){
  99. przesuniecie_x -= 10;
  100.  
  101.  
  102. }else if (key == 'd'){
  103. przesuniecie_x += 10;
  104.  
  105. }
  106. else if (key == 'c'){
  107. c += 2.0;
  108.  
  109.  
  110. }
  111. else if (key == '1'){
  112. wypłaszczenie -= 0.1;
  113.  
  114. }
  115. else if (key == '2'){
  116. wypłaszczenie += 0.1;
  117.  
  118.  
  119. }
  120.  
  121. else if (key == 32){
  122.  
  123. Move(x, y, img2);
  124.  
  125. }
  126.  
  127.  
  128. img2 = Mat(600, 800, CV_8UC1, Scalar(0));
  129.  
  130. //After this the Mat can be re-assigned another value for example:
  131. //img2 = Mat::zeros(600, 800, CV_8UC1);
  132.  
  133. curvePoints.clear();
  134. //Define the curve through equation. In this example, a simple parabola
  135. for (float x = start_point_x; x <= end_point_x; x += 1){
  136. //float y = ((0.0425*x*x) + a) -( (4.25*x) + b) + (258 + c);
  137.  
  138. float y = ((a*pow(x - przesuniecie_x, 2)) + przesuniecie_y)/wypłaszczenie;
  139. Point2f new_point = Point2f( x, y); //resized to better visualize
  140. curvePoints.push_back(new_point); //add point to vector/list
  141. }
  142.  
  143. //Option 1: use polylines
  144. //Mat curve(curvePoints, true);
  145. //curve.convertTo(curve, CV_32S); //adapt type for polylines
  146. //polylines(img, curve, false, Scalar(255), 2, CV_AA);
  147.  
  148. //Option 2: use line with each pair of consecutives points
  149. for (int i = 0; i < curvePoints.size() - 1; i++){
  150. line(img2, curvePoints[i], curvePoints[i + 1], Scalar(255), 2, CV_AA);
  151.  
  152. }
  153.  
  154. /*imshow("Curve 1 - polylines", img)*/;
  155. imshow("Curve 2 - line", img2);
  156. waitKey(1);
  157. }
  158.  
  159.  
  160.  
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement