/******************************************************************************/
-#define TABLE_LEN 256
+#define TABLE_LEN 256
/******************************************************************************/
/******************************************************************************/
/** Initializes the transform table.
- * It can then be used to transform from {0..255} to <-1,1>.
- * @param threshold Value which will transform to zero.
- * @param k Saturation - if k>1.0, differences between positive and negative values grow.
- * @return 0 when table already initialized, 1 if ok */
+ * It can then be used to transform from {0..255} to <-1,1>.
+ * @param threshold Value which will transform to zero.
+ * @param k Saturation - if k>1.0, differences between positive and negative values grow.
+ * @return 0 when table already initialized, 1 if ok */
int initTable(unsigned char threshold, float k) {
- float divisor;
+ float divisor;
if((threshold == currentThr) && (k == currentK)) return 0;
divisor = (float)(threshold > 255-threshold ? threshold : 255-threshold)/k;
if(!src) return 0;
if(initTable(threshold, k) < 0) return 0;
- if(thresholded) cvThreshold(src, thresholded, threshold, 255, CV_THRESH_BINARY); // threshold (if wanted)
+ if(thresholded) cvThreshold(src, thresholded, threshold, 255, CV_THRESH_BINARY); // threshold (if wanted)
//if destination matrix is not alloced or of needed properties, create new
if(!(*dest)) *dest = cvCreateMat(src->height,src->width,CV_32FC1);
if(src->nChannels > 1) {
IplImage *gray = cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,1); // create new 1-channel 1-byte image
- cvCvtColor(src, gray, CV_BGR2GRAY); // convert to grayscale
+ cvCvtColor(src, gray, CV_BGR2GRAY); // convert to grayscale
res = gray2float(gray, dest, threshold, k, thresholded);
cvReleaseImage(&gray);
} else res = gray2float(src, dest, threshold, k, thresholded);
/******************************************************************************/
/** Transforms a colorful image to its float representation.
- * @param src Image in BGR format.
- * @param dest Pointer to a destination matrix.
- * @param threshold Level of gray which will transform to zero.
- * @param k Saturation - if k>1.0, differences between positive and negative values grow.
- * @param thresholded If not NULL, BW thresholded version of src is stored here.
- * @return Length of the destination data, or 0 if an error occurs. */
+ * @param src Image in BGR format.
+ * @param dest Pointer to a destination matrix.
+ * @param threshold Level of gray which will transform to zero.
+ * @param k Saturation - if k>1.0, differences between positive and negative values grow.
+ * @param thresholded If not NULL, BW thresholded version of src is stored here.
+ * @return Length of the destination data, or 0 if an error occurs. */
int clr2float(const IplImage *src, CvMat **dest, unsigned char threshold, float k=1.0, IplImage *thresholded=NULL);
/******************************************************************************/
/******************************************************************************/
-#define TABLE_LEN 256
+#define TABLE_LEN 256
// color definitions
-#define N CL_NEUTRAL
-#define B 0 //black
-#define W 255 //white
+#define N CL_NEUTRAL
+#define B 0 //black
+#define W 255 //white
/******************************************************************************/
CvMat *transformTable;
//table of corns' colors in side masks
const uchar sideCornColors[SIDEMASKSCNT][CORNSCNT] = {
- {W,W,B,W,B,N,W,N,N,N},
- {B,W,W,W,B,N,W,N,N,N},
- {W,W,W,W,B,N,B,N,N,N},
- {W,B,W,W,W,N,B,N,N,N},
- {B,B,W,W,W,N,W,N,N,N},
- {W,B,B,W,W,N,W,N,N,N},
- {W,W,B,B,W,N,W,N,N,N},
- {B,W,W,B,W,N,W,N,N,N},
- {W,W,W,B,W,N,B,N,N,N}
+ {W,W,B,W,B,N,W,N,N,N},
+ {B,W,W,W,B,N,W,N,N,N},
+ {W,W,W,W,B,N,B,N,N,N},
+ {W,B,W,W,W,N,B,N,N,N},
+ {B,B,W,W,W,N,W,N,N,N},
+ {W,B,B,W,W,N,W,N,N,N},
+ {W,W,B,B,W,N,W,N,N,N},
+ {B,W,W,B,W,N,W,N,N,N},
+ {W,W,W,B,W,N,B,N,N,N}
};
//table of corns' colors in central masks
const uchar centerCornColors[CENTERMASKSCNT][CORNSCNT] = {
- {N,N,N,N,N,B,N,W,B,W},
- {N,N,N,N,N,B,N,B,W,W},
- {N,N,N,N,N,W,N,W,B,B},
- {N,N,N,N,N,W,N,B,W,B}
+ {N,N,N,N,N,B,N,W,B,W},
+ {N,N,N,N,N,B,N,B,W,W},
+ {N,N,N,N,N,W,N,W,B,B},
+ {N,N,N,N,N,W,N,B,W,B}
};
/******************************************************************************/
for(int i=0; i<masksCnt; i++) {
dest = cvCloneImage(src);
- replaceTableColors(cornColors, i); //adapt look-up table for this mask
+ replaceTableColors(cornColors, i); //adapt look-up table for this mask
sprintf(outFilename, "mask%02d%c%c.pnm", i, orientation, teamColor); //output filename (P=s/c (side/center), C=b/y (blue/yellow))
- cvLUT(src, dest, transformTable); //replace colors (apply look-up table)
+ cvLUT(src, dest, transformTable); //replace colors (apply look-up table)
if(blur>0) {
- if(!(blur%2)) blur++; //blur width must be an odd number
- cvSmooth(dest, dest, CV_GAUSSIAN, blur); //smooth edges
+ if(!(blur%2)) blur++; //blur width must be an odd number
+ cvSmooth(dest, dest, CV_GAUSSIAN, blur); //smooth edges
}
- if(!cvSaveImage(outFilename,dest)) //save output image
+ if(!cvSaveImage(outFilename,dest)) //save output image
fprintf(stderr, "Could not save: %s\n", outFilename);
else fprintf(stderr, "File %s saved successfully.\n", outFilename);
int main(int argc, char *argv[]) {
char opt;
- int blur=0; //some default value of blur
+ int blur=0; //some default value of blur
char color=clBLUE;
IplImage *mask = NULL;
// scan for program arguments
- while ((opt = getopt(argc, argv, "yb:")) != -1) {
- switch (opt) {
- case 'b':
- if(optarg) blur = atoi(optarg); //threshold
- break;
- case 'y':
- color=clYELLOW;
- break;
- }
- }
- // there must be exactly one argument (besides optional -b) - mask filename
- if(argc-optind != 1) {
- fprintf(stderr, "Invalid program arguments.\n\
- Call %s mask_filename to generate masks out of masks' mask file.\n\
- Use optional argument [-b value] to specify the output images blur.\n", argv[0]);
- return 1;
- }
+ while ((opt = getopt(argc, argv, "yb:")) != -1) {
+ switch (opt) {
+ case 'b':
+ if(optarg) blur = atoi(optarg); //threshold
+ break;
+ case 'y':
+ color=clYELLOW;
+ break;
+ }
+ }
+ // there must be exactly one argument (besides optional -b) - mask filename
+ if(argc-optind != 1) {
+ fprintf(stderr, "Invalid program arguments.\n\
+ Call %s mask_filename to generate masks out of masks' mask file.\n\
+ Use optional argument [-b value] to specify the output images blur.\n", argv[0]);
+ return 1;
+ }
mask = cvLoadImage(argv[optind], CV_LOAD_IMAGE_GRAYSCALE); //load mask image (as grayscale)
if(!mask) {
fprintf(stderr, "Invalid mask image. File %s cannot be loaded.\n", argv[optind]);
return 2;
}
- initTable(); //fill transformTable with value 128 (gray, i.e. neutral)
+ initTable(); //fill transformTable with value 128 (gray, i.e. neutral)
generateMasks(mask, blur, orSIDE, color, sideCornColors, SIDEMASKSCNT); //generate side masks from the masks' mask
- generateMasks(mask, blur, orCENTER, color, centerCornColors, CENTERMASKSCNT); //generate center masks from the masks' mask
+ generateMasks(mask, blur, orCENTER, color, centerCornColors, CENTERMASKSCNT); //generate center masks from the masks' mask
cvReleaseMat(&transformTable);
cvReleaseImage(&mask);