int main(int argc, char **argv) {
	InitVars(argc, argv, "../heh.cfg");

	// Read image
	ImageRGB<byte> imagergb;
	ImageF image;
	ReadImage(argv[1], imagergb);
	ImageCopy(imagergb, image);

	// Run segmentation
	MatI seg(image.GetHeight(), image.GetWidth());
	if (argc >= 3) {
		ReadMatrix(argv[2], seg);
	} else {
		FHSegmenter segmenter(image.GetWidth(), image.GetHeight());
		segmenter.Compute(image, seg, 1, 50, 150);
	}
	//DREPORT(seg);

	// Compute features
	HehFeatureGen gen;
	gen.Compute(imagergb, image, seg);

	for (int i = 0; i < gen.features.size(); i++) {
		DREPORT(i);
		SCOPED_INDENT;
		const HehFeature& f = gen.features[i];
		DLOG << f;
	}

	return 0;
}
Exemple #2
0
/*
 * \brief This function initializes the system and copies the image. 
 *
 * \param  none
 *
 * \return none 
*/
int main(void)
{
    /* Configures PLL and DDR controller*/
    BlPlatformConfig();

    UARTPuts("MAACS ", -1);
    UARTPuts(deviceType, -1);
    UARTPuts(" Boot Loader\n\r", -1);
		UARTPuts("Version 0.0.0\n\r",-1);
		UARTPuts("Revised by: Jacob Cook\n\r",-1);

    /* Copies application from non-volatile flash memory to RAM */
    ImageCopy();

    UARTPuts("Jumping to MAACS Flight Software...\r\n\n", -1);

    /* Do any post-copy config before leaving boot loader */
    BlPlatformConfigPostBoot();

    /* Giving control to the application */
    appEntry = (void (*)(void)) entryPoint;

    (*appEntry)( );

    return 0;
}
	void OutputGradientViz(const string& filename,
												 const ImageRGB<byte>& image) const {
		const int& w = image.GetWidth();
		const int& h = image.GetHeight();

		// Draw segment boundaries
		ImageRGB<byte> canvas;
		const MatI& segmap = segmentation;
		ImageCopy(image, canvas);
		for (int r = 0; r < h; r++) {
			for (int c = 0; c < w; c++) {
				if (distxform.dists[r][c] == 0) {
					canvas[r][c] = BrightColors::Get(segmap[r][c]);
				}
			}
		}

		// Draw segment orientation
		for (int i = 0; i < num_segments; i++) {
			if (seg_sizes[i] > 40) {
				const double norm = 10.0 / sqrt(seg_dx[i]*seg_dx[i] + seg_dy[i]*seg_dy[i]);
				Vector<2> a = makeVector(seg_x[i], seg_y[i]);
				Vector<2> b = makeVector(seg_x[i]+seg_dx[i]*norm, seg_y[i]+seg_dy[i]*norm);
				DrawSpot(canvas, BrightColors::Get(i), a, 1);
				DrawLineClipped(canvas, a, b, BrightColors::Get(i));
			}
		}
		WriteImage("out/segorients.png", canvas);
	}
	void OutputViz(const ImageRGB<byte>& orig,
								 const string& filename) const {
		ImageRGB<byte> canvas;
		ImageCopy(orig, canvas);
		Draw(canvas, PixelRGB<byte>(255, 0, 0));
		WriteImage(filename, canvas);
	}
void WriteHueOnly(const string& filename,
									ImageHSV<byte>& image) {
	ImageHSV<byte> clone;
	ImageCopy(image, clone);
	for (int r = 0; r < clone.GetHeight(); r++) {
		for (int c = 0; c < clone.GetWidth(); c++) {
			clone[r][c].s = 255;
		}
	}
	WriteImage(filename, clone);
}
	void Compute(const ImageRGB<byte>& imagergb,
							 const MatI& seg,
							 int num_segs) {
		const int& w = imagergb.GetWidth();
		const int& h = imagergb.GetHeight();
		segmentation = seg;
		num_segments = num_segs;
		
		// Compute gradients
		ImageCopy(imagergb, imagemono);
		gradients.Compute(imagemono);
		distxform.Compute(seg);

		// Compute average gradient in each segment
		mask.Resize(h, w);
		mask.Fill(0);
		seg_x.Resize(num_segments, 0.0);
		seg_y.Resize(num_segments, 0.0);
		seg_dx.Resize(num_segments, 0.0);
		seg_dy.Resize(num_segments, 0.0);
		seg_sizes.Resize(num_segments, 0);
		for (int r = 0; r < h; r++) {
			const int* segrow = seg[r];
			const PixelF* dxrow = gradients.diffx[r];
			const PixelF* dyrow = gradients.diffy[r];
			const int* distrow = distxform.dists[r];
			for (int c = 0; c < w; c++) {
				if (distrow[c] >= 2) {
					const int seg = segrow[c];
					seg_x[seg] += c;
					seg_y[seg] += r;
					seg_dx[seg] += dxrow[c].y;  // "y" just means the value of the pixel
					seg_dy[seg] += dyrow[c].y;
					seg_sizes[seg]++;
					mask[r][c] = 1;
				}
			}
		}

		// Compose features and normalize
		features.resize(num_segments);
		for (int i = 0; i < num_segments; i++) {
			if (seg_sizes[i] > 0) {
				seg_x[i] /= seg_sizes[i];
				seg_y[i] /= seg_sizes[i];
				seg_dx[i] /= seg_sizes[i];
				seg_dy[i] /= seg_sizes[i];
			}
			features[i] = MakeVector<2,float>(seg_dx[i], seg_dy[i]);
		}
	}
Exemple #7
0
/*-----------------------------------------------------
        Parameters:

        Returns value:

        Description
          read an image from file and convert it to the specified
          format.
------------------------------------------------------*/
IMAGE *
ImageReadType(const char*fname, int pixel_format)
{
  IMAGE *Itmp, *I ;

  Itmp = ImageRead(fname) ;
  if (!Itmp)
    ErrorReturn(NULL, (ERROR_NO_FILE,
                       "ImageReadType(%s, %d): could not read image",
                       fname, pixel_format)) ;
  if (Itmp->pixel_format != pixel_format)
  {
    I = ImageAlloc(Itmp->rows, Itmp->cols, pixel_format, Itmp->num_frame) ;
    ImageCopy(Itmp, I) ;
    ImageFree(&Itmp) ;
  }
  else
    I = Itmp ;

  return(I) ;
}
	void Compute(ImageF& image) {
		const int nx = image.GetWidth();
		const int ny = image.GetHeight();
		const int len = *gvRoiSize;

		// Compute gradients
		gradients.Compute(image);
		MatF& magsqr = gradients.magnitude_sqr;
		magsqr /= magsqr.MaxValue();

		// Create the histogram
		votes.Resize(ny, nx, *gvThetaBins);


		// Compute the (theta,rho,phi) histogram
		for (int y = roi.Top(); y < roi.Bottom(); y++) {
			const float* orientrow = orient[y];
			const float* magrow = magsqr[y];
			for (int x = roi.Left(); x < roi.Right(); x++) {
				if (mask[y-roi.Top()][x-roi.Left()]) {
					const float theta = OpenUpAngle(orientrow[x]);
					const float rho = (x-cx) * cos(theta)	+ (y-cy) * sin(theta);
					const int theta_bin = ThetaToBin(theta);
					const int rho_bin = RhoToBin(rho);
					const float mag = sqrtf(magrow[x]);
					hist[theta_bin][rho_bin] += mag;
				}
			}
		}

		// Find edgels
		int nn = 0;
		for (int y = 0; y < hist.Rows(); y++) {
			for (int x = 0; x < hist.Cols(); x++) {
				if (hist[y][x] >= *gvThresh) {
					const float theta = BinToTheta(y);
					const float rho = BinToRho(x);
					const float costh = cos(theta);
					const float sinth = sin(theta);
					const Vec3F line(costh, sinth, -cx*costh - cy*sinth - rho);
					Edgel cur(theta, rho, hist[y][x], line);
					ClipLineToROI(cur.line, roi, cur.start, cur.end);
					edgels.push_back(cur);
				}
			}
		}

int main(int argc, char **argv) {
	InitVars(argc, argv, "edgels.cfg");

	ImageF image;
	ImageRGB<byte> imagergb;
	ReadImage(argv[1], imagergb);
	ImageCopy(imagergb, image);
	ResetAlpha(imagergb);
	const int nx = image.GetWidth();
	const int ny = image.GetHeight();

	Edgels edgels(image);
	DREPORT(edgels.edgels.size());

	ImageRGB<byte> canvas;
	ImageCopy(imagergb, canvas);
	BrightColors colors;
	BOOST_FOREACH(const Edgel& e, edgels.edgels) {
		e.Draw(canvas, colors.Next());
	}
	WriteImage("out/all_edgels.png", canvas);

	return 0;
}
Exemple #9
0
// Load a BMFont file (AngelCode font file)
static SpriteFont LoadBMFont(const char *fileName)
{
    #define MAX_BUFFER_SIZE     256

    SpriteFont font = { 0 };
    font.texture.id = 0;

    char buffer[MAX_BUFFER_SIZE];
    char *searchPoint = NULL;

    int fontSize = 0;
    int texWidth, texHeight;
    char texFileName[128];
    int numChars = 0;

    int base;   // Useless data

    FILE *fntFile;

    fntFile = fopen(fileName, "rt");

    if (fntFile == NULL)
    {
        TraceLog(WARNING, "[%s] FNT file could not be opened", fileName);
        return font;
    }

    // NOTE: We skip first line, it contains no useful information
    fgets(buffer, MAX_BUFFER_SIZE, fntFile);
    //searchPoint = strstr(buffer, "size");
    //sscanf(searchPoint, "size=%i", &fontSize);

    fgets(buffer, MAX_BUFFER_SIZE, fntFile);
    searchPoint = strstr(buffer, "lineHeight");
    sscanf(searchPoint, "lineHeight=%i base=%i scaleW=%i scaleH=%i", &fontSize, &base, &texWidth, &texHeight);

    TraceLog(DEBUG, "[%s] Font size: %i", fileName, fontSize);
    TraceLog(DEBUG, "[%s] Font texture scale: %ix%i", fileName, texWidth, texHeight);

    fgets(buffer, MAX_BUFFER_SIZE, fntFile);
    searchPoint = strstr(buffer, "file");
    sscanf(searchPoint, "file=\"%128[^\"]\"", texFileName);

    TraceLog(DEBUG, "[%s] Font texture filename: %s", fileName, texFileName);

    fgets(buffer, MAX_BUFFER_SIZE, fntFile);
    searchPoint = strstr(buffer, "count");
    sscanf(searchPoint, "count=%i", &numChars);

    TraceLog(DEBUG, "[%s] Font num chars: %i", fileName, numChars);

    // Compose correct path using route of .fnt file (fileName) and texFileName
    char *texPath = NULL;
    char *lastSlash = NULL;

    lastSlash = strrchr(fileName, '/');

    // NOTE: We need some extra space to avoid memory corruption on next allocations!
    texPath = malloc(strlen(fileName) - strlen(lastSlash) + strlen(texFileName) + 4);

    // NOTE: strcat() and strncat() required a '\0' terminated string to work!
    *texPath = '\0';
    strncat(texPath, fileName, strlen(fileName) - strlen(lastSlash) + 1);
    strncat(texPath, texFileName, strlen(texFileName));

    TraceLog(DEBUG, "[%s] Font texture loading path: %s", fileName, texPath);
    
    Image imFont = LoadImage(texPath);
    
    if (imFont.format == UNCOMPRESSED_GRAYSCALE) 
    {
        Image imCopy = ImageCopy(imFont);
        
        for (int i = 0; i < imCopy.width*imCopy.height; i++) ((unsigned char *)imCopy.data)[i] = 0xff;  // WHITE pixel

        ImageAlphaMask(&imCopy, imFont);
        font.texture = LoadTextureFromImage(imCopy);
        UnloadImage(imCopy);
    }
    else font.texture = LoadTextureFromImage(imFont);
    
    font.size = fontSize;
    font.numChars = numChars;
    font.charValues = (int *)malloc(numChars*sizeof(int));
    font.charRecs = (Rectangle *)malloc(numChars*sizeof(Rectangle));
    font.charOffsets = (Vector2 *)malloc(numChars*sizeof(Vector2));
    font.charAdvanceX = (int *)malloc(numChars*sizeof(int));

    UnloadImage(imFont);
    
    free(texPath);

    int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX;

    for (int i = 0; i < numChars; i++)
    {
        fgets(buffer, MAX_BUFFER_SIZE, fntFile);
        sscanf(buffer, "char id=%i x=%i y=%i width=%i height=%i xoffset=%i yoffset=%i xadvance=%i",
                       &charId, &charX, &charY, &charWidth, &charHeight, &charOffsetX, &charOffsetY, &charAdvanceX);

        // Save data properly in sprite font
        font.charValues[i] = charId;
        font.charRecs[i] = (Rectangle){ charX, charY, charWidth, charHeight };
        font.charOffsets[i] = (Vector2){ (float)charOffsetX, (float)charOffsetY };
        font.charAdvanceX[i] = charAdvanceX;
    }

    fclose(fntFile);

    if (font.texture.id == 0)
    {
        UnloadSpriteFont(font);
        font = GetDefaultFont();
    }
    else TraceLog(INFO, "[%s] SpriteFont loaded successfully", fileName);

    return font;
}