#include <stdint.h>
#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | nv2_image_patch |
Represents an image patch, with image data stored in row-major fashion. More... | |
struct | nv2_patch_label |
Represents a label for an image patch. More... | |
Defines | |
#define | NV2_EXTERN_C |
#define | NV2_PATCH_PROTOCOL_VERSION ((uint32_t) 1004) |
Represents the current version of struct nv2_image_patch. | |
#define | NV2_IMAGE_PATCH_HEADER_SIZE (sizeof(struct nv2_image_patch) - sizeof(unsigned char*)) |
#define | NV2_LABEL_PROTOCOL_VERSION ((uint32_t) 2004) |
Represents the current version of struct nv2_patch_label. | |
#define | NV2_MAX_LABEL_CONFIDENCE 10000u |
The scaling factor used to represent confidence levels in nv2_patch_label. | |
#define | nv2_fatal(what) nv2_fatal_impl(__FILE__, __LINE__, __FUNCTION__, what) |
Print an error message to stderr and exit. | |
#define | nv2_warn(what) nv2_warn_impl(__FILE__, __LINE__, __FUNCTION__, what) |
Print a warning message to stderr. | |
#define | NV2_PATCH_READER_PORT 9930 |
Default tcp port number for the patch reader. | |
#define | NV2_LABEL_READER_PORT 9931 |
Default tcp port number for the label reader. | |
Enumerations | |
enum | nv2_pixel_type { NV2_PIXEL_TYPE_NONE = 5000, NV2_PIXEL_TYPE_GRAY8 = 5001, NV2_PIXEL_TYPE_RGB24 = 5002 } |
Different pixel types that can be stored in an nv2_image_patch. More... | |
Functions | |
uint32_t | nv2_pixel_type_bytes_per_pixel (enum nv2_pixel_type typ) |
Get the number of bytes used per pixel of a given type. | |
NV2_EXTERN_C void | nv2_image_patch_init_empty (struct nv2_image_patch *p) |
Initialize with the current protocol version, and zeros elsewhere. | |
NV2_EXTERN_C void | nv2_image_patch_destroy (struct nv2_image_patch *p) |
Free the data array associated with p, and reinitialize to an empty state. | |
NV2_EXTERN_C void | nv2_image_patch_set_training_label (struct nv2_image_patch *p, const char *label) |
Copy a training label into the image patch. | |
NV2_EXTERN_C void | nv2_image_patch_set_remote_command (struct nv2_image_patch *p, const char *command) |
Copy a remote command into the image patch. | |
NV2_EXTERN_C void | nv2_patch_label_init_empty (struct nv2_patch_label *l) |
Initialize with the current protocol version, and zeros elsewhere. | |
NV2_EXTERN_C void | nv2_fatal_impl (const char *file, int line, const char *function, const char *what) |
Helper for nv2_fatal. | |
NV2_EXTERN_C void | nv2_warn_impl (const char *file, int line, const char *function, const char *what) |
Helper for nv2_warn. | |
size_t | nv2_robust_write (int fd, const void *data, size_t nbytes) |
Keep doing write() calls until either all the bytes are written or an error occurs. | |
size_t | nv2_robust_read (int fd, void *buf, size_t nbytes, int *nchunks) |
Keep doing read() calls until either all the bytes are read or an error occurs. |
Definition in file nv2_common.h.
#define nv2_fatal | ( | what | ) | nv2_fatal_impl(__FILE__, __LINE__, __FUNCTION__, what) |
Print an error message to stderr and exit.
Definition at line 150 of file nv2_common.h.
Referenced by nv2_label_reader_create(), nv2_label_reader_destroy(), nv2_label_reader_send_patch_sync(), nv2_label_server_create(), nv2_label_server_destroy(), nv2_label_server_send_label(), and nv2_pixel_type_bytes_per_pixel().
#define NV2_LABEL_PROTOCOL_VERSION ((uint32_t) 2004) |
Represents the current version of struct nv2_patch_label.
Be sure to assign the proper protocol_version before sending any nv2_patch_label objects across the network, and be sure to check the protocol_version field of any nv2_patch_label objects received from the network before using any of the other data fields.
Definition at line 118 of file nv2_common.h.
Referenced by nv2_patch_label_init_empty().
#define NV2_LABEL_READER_PORT 9931 |
Default tcp port number for the label reader.
Definition at line 181 of file nv2_common.h.
#define NV2_MAX_LABEL_CONFIDENCE 10000u |
The scaling factor used to represent confidence levels in nv2_patch_label.
A raw confidence value in [0,1] should be encoded as uint32_t(0.5 + raw*NV2_MAX_LABEL_CONFIDENCE)
Definition at line 138 of file nv2_common.h.
#define NV2_PATCH_PROTOCOL_VERSION ((uint32_t) 1004) |
Represents the current version of struct nv2_image_patch.
Make sure that any struct nv2_image_patch objects to be sent across the network have this value assigned to their protocol_version field, and make sure that any struct nv2_image_patch objects received from the network have the proper protocol_version before using the other data fields.
Definition at line 68 of file nv2_common.h.
Referenced by nv2_image_patch_init_empty().
#define NV2_PATCH_READER_PORT 9930 |
Default tcp port number for the patch reader.
Definition at line 178 of file nv2_common.h.
#define nv2_warn | ( | what | ) | nv2_warn_impl(__FILE__, __LINE__, __FUNCTION__, what) |
Print a warning message to stderr.
Definition at line 158 of file nv2_common.h.
Referenced by nv2_label_reader_send_patch_sync(), and nv2_label_server_send_label().
enum nv2_pixel_type |
Different pixel types that can be stored in an nv2_image_patch.
Definition at line 51 of file nv2_common.h.
NV2_EXTERN_C void nv2_fatal_impl | ( | const char * | file, | |
int | line, | |||
const char * | function, | |||
const char * | what | |||
) |
Helper for nv2_fatal.
Definition at line 113 of file nv2_common.c.
NV2_EXTERN_C void nv2_image_patch_destroy | ( | struct nv2_image_patch * | p | ) |
Free the data array associated with p, and reinitialize to an empty state.
Definition at line 77 of file nv2_common.c.
References nv2_image_patch_init_empty().
Referenced by nv2_label_reader_destroy(), nv2_label_reader_send_patch(), nv2_label_reader_send_patch_sync(), and nv2_label_server_destroy().
NV2_EXTERN_C void nv2_image_patch_init_empty | ( | struct nv2_image_patch * | p | ) |
Initialize with the current protocol version, and zeros elsewhere.
This function does NOT free any data associated with p->data; it is up to the caller to do that (if necessary) before calling this function.
Definition at line 64 of file nv2_common.c.
References NV2_PATCH_PROTOCOL_VERSION.
Referenced by nv2_image_patch_destroy(), nv2_label_reader_create(), nv2_label_reader_send_patch(), nv2_label_reader_send_patch_sync(), nv2_label_server_create(), and nv2_label_server_get_current_patch().
NV2_EXTERN_C void nv2_image_patch_set_remote_command | ( | struct nv2_image_patch * | p, | |
const char * | command | |||
) |
Copy a remote command into the image patch.
Definition at line 94 of file nv2_common.c.
NV2_EXTERN_C void nv2_image_patch_set_training_label | ( | struct nv2_image_patch * | p, | |
const char * | label | |||
) |
Copy a training label into the image patch.
Definition at line 85 of file nv2_common.c.
NV2_EXTERN_C void nv2_patch_label_init_empty | ( | struct nv2_patch_label * | l | ) |
Initialize with the current protocol version, and zeros elsewhere.
Definition at line 103 of file nv2_common.c.
References nv2_patch_label::confidence, and NV2_LABEL_PROTOCOL_VERSION.
Referenced by nv2_label_reader_create(), and nv2_label_reader_get_current_label().
uint32_t nv2_pixel_type_bytes_per_pixel | ( | enum nv2_pixel_type | typ | ) |
Get the number of bytes used per pixel of a given type.
Definition at line 49 of file nv2_common.c.
References nv2_fatal.
Referenced by nv2_label_reader_send_patch_sync().
size_t nv2_robust_read | ( | int | fd, | |
void * | buf, | |||
size_t | nbytes, | |||
int * | nchunks | |||
) |
Keep doing read() calls until either all the bytes are read or an error occurs.
Returns the number of bytes read; if this number is less than the number of requested bytes (nbytes), then it means that some error occurred
nchunks | if not null, then the total number of read() system calls performed will be returned through this pointer |
Definition at line 170 of file nv2_common.c.
size_t nv2_robust_write | ( | int | fd, | |
const void * | data, | |||
size_t | nbytes | |||
) |
Keep doing write() calls until either all the bytes are written or an error occurs.
Returns the number of bytes written; if this number is less than the number of requested bytes (nbytes), then it means that some error occurred
Definition at line 136 of file nv2_common.c.
Referenced by nv2_label_reader_send_patch_sync(), and nv2_label_server_send_label().
NV2_EXTERN_C void nv2_warn_impl | ( | const char * | file, | |
int | line, | |||
const char * | function, | |||
const char * | what | |||
) |
Helper for nv2_warn.
Definition at line 125 of file nv2_common.c.