Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- *
- * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * Use of the Software is limited solely to applications:
- * (a) running on a Xilinx device, or
- * (b) that interact with a Xilinx device through a bus or interconnect.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * Except as contained in this notice, the name of the Xilinx shall not be used
- * in advertising or otherwise to promote the sale, use or other dealings in
- * this Software without prior written authorization from Xilinx.
- *
- ******************************************************************************/
- /*
- * helloworld.c: simple test application
- *
- * This application configures UART 16550 to baud rate 9600.
- * PS7 UART (Zynq) is not initialized by this application, since
- * bootrom/bsp configures it to baud rate 115200
- *
- * ------------------------------------------------
- * | UART TYPE BAUD RATE |
- * ------------------------------------------------
- * uartns550 9600
- * uartlite Configurable only in HW design
- * ps7_uart 115200 (configured by bootrom/bsp)
- */
- #include <stdio.h>
- #include "platform.h"
- #include "xil_printf.h"
- #include "xuartlite.h"
- #include "xuartlite_i.h"
- #define UART_ADDR 0x40600000
- #define WIDTH 50
- #define HEIGHT 50
- #define PI 3.1415
- #define WHITE 0
- #define BLACK 255
- void binarizare(unsigned char *image, unsigned char thresh)
- {
- int i;
- for (i = 0; i < WIDTH * HEIGHT; i++)
- if (image[i] >= thresh)
- image[i] = WHITE;
- else
- image[i] = BLACK ;
- }
- int gasireCentru(unsigned char *image)
- {
- long int xSum = 0;
- long int ySum = 0;
- int count = 0;
- int x, y;
- for (x = 0; x < WIDTH; x++)
- {
- for (y = 0; y < HEIGHT; y++)
- {
- if (image[x * WIDTH + y] == 255)
- {
- xSum += x;
- ySum += y;
- count++;
- }
- }
- }
- xSum /= count;
- ySum /= count;
- return xSum * WIDTH + ySum;
- }
- /*
- float sinus(float angle)
- {
- return angle
- - angle * angle * angle / 6
- + angle * angle * angle * angle * angle / 120
- - angle * angle * angle * angle * angle * angle * angle / 5040;
- }
- float cosinus(float angle)
- {
- return 1
- - angle * angle / 2
- + angle * angle * angle * angle / 24
- - angle * angle * angle * angle * angle * angle / 720;
- }
- int gasireRaza(unsigned char *image, int xCenter, int yCenter)
- {
- int radius, degrees, foundPoints, x, y;
- int maxRadius = xCenter;
- if (49 - xCenter < maxRadius) maxRadius = 49 - xCenter;
- if (yCenter < maxRadius) maxRadius = yCenter;
- if (49 - yCenter < maxRadius) maxRadius = 49 - yCenter;
- int finalRadius = -1;
- for (radius = 2; radius < maxRadius; radius++)
- {
- foundPoints = 0;
- for (degrees = 0; degrees < 360; degrees += 20)
- {
- x = (int)(sinus(degrees * PI / 180) * radius);
- y = (int)(cosinus(degrees * PI / 180) * radius);
- if (image[x * WIDTH + y] == 255) foundPoints++;
- }
- if (foundPoints > 40) finalRadius = radius;
- }
- return finalRadius;
- }*/
- int main()
- {
- init_platform();
- print("Hello World\n\r");
- int i = 0;
- unsigned char image[WIDTH * HEIGHT];
- while(i < WIDTH * HEIGHT)
- {
- unsigned char byte = XUartLite_RecvByte(UART_ADDR);
- image[i] = byte;
- i++;
- }
- binarizare(image, 178);
- int centru = gasireCentru(image);
- int xCentru = centru / 50;
- int yCentru = centru % 50;
- char arr[] = "Centru: x = ; y = ; raza = \n";
- arr[12] = (xCentru / 10) + '0';
- arr[13] =(xCentru % 10) + '0';
- arr[20] = (yCentru / 10) + '0';
- arr[21] =(yCentru % 10) + '0';
- int raza = gasireRaza(image, xCentru, yCentru);
- arr[30] = (raza / 10) + '0';
- arr[31] = (raza % 10) + '0';
- while (1)
- print(arr);
- cleanup_platform();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment