Guest User

aaa

a guest
Jan 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * Use of the Software is limited solely to applications:
  16. * (a) running on a Xilinx device, or
  17. * (b) that interact with a Xilinx device through a bus or interconnect.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. *
  27. * Except as contained in this notice, the name of the Xilinx shall not be used
  28. * in advertising or otherwise to promote the sale, use or other dealings in
  29. * this Software without prior written authorization from Xilinx.
  30. *
  31. ******************************************************************************/
  32.  
  33. /*
  34. * helloworld.c: simple test application
  35. *
  36. * This application configures UART 16550 to baud rate 9600.
  37. * PS7 UART (Zynq) is not initialized by this application, since
  38. * bootrom/bsp configures it to baud rate 115200
  39. *
  40. * ------------------------------------------------
  41. * | UART TYPE BAUD RATE |
  42. * ------------------------------------------------
  43. * uartns550 9600
  44. * uartlite Configurable only in HW design
  45. * ps7_uart 115200 (configured by bootrom/bsp)
  46. */
  47.  
  48. #include <stdio.h>
  49. #include "platform.h"
  50. #include "xil_printf.h"
  51. #include "xuartlite.h"
  52. #include "xuartlite_i.h"
  53.  
  54. #define UART_ADDR 0x40600000
  55. #define WIDTH 50
  56. #define HEIGHT 50
  57. #define PI 3.1415
  58. #define WHITE 0
  59. #define BLACK 255
  60.  
  61. void binarizare(unsigned char *image, unsigned char thresh)
  62. {
  63. int i;
  64. for (i = 0; i < WIDTH * HEIGHT; i++)
  65. if (image[i] >= thresh)
  66. image[i] = WHITE;
  67. else
  68. image[i] = BLACK ;
  69. }
  70.  
  71. int gasireCentru(unsigned char *image)
  72. {
  73. long int xSum = 0;
  74. long int ySum = 0;
  75. int count = 0;
  76. int x, y;
  77.  
  78. for (x = 0; x < WIDTH; x++)
  79. {
  80. for (y = 0; y < HEIGHT; y++)
  81. {
  82. if (image[x * WIDTH + y] == 255)
  83. {
  84. xSum += x;
  85. ySum += y;
  86. count++;
  87. }
  88. }
  89. }
  90.  
  91. xSum /= count;
  92. ySum /= count;
  93. return xSum * WIDTH + ySum;
  94. }
  95. /*
  96. float sinus(float angle)
  97. {
  98. return angle
  99. - angle * angle * angle / 6
  100. + angle * angle * angle * angle * angle / 120
  101. - angle * angle * angle * angle * angle * angle * angle / 5040;
  102. }
  103.  
  104. float cosinus(float angle)
  105. {
  106. return 1
  107. - angle * angle / 2
  108. + angle * angle * angle * angle / 24
  109. - angle * angle * angle * angle * angle * angle / 720;
  110. }
  111.  
  112. int gasireRaza(unsigned char *image, int xCenter, int yCenter)
  113. {
  114. int radius, degrees, foundPoints, x, y;
  115. int maxRadius = xCenter;
  116. if (49 - xCenter < maxRadius) maxRadius = 49 - xCenter;
  117. if (yCenter < maxRadius) maxRadius = yCenter;
  118. if (49 - yCenter < maxRadius) maxRadius = 49 - yCenter;
  119. int finalRadius = -1;
  120.  
  121. for (radius = 2; radius < maxRadius; radius++)
  122. {
  123. foundPoints = 0;
  124. for (degrees = 0; degrees < 360; degrees += 20)
  125. {
  126. x = (int)(sinus(degrees * PI / 180) * radius);
  127. y = (int)(cosinus(degrees * PI / 180) * radius);
  128. if (image[x * WIDTH + y] == 255) foundPoints++;
  129. }
  130. if (foundPoints > 40) finalRadius = radius;
  131. }
  132. return finalRadius;
  133. }*/
  134.  
  135. int main()
  136. {
  137. init_platform();
  138.  
  139. print("Hello World\n\r");
  140. int i = 0;
  141. unsigned char image[WIDTH * HEIGHT];
  142.  
  143. while(i < WIDTH * HEIGHT)
  144. {
  145. unsigned char byte = XUartLite_RecvByte(UART_ADDR);
  146. image[i] = byte;
  147. i++;
  148. }
  149.  
  150. binarizare(image, 178);
  151. int centru = gasireCentru(image);
  152. int xCentru = centru / 50;
  153. int yCentru = centru % 50;
  154. char arr[] = "Centru: x = ; y = ; raza = \n";
  155. arr[12] = (xCentru / 10) + '0';
  156. arr[13] =(xCentru % 10) + '0';
  157. arr[20] = (yCentru / 10) + '0';
  158. arr[21] =(yCentru % 10) + '0';
  159. int raza = gasireRaza(image, xCentru, yCentru);
  160. arr[30] = (raza / 10) + '0';
  161. arr[31] = (raza % 10) + '0';
  162. while (1)
  163. print(arr);
  164.  
  165. cleanup_platform();
  166. return 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment