Skip to content

Commit

Permalink
Merge pull request #309 from christian-rauch/fix_warnings
Browse files Browse the repository at this point in the history
fix warnings
  • Loading branch information
christian-rauch authored Jan 20, 2024
2 parents 4a689cc + 0720cc4 commit 5c2753e
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 156 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/industrial_ci_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
matrix:
env:
# ROS 1
- {ROS_DISTRO: kinetic}
- {ROS_DISTRO: melodic}
- {ROS_DISTRO: noetic}
# ROS 2
- {ROS_DISTRO: humble}
Expand Down
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.16)
project(apriltag VERSION 3.3.0 LANGUAGES C CXX)

if(POLICY CMP0077)
Expand Down Expand Up @@ -39,6 +39,15 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Werror)
# add_compile_options(-Wpedantic)
add_compile_options(-Wno-shift-negative-value)
if(NOT CMAKE_C_COMPILER_ID MATCHES "AppleClang")
add_link_options("-Wl,-z,relro,-z,now,-z,defs")
endif()
endif()

aux_source_directory(common COMMON_SRC)
set(APRILTAG_SRCS apriltag.c apriltag_pose.c apriltag_quad_thresh.c)

Expand All @@ -50,7 +59,11 @@ if (MSVC)
add_compile_definitions("_CRT_SECURE_NO_WARNINGS")
else()
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads m)
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads)
endif()

if (UNIX)
target_link_libraries(${PROJECT_NAME} PUBLIC m)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 3 VERSION ${PROJECT_VERSION})
Expand Down
17 changes: 8 additions & 9 deletions apriltag.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static void quick_decode_init(apriltag_family_t *family, int maxhamming)

errno = 0;

for (int i = 0; i < family->ncodes; i++) {
for (uint32_t i = 0; i < family->ncodes; i++) {
uint64_t code = family->codes[i];

// add exact code (hamming = 0)
Expand Down Expand Up @@ -624,7 +624,7 @@ static float quad_decode(apriltag_detector_t* td, apriltag_family_t *family, ima
graymodel_init(&whitemodel);
graymodel_init(&blackmodel);

for (int pattern_idx = 0; pattern_idx < sizeof(patterns)/(5*sizeof(float)); pattern_idx ++) {
for (long unsigned int pattern_idx = 0; pattern_idx < sizeof(patterns)/(5*sizeof(float)); pattern_idx ++) {
float *pattern = &patterns[pattern_idx * 5];

int is_white = pattern[4];
Expand Down Expand Up @@ -685,7 +685,7 @@ static float quad_decode(apriltag_detector_t* td, apriltag_family_t *family, ima
double *values = calloc(family->total_width*family->total_width, sizeof(double));

int min_coord = (family->width_at_border - family->total_width)/2;
for (int i = 0; i < family->nbits; i++) {
for (uint32_t i = 0; i < family->nbits; i++) {
int bity = family->bit_y[i];
int bitx = family->bit_x[i];

Expand Down Expand Up @@ -718,7 +718,7 @@ static float quad_decode(apriltag_detector_t* td, apriltag_family_t *family, ima
sharpen(td, values, family->total_width);

uint64_t rcode = 0;
for (int i = 0; i < family->nbits; i++) {
for (uint32_t i = 0; i < family->nbits; i++) {
int bity = family->bit_y[i];
int bitx = family->bit_x[i];
rcode = (rcode << 1);
Expand Down Expand Up @@ -1341,8 +1341,7 @@ zarray_t *apriltag_detector_detect(apriltag_detector_t *td, image_u8_t *im_orig)
int k = (j + 1) & 3;
image_u8x3_draw_line(out,
det->p[j][0], det->p[j][1], det->p[k][0], det->p[k][1],
(uint8_t[]) { rgb[0], rgb[1], rgb[2] },
1);
(uint8_t[]) { rgb[0], rgb[1], rgb[2] });
}
}

Expand Down Expand Up @@ -1424,10 +1423,10 @@ void apriltag_detections_destroy(zarray_t *detections)
zarray_destroy(detections);
}

image_u8_t *apriltag_to_image(apriltag_family_t *fam, int idx)
image_u8_t *apriltag_to_image(apriltag_family_t *fam, uint32_t idx)
{
assert(fam != NULL);
assert(idx >= 0 && idx < fam->ncodes);
assert(idx < fam->ncodes);

uint64_t code = fam->codes[idx];

Expand All @@ -1444,7 +1443,7 @@ image_u8_t *apriltag_to_image(apriltag_family_t *fam, int idx)
}

int border_start = (fam->total_width - fam->width_at_border)/2;
for (int i = 0; i < fam->nbits; i++) {
for (uint32_t i = 0; i < fam->nbits; i++) {
if (code & (APRILTAG_U64_ONE << (fam->nbits - i - 1))) {
im->buf[(fam->bit_y[i] + border_start)*im->stride + fam->bit_x[i] + border_start] = 255;
}
Expand Down
2 changes: 1 addition & 1 deletion apriltag.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void apriltag_detections_destroy(zarray_t *detections);

// Renders the apriltag.
// Caller is responsible for calling image_u8_destroy on the image
image_u8_t *apriltag_to_image(apriltag_family_t *fam, int idx);
image_u8_t *apriltag_to_image(apriltag_family_t *fam, uint32_t idx);

#ifdef __cplusplus
}
Expand Down
20 changes: 10 additions & 10 deletions apriltag_quad_thresh.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ int quad_segment_maxima(apriltag_detector_t *td, zarray_t *cluster, struct line_
}

// returns 0 if the cluster looks bad.
int quad_segment_agg(apriltag_detector_t *td, zarray_t *cluster, struct line_fit_pt *lfps, int indices[4])
int quad_segment_agg(zarray_t *cluster, struct line_fit_pt *lfps, int indices[4])
{
int sz = zarray_size(cluster);

Expand Down Expand Up @@ -893,7 +893,7 @@ int fit_quad(
if (!quad_segment_maxima(td, cluster, lfps, indices))
goto finish;
} else {
if (!quad_segment_agg(td, cluster, lfps, indices))
if (!quad_segment_agg(cluster, lfps, indices))
goto finish;
}

Expand Down Expand Up @@ -1014,7 +1014,7 @@ int fit_quad(

#define DO_UNIONFIND2(dx, dy) if (im->buf[(y + dy)*s + x + dx] == v) unionfind_connect(uf, y*w + x, (y + dy)*w + x + dx);

static void do_unionfind_first_line(unionfind_t *uf, image_u8_t *im, int h, int w, int s)
static void do_unionfind_first_line(unionfind_t *uf, image_u8_t *im, int w, int s)
{
int y = 0;
uint8_t v;
Expand All @@ -1029,7 +1029,7 @@ static void do_unionfind_first_line(unionfind_t *uf, image_u8_t *im, int h, int
}
}

static void do_unionfind_line2(unionfind_t *uf, image_u8_t *im, int h, int w, int s, int y)
static void do_unionfind_line2(unionfind_t *uf, image_u8_t *im, int w, int s, int y)
{
assert(y > 0);

Expand Down Expand Up @@ -1075,7 +1075,7 @@ static void do_unionfind_task2(void *p)
struct unionfind_task *task = (struct unionfind_task*) p;

for (int y = task->y0; y < task->y1; y++) {
do_unionfind_line2(task->uf, task->im, task->h, task->w, task->s, y);
do_unionfind_line2(task->uf, task->im, task->w, task->s, y);
}
}

Expand Down Expand Up @@ -1532,12 +1532,12 @@ unionfind_t* connected_components(apriltag_detector_t *td, image_u8_t* threshim,
unionfind_t *uf = unionfind_create(w * h);

if (td->nthreads <= 1) {
do_unionfind_first_line(uf, threshim, h, w, ts);
do_unionfind_first_line(uf, threshim, w, ts);
for (int y = 1; y < h; y++) {
do_unionfind_line2(uf, threshim, h, w, ts, y);
do_unionfind_line2(uf, threshim, w, ts, y);
}
} else {
do_unionfind_first_line(uf, threshim, h, w, ts);
do_unionfind_first_line(uf, threshim, w, ts);

int sz = h;
int chunksize = 1 + sz / (APRILTAG_TASKS_PER_THREAD_TARGET * td->nthreads);
Expand Down Expand Up @@ -1567,7 +1567,7 @@ unionfind_t* connected_components(apriltag_detector_t *td, image_u8_t* threshim,

// XXX stitch together the different chunks.
for (int i = 1; i < ntasks; i++) {
do_unionfind_line2(uf, threshim, h, w, ts, tasks[i].y0 - 1);
do_unionfind_line2(uf, threshim, w, ts, tasks[i].y0 - 1);
}

free(tasks);
Expand Down Expand Up @@ -1891,7 +1891,7 @@ zarray_t *apriltag_quad_thresh(apriltag_detector_t *td, image_u8_t *im)
for (int x = 0; x < w; x++) {
uint32_t v = unionfind_get_representative(uf, y*w+x);

if (unionfind_get_set_size(uf, v) < td->qtp.min_cluster_pixels)
if ((int)unionfind_get_set_size(uf, v) < td->qtp.min_cluster_pixels)
continue;

uint32_t color = colors[v];
Expand Down
6 changes: 3 additions & 3 deletions common/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int getopt_parse(getopt_t *gopt, int argc, char *argv[], int showErrors)
}

// now loop over the elements and evaluate the arguments
unsigned int i = 0;
int i = 0;

char *tok = NULL;

Expand Down Expand Up @@ -499,7 +499,7 @@ char * getopt_get_usage(getopt_t *gopt)
int longwidth=12;
int valuewidth=10;

for (unsigned int i = 0; i < zarray_size(gopt->options); i++) {
for (int i = 0; i < zarray_size(gopt->options); i++) {
getopt_option_t *goo = NULL;
zarray_get(gopt->options, i, &goo);

Expand All @@ -512,7 +512,7 @@ char * getopt_get_usage(getopt_t *gopt)
valuewidth = max(valuewidth, (int) strlen(goo->svalue));
}

for (unsigned int i = 0; i < zarray_size(gopt->options); i++) {
for (int i = 0; i < zarray_size(gopt->options); i++) {
getopt_option_t *goo = NULL;
zarray_get(gopt->options, i, &goo);

Expand Down
2 changes: 1 addition & 1 deletion common/homography.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ matd_t *homography_to_pose(const matd_t *H, double fx, double fy, double cx, dou
// [ 0 0 C D ]
// [ 0 0 -1 0 ]

matd_t *homography_to_model_view(const matd_t *H, double F, double G, double A, double B, double C, double D)
matd_t *homography_to_model_view(const matd_t *H, double F, double G, double A, double B)
{
// Note that every variable that we compute is proportional to the scale factor of H.
double R20 = -MATD_EL(H, 2, 0);
Expand Down
2 changes: 1 addition & 1 deletion common/homography.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ matd_t *homography_to_pose(const matd_t *H, double fx, double fy, double cx, dou
// [ 0 0 C D ]
// [ 0 0 -1 0 ]

matd_t *homography_to_model_view(const matd_t *H, double F, double G, double A, double B, double C, double D);
matd_t *homography_to_model_view(const matd_t *H, double F, double G, double A, double B);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion common/image_u8.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int image_u8_write_pnm(const image_u8_t *im, const char *path)
fprintf(f, "P5\n%d %d\n255\n", im->width, im->height);

for (int y = 0; y < im->height; y++) {
if (im->width != fwrite(&im->buf[y*im->stride], 1, im->width, f)) {
if (im->width != (int32_t)fwrite(&im->buf[y*im->stride], 1, im->width, f)) {
res = -2;
goto finish;
}
Expand Down
4 changes: 2 additions & 2 deletions common/image_u8x3.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int image_u8x3_write_pnm(const image_u8x3_t *im, const char *path)

// Only outputs to RGB
fprintf(f, "P6\n%d %d\n255\n", im->width, im->height);
int linesz = im->width * 3;
size_t linesz = im->width * 3;
for (int y = 0; y < im->height; y++) {
if (linesz != fwrite(&im->buf[y*im->stride], 1, linesz, f)) {
res = -1;
Expand All @@ -163,7 +163,7 @@ int image_u8x3_write_pnm(const image_u8x3_t *im, const char *path)
}

// only width 1 supported
void image_u8x3_draw_line(image_u8x3_t *im, float x0, float y0, float x1, float y1, uint8_t rgb[3], int width)
void image_u8x3_draw_line(image_u8x3_t *im, float x0, float y0, float x1, float y1, uint8_t rgb[3])
{
double dist = sqrtf((y1-y0)*(y1-y0) + (x1-x0)*(x1-x0));
double delta = 0.5 / dist;
Expand Down
2 changes: 1 addition & 1 deletion common/image_u8x3.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void image_u8x3_destroy(image_u8x3_t *im);
int image_u8x3_write_pnm(const image_u8x3_t *im, const char *path);

// only width 1 supported
void image_u8x3_draw_line(image_u8x3_t *im, float x0, float y0, float x1, float y1, uint8_t rgb[3], int width);
void image_u8x3_draw_line(image_u8x3_t *im, float x0, float y0, float x1, float y1, uint8_t rgb[3]);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 5c2753e

Please sign in to comment.