*
* Petr Kubizňák (kubiznak.petr@gmail.com), 2010
*
- * Usage: ./maskgen inputfile [-b value]
+ * Usage: ./maskgen inputfile [-b value] [-y]
* inputfile:
* Specifies filename of the masks' mask image, i.e. image with black
* background and corns in different colors (first #141414, second #282828, ...),
* that will be replaced by black or white, depending on mask being generated.
* -b:
* If specified, the output image will be smoothed using 'value' width.
+ * -y:
+ * If specified, masks are generated for the yellow start, otherwise blue.
+ * In fact, this option influences only one letter in names of output files.
*
- * Output: Files mask%d.png, where %d means index of mask.
+ * Output: Files mask%d%c%c.png, where %d means index of mask,
+ * first %c place of mask (s|c = side/central)
+ * and second %c color of starting point (y|b).
*
******************************************************************************/
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <unistd.h>
+#include "masks_globals.h"
/******************************************************************************/
// color definitions
#define CL_NEUTRAL 128 //neutral color - gray
+#define N CL_NEUTRAL
#define B 0 //black
#define W 255 //white
-#define CORNSCNT 5 //number of corns in one mask
-#define MASKSCNT 32 //number of all masks
-
/******************************************************************************/
//look-up table
CvMat *transformTable;
-//table of corns colors in each mask
-uchar cornColors[MASKSCNT][CORNSCNT] = {
- {B,B,B,B,B},
- {B,B,B,B,W},
- {B,B,B,W,B},
- {B,B,B,W,W},
- {B,B,W,B,B},
- {B,B,W,B,W},
- {B,B,W,W,B},
- {B,B,W,W,W},
- {B,W,B,B,B},
- {B,W,B,B,W},
- {B,W,B,W,B},
- {B,W,B,W,W},
- {B,W,W,B,B},
- {B,W,W,B,W},
- {B,W,W,W,B},
- {B,W,W,W,W},
- {W,B,B,B,B},
- {W,B,B,B,W},
- {W,B,B,W,B},
- {W,B,B,W,W},
- {W,B,W,B,B},
- {W,B,W,B,W},
- {W,B,W,W,B},
- {W,B,W,W,W},
- {W,W,B,B,B},
- {W,W,B,B,W},
- {W,W,B,W,B},
- {W,W,B,W,W},
- {W,W,W,B,B},
- {W,W,W,B,W},
- {W,W,W,W,B},
- {W,W,W,W,W}
+//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}
+};
+//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}
};
/******************************************************************************/
/******************************************************************************/
-/** Accordingly to selected mask some colors in lookup table are replaced to black or white. */
-void replaceTableColors(int maskIndex) {
+/** Accordingly to selected mask some colors in lookup table are replaced to black, white or neutral. */
+int replaceTableColors(const uchar cornColors[][CORNSCNT], int maskIndex) {
uchar *data = transformTable->data.ptr;
- data[20] = cornColors[maskIndex][0];
- data[40] = cornColors[maskIndex][1];
- data[60] = cornColors[maskIndex][2];
- data[80] = cornColors[maskIndex][3];
- data[100]= cornColors[maskIndex][4];
+ for(int i=0; i<CORNSCNT; i++) {
+ if(i>11) return 1;
+ data[20+20*i] = cornColors[maskIndex][i];
+ }
+ return 0;
}
/******************************************************************************/
/** Generates outputs by replacing the colors of src in a loop.
* If blur>0, the outputs are also smoothed with specified blur width. */
-int generateMasks(const IplImage *src, int blur) {
+int generateMasks(const IplImage *src, int blur, char orientation, char teamColor,
+ const uchar cornColors[][CORNSCNT], int masksCnt) {
IplImage *dest;
- char outFilename[20];
+ char outFilename[100];
- for(int i=0; i<MASKSCNT; i++) {
+ for(int i=0; i<masksCnt; i++) {
dest = cvCloneImage(src);
- replaceTableColors(i); //adapt look-up table for this mask
- sprintf(outFilename, "mask%02d.png", i); //output filename
+ replaceTableColors(cornColors, i); //adapt look-up table for this mask
+ sprintf(outFilename, "mask%02d%c%c.png", 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)
if(blur>0) {
int main(int argc, char *argv[]) {
char opt;
int blur=0; //some default value of blur
+ char color=clBLUE;
IplImage *mask = NULL;
// scan for program arguments
- while ((opt = getopt(argc, argv, "b:")) != -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
initTable(); //fill transformTable with value 128 (gray, i.e. neutral)
- generateMasks(mask, blur); //generate masks out of the masks' mask
+ 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
cvReleaseMat(&transformTable);
cvReleaseImage(&mask);