0

For background, I am implementing this code in Vitis HLS. When I try to print values for my possible_radius and tested_angle arrays it always outputs zero and I dont know why.

// extrafiles.h

#include <math.h>
int possible_radius[363];
float tested_angles[361];
float cosines[361];
float sines[361];

void createfiles();

// extrafiles.c

#include "extras.h"

float tested_angles[361];
int possible_radius[363];
float cosines[361];
float sines[361];

void createfiles(){

    for(int i = 0;i < 363;i++){
        possible_radius[i] = i + 1;
    }
    for(int j = 0; j < 361; j++) {
        tested_angles[j] = -M_PI + j * ((M_PI + M_PI) / 360.0);
    }
    for(int k = 0; k < 361; k++) {
        cosines[k] = cos(tested_angles[k]);
        sines[k] = sin(tested_angles[k]);
    }
}

// hough.c (top function)
#include "hough.h"
#include "extras.h"
#include <stdio.h>

#define Len ROWS * COLS
#define max_distance 363
#define thetas 361

unsigned int accumulator[max_distance][thetas] = {0};

int xcoord[257]; // Set to an arbitrarily large amount so that any number of coordinates can be passed in
int ycoord[257];
int current_max = 0;

void createfiles();

void hough(unsigned int testarray[ROWS][COLS], float *slope1, float *intercept1){

    #pragma HLS INTERFACE s_axilite port=return
    #pragma HLS INTERFACE s_axilite port=return
    #pragma HLS PIPELINE

    int i, j, radius1,z,k; // All the integers I will use
    float theta1, xi, yi,i1,s1;
    double r;

    // First loop grabs our x and y values from the image
    z = 0;
    for (i=0;i<ROWS;i++){
        k = 255 - i;
        for (j=0;j<COLS;j++){
            if (testarray[k][j] != 0){
                ycoord[z] = i;
                xcoord[z] = j;
                z += 1;
            }
        }
    }
    for (i=0;i<257;i++){
        for (j=0;j<thetas;j++){
            r = abs(xcoord[i] * cosines[j] + ycoord[i] * sines[j]);
            accumulator[(int)r][j] += 1;
        }
    }
    for (i=0;i<max_distance;i++){
        for (j=0;j<thetas;j++){
            if (accumulator[i][j] > current_max){
                current_max = accumulator[i][j];
                radius1 = possible_radius[i];
                theta1 = tested_angles[j];
            }
        }
    }
    printf("%d\n",possible_radius[50]);
    printf("%f\n",tested_angles[0]);

        // Calculating the slope and intercept from top radius and theta
    s1 = tan(theta1 + M_PI/2.00);
    xi = radius1 * cos(theta1 + M_PI_2);
    yi = (radius1 - xi*cos(theta1 + M_PI_2)) / sin(theta1 + M_PI_2);
    i1 = yi - (s1 * xi);

    *slope1 = tested_angles[200];
    *intercept1 = cosines[180];

}
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • The problem is that writing e.g. `int possible_radius[363];` makes **each translation unit** that does `#include extrafiles.h` have a **separate** array, because `#include` is a **literal copy and paste** operation that modifies source code before it is seen by the compiler. To share the data between translation units, the ones that don't actually define the data should declare it using the `extern` keyword. The normal way to do this is by using `extern` in the header (it's not a problem when the `extrafiles.c` implementation includes this, because it is only a definition). – Karl Knechtel Mar 10 '23 at 03:13

0 Answers0