7 #include <opencv2/highgui/highgui_c.h> 411 int id,
int direction,
double world_diagonal,
412 double x1,
double y1,
double x2,
double y2,
413 double x3,
double y3,
double x4,
double y4) {
415 "Fiducial: id=%d dir=%d diag=%.2f (%.2f,%.2f), " 416 "(%.2f,%.2f), (%.2f,%.2f), (%.2f,%.2f)",
417 id, direction, world_diagonal, x1, y1, x2, y2, x3, y3, x4, y4);
464 unsigned int debug_index = 0;
465 unsigned int previous_debug_index = debug_index;
473 cvShowImage(window_name, debug_image);
477 char control_character =
'\0';
479 control_character = (char)(cvWaitKey(0) & 0xff);
483 switch (control_character) {
495 if (debug_index > 0) {
519 if ((
unsigned int)control_character <= 127) {
521 "Unknown control character %d\n", control_character);
530 if (debug_index != previous_debug_index) {
532 "****************************debug_index = %d\n", debug_index);
533 previous_debug_index = debug_index;
540 cvDestroyWindow(window_name);
572 File log_file = stderr;
574 String full_log_file_name =
579 File__format(log_file,
"CV width=%d CV height = %d\n", width, height);
581 int term_criteria_type =
587 static int north_mapping_flipped[64] = {
589 7, 6, 5, 4, 3, 2, 1, 0,
590 15, 14, 13, 12, 11, 10, 9, 8,
591 23, 22, 21, 20, 19, 18, 17, 16,
592 31, 30, 29, 28, 27, 26, 25, 24,
593 39, 38, 37, 36, 35, 34, 33, 32,
594 47, 46, 45, 44, 43, 42, 41, 40,
595 55, 54, 53, 52, 51, 50, 49, 48,
596 63, 62, 61, 60, 59, 58, 57, 56,
600 static int west_mapping_flipped[64] = {
602 63, 55, 47, 39, 31, 23, 15, 7,
603 62, 54, 46, 38, 30, 22, 14, 6,
604 61, 53, 45, 37, 29, 21, 13, 5,
605 60, 52, 44, 36, 28, 20, 12, 4,
606 59, 51, 43, 35, 27, 19, 11, 3,
607 58, 50, 42, 34, 26, 18, 10, 2,
608 57, 49, 41, 33, 25, 17, 9, 1,
609 56, 48, 40, 32, 24, 16, 8, 0,
613 static int south_mapping_flipped[64] = {
615 56, 57, 58, 59, 60, 61, 62, 63,
616 48, 49, 50, 51, 52, 53, 54, 55,
617 40, 41, 42, 43, 44, 45, 46, 47,
618 32, 33, 34, 35, 36, 37, 38, 39,
619 24, 25, 26, 27, 28, 29, 30, 31,
620 16, 17, 18, 19, 20, 21, 22, 23,
621 8, 9, 10, 11, 12, 13, 14, 15,
622 0, 1, 2, 3, 4, 5, 6, 7,
626 static int east_mapping_flipped[64] = {
628 0, 8, 16, 24, 32, 40, 48, 56,
629 1, 9, 17, 25, 33, 41, 49, 57,
630 2, 10, 18, 26, 34, 42, 50, 58,
631 3, 11, 19, 27, 35, 43, 51, 59,
632 4, 13, 20, 28, 36, 44, 52, 60,
633 5, 13, 21, 29, 37, 45, 53, 61,
634 6, 14, 22, 30, 38, 46, 54, 62,
635 7, 15, 23, 31, 39, 47, 55, 63,
642 static int *mappings[4] = {
643 &north_mapping_flipped[0],
644 &west_mapping_flipped[0],
645 &south_mapping_flipped[0],
646 &east_mapping_flipped[0],
663 if (fiducial_announce_routine != NULL)
669 fiducials->
blur = (bool)0;
682 fiducials->
map_x = map_x;
683 fiducials->
map_y = map_y;
687 fiducials->
path = fiducials_path;
702 fiducials->
y_flip = (bool)0;
764 if (debug_index == 0) {
772 if (debug_index == 0) {
776 }
else if (channels == 1) {
787 }
else if (channels == 1) {
795 if (debug_index == 1) {
801 int flags = CV_INTER_NN | CV_WARP_FILL_OUTLIERS;
808 if (debug_index == 2) {
813 if (fiducials->
blur) {
818 if (debug_index == 3) {
827 if (debug_index == 4) {
833 int header_size = 128;
841 if (debug_index == 5) {
846 contours, red, red, 2, 2, 8, origin);
850 if (debug_index >= 5) {
855 unsigned int contours_count = 0;
864 whole_sequence = CV_WHOLE_SEQ;
872 if (debug_index == 6) {
876 polygon_contour, green, green, 2, 2, 1, origin);
883 CV__whole_seq, 0)) > 500.0 &&
889 if (debug_index == 7) {
892 polygon_contour, red, red, 2, 2, 1, origin);
904 if (debug_index == 7) {
920 if (debug_index == 8) {
930 color = fiducials->
red;
934 color = fiducials->
green;
938 color = fiducials->
blue;
942 color = fiducials->
purple;
950 "poly_point[%d]=(%d:%d) %s\n",
index, x, y, text);
972 int threshold = (white_darkest + black_lightest) / 2;
977 if (debug_index == 9) {
990 if (value < threshold) {
999 if (black_lightest < white_darkest) {
1009 bool *tag_bits = &fiducials->
tag_bits[0];
1018 int bit = (value < threshold);
1019 tag_bits[
index] = bit;
1022 if (debug_index == 10) {
1056 int **mappings = fiducials->
mappings;
1057 unsigned int mappings_size = 4;
1058 for (
unsigned int direction_index = 0;
1059 direction_index < mappings_size; direction_index++) {
1061 int *mapping = mappings[direction_index];
1066 int mapped_bits[64];
1067 for (
unsigned int i = 0; i < 64; i++) {
1068 mapped_bits[mapping[i]] = tag_bits[i];
1072 unsigned int tag_bytes[8];
1073 for (
unsigned int i = 0; i < 8; i++) {
1074 unsigned int byte = 0;
1075 for (
unsigned int j = 0; j < 8; j++) {
1076 if (mapped_bits[(i<<3) + j]) {
1078 byte |= 1 << (7 - j);
1081 tag_bytes[i] = byte;
1083 if (debug_index == 11) {
1085 "dir=%d Tag[0]=0x%x Tag[1]=0x%x\n",
1086 direction_index, tag_bytes[0], tag_bytes[1]);
1090 FEC fec = fiducials->
fec;
1093 if (debug_index == 11) {
1098 unsigned int computed_crc =
CRC__compute(tag_bytes, 2);
1099 unsigned int tag_crc = (tag_bytes[3] << 8) | tag_bytes[2];
1100 if (computed_crc == tag_crc) {
1104 unsigned int tag_id =
1105 (tag_bytes[1] << 8) | tag_bytes[0];
1107 if (debug_index == 11) {
1109 "CRC correct, Tag=%d\n", tag_id);
1112 double vertices[4][2];
1115 vertices[
index][0] = pt->x;
1116 vertices[
index][1] = pt->y;
1120 direction_index, 0.0,
1121 vertices[0][0], vertices[0][1],
1122 vertices[1][0], vertices[1][1],
1123 vertices[2][0], vertices[2][1],
1124 vertices[3][0], vertices[3][1]);
1153 static int weights0[9] = {
1158 static int weights1[9] = {
1163 static int weights2[9] = {
1169 static int x_offsets[9] = {
1173 static int y_offsets[9] = {
1179 int *weights = (
int *)0;
1194 int denominator = 0;
1197 x + x_offsets[
index], y + y_offsets[index]);
1199 int weight = weights[
index];
1200 numerator += sample * weight;
1201 denominator += weight;
1207 if (denominator > 0) {
1208 result = numerator / denominator;
1269 double v1x = x1 - x0;
1270 double v1y = y1 - y0;
1271 double v2x = x2 - x1;
1272 double v2y = y2 - y1;
1275 double z = v1x * v2y - v2x * v1y;
1325 double dx21 = x2 - x1;
1326 double dy21 = y2 - y1;
1327 double dx30 = x3 - x0;
1328 double dy30 = y3 - y0;
1332 double xx0 = x1 + dx21 * 5.0 / 20.0;
1333 double yy0 = y1 + dy21 * 5.0 / 20.0;
1334 double xx1 = x0 + dx30 * 5.0 / 20.0;
1335 double yy1 = y0 + dy30 * 5.0 / 20.0;
1339 double dxx10 = xx1 - xx0;
1340 double dyy10 = yy1 - yy0;
1352 double xx2 = x1 + dx21 * 15.0 / 20.0;
1353 double yy2 = y1 + dy21 * 15.0 / 20.0;
1354 double xx3 = x0 + dx30 * 15.0 / 20.0;
1355 double yy3 = y0 + dy30 * 15.0 / 20.0;
1359 double dxx32 = xx3 - xx2;
1360 double dyy32 = yy3 - yy2;
1398 if (value > result) {
1422 int result = 0x7fffffff;
1428 if (value < result) {
1473 double dx21 = x2 - x1;
1474 double dy21 = y2 - y1;
1475 double dx30 = x3 - x0;
1476 double dy30 = y3 - y0;
1479 unsigned int index = 0;
1487 double i_fraction = 3.0 / 20.0;
1488 double i_increment = 2.0 / 20.0;
1497 double xx1 = x1 + dx21 * i_fraction;
1498 double yy1 = y1 + dy21 * i_fraction;
1499 double xx2 = x0 + dx30 * i_fraction;
1500 double yy2 = y0 + dy30 * i_fraction;
1503 double dxx21 = xx2 - xx1;
1504 double dyy21 = yy2 - yy1;
1509 double j_fraction = 3.0 / 20.0;
1510 double j_increment = 2.0 / 20.0;
1525 j_fraction = j_fraction + j_increment;
1530 i_fraction = i_fraction + i_increment;
void CV_Point2D32F__x_set(CV_Point2D32F point, double x)
CV_Point2D32F_Vector sample_points
CV_Point2D32F_Vector corners
CV_Memory_Storage CV_Memory_Storage__create(int block_size)
void CV_Image__copy(CV_Image source_image, CV_Image destination_image, CV_Image mask)
static struct Fiducials_Create__Struct fiducials_create_struct
int CV_Sequence__total_get(CV_Sequence sequence)
CV_Image temporary_gray_image
void Memory__free(Memory memory)
Releases the storage associated with memory.
void String__free(String_Const string)
will free memory assciated with string.
Fiducials_Fiducial_Announce_Routine fiducial_announce_routine
void CV_Memory_Storage__clear(CV_Memory_Storage storage)
double CV_Point2D32F__y_get(CV_Point2D32F point)
void CV_Image__smooth(CV_Image source_image, CV_Image destination_image, int smooth_type, int parameter1, int parameter2, double parameter3, double parameter4)
void Fiducials__image_show(Fiducials fiducials, bool show)
Is a HighGUI interface to show the current image.
int CV_Point__y_get(CV_Point point)
String_Const fiducials_path
int CV_Point__x_get(CV_Point point)
void CV_Point2D32F__point_set(CV_Point2D32F point2d32f, CV_Point point)
int Fiducials__points_minimum(Fiducials fiducials, CV_Point2D32F_Vector points, unsigned int start_index, unsigned int end_index)
Return the minimum value of the points in points.
CV_Term_Criteria term_criteria
CvPoint2D32f * CV_Point2D32F
FILE * File
FILE is a file I/O object.
CV_Sequence CV_Sequence__approximate_polygon(CV_Sequence contour, int header_size, CV_Memory_Storage storage, int method, int parameter1, double parameter2)
void CV_Image__find_corner_sub_pix(CV_Image image, CV_Point2D32F_Vector corners, int count, CV_Size window, CV_Size zero_zone, CV_Term_Criteria criteria)
CV_Sequence CV_Image__find_contours(CV_Image image, CV_Memory_Storage storage, int header_size, int mode, int method, CV_Point point)
CV_Term_Criteria CV_Term_Criteria__create(int type, int maximum_iterations, double epsilon)
void CV_Scalar__free(CV_Scalar cv_scalar)
CvPoint2D32f * CV_Point2D32F_Vector
CV_Memory_Storage storage
int CV__term_criteria_iterations
Fiducials_Fiducial_Announce_Routine fiducial_announce_routine
bool CV_Point2D32F_Vector__is_clockwise(CV_Point2D32F_Vector corners)
Return true if corners is in a clockwise direction.
int CV_Image__width_get(CV_Image image)
Fiducials_Results results
CvMemStorage * CV_Memory_Storage
#define Memory__new(Type, from)
Allocate a Type object from the heap.
void File__format(File file, String_Const format,...)
will write format out to file with all patterns that start with "%" replaced by formatted versions of...
CV_Image CV_Image__create(CV_Size size, unsigned int depth, unsigned int channels)
char * String
Copyright (c) 2013-2014 by Wayne C. Gramlich. All rights reserved.
void(* Fiducials_Fiducial_Announce_Routine)(void *announce_object, int id, int direction, double world_diagonal, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
CV_Point2D32F CV_Point2D32F_Vector__fetch1(CV_Point2D32F_Vector vector, unsigned int index)
Fiducials Fiducials__create(CV_Image original_image, Fiducials_Create fiducials_create)
Create and return a Fiducials object.
CV_Point CV_Sequence__point_fetch1(CV_Sequence sequence, unsigned int index)
int Fiducials__points_maximum(Fiducials fiducials, CV_Point2D32F_Vector points, unsigned int start_index, unsigned int end_index)
Return the maximum value of the points in points.
CV_Scalar CV_Scalar__rgb(double red, double green, double blue)
void CV_Image__adaptive_threshold(CV_Image source_image, CV_Image destination_image, double maximum_value, int adaptive_method, int threshold_type, int block_size, double parameter1)
void CV_Image__remap(CV_Image source_image, CV_Image destination_image, CV_Image map_x, CV_Image map_y, int flags, CV_Scalar fill_value)
int CV_Image__gray_fetch(CV_Image image, int x, int y)
int CV_Image__height_get(CV_Image image)
void CV_Image__convert_color(CV_Image source_image, CV_Image destination_image, int conversion_code)
bool CV_Sequence__check_contour_convexity(CV_Sequence contour)
void Fiducials__fiducial_announce(void *announce_object, int id, int direction, double world_diagonal, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
Callback routine tthat prints out the fidicial information.
Fiducials_Create Fiducials_Create__one_and_only(void)
Returns the one and only Fiducials_Create object.
CV_Point2D32F_Vector Fiducials__references_compute(Fiducials fiducials, CV_Point2D32F_Vector corners)
Return 8 sample locations to determine if a quadralateral is worth testing for quadralateral'ness.
unsigned int sequence_number
int CV__round(double value)
int CV__term_criteria_eps
FEC FEC__create(unsigned int symbol_size, unsigned int data_size, unsigned int parity_size)
CV_Point CV_Point__create(int x, int y)
unsigned int CRC__compute(unsigned int *buffer, unsigned int size)
Returns a 16-bit CRC of the size bytes in buffer.
Fiducials_Results Fiducials__process(Fiducials fiducials)
Process the current image associated with fiducials.
void * Memory
Memory is a pointer to memory.
unsigned int weights_index
CV_Sequence CV_Sequence__next_get(CV_Sequence sequence)
int CV__chain_approx_simple
File File__open(String_Const file_name, String_Const flags)
will open file_name using flags to specify read/write options.
void Fiducials__map_save(Fiducials fiducials)
Force the map associated with fiducials to be saved.
void CV_Point2D32F__y_set(CV_Point2D32F point, double y)
int CV__adaptive_thresh_gaussian_c
CV_Point2D32F_Vector CV_Point2D32F_Vector__create(unsigned int size)
double CV_Sequence__arc_length(CV_Sequence contour, CV_Slice slice, int is_closed)
CV_Size CV_Size__create(int width, int height)
void CV_Size__free(CV_Size cv_size)
const char * String_Const
CV_Point2D32F_Vector references
double CV_Sequence__contour_area(CV_Sequence contour, CV_Slice slice, int oriented)
void CV_Image__cross_draw(CV_Image image, int x, int y, CV_Scalar color)
String_Const log_file_name
void Fiducials__sample_points_compute(CV_Point2D32F_Vector corners, CV_Point2D32F_Vector sample_points)
Compute the fiducial locations to sample using corners
void CV_Image__draw_contours(CV_Image image, CV_Sequence contour, CV_Scalar external_color, CV_Scalar hole_color, int maximal_level, int thickness, int line_type, CV_Point offset)
double CV_Point2D32F__x_get(CV_Point2D32F point)
void CV_Point2D32F_Vector__corners_normalize(CV_Point2D32F_Vector corners)
Force corners to be counter-clockwise.
static CvSlice whole_sequence
int Fiducials__point_sample(Fiducials fiducials, CV_Point2D32F point)
Helper routine to sample a point from the image in fiducials.
bool FEC__correct(FEC fec, unsigned int *data, unsigned int size)
void Fiducials__image_set(Fiducials fiducials, CV_Image image)
Sets the original image for *fiducials.
void Fiducials__free(Fiducials fiducials)
will release the storage associated with fiducials.
int CV_Image__channels_get(CV_Image image)
String String__format(String_Const format,...)
Return a formatted version of format.
void CV__release_image(CV_Image image)