Example #1
0
 void canny(unsigned char *readImage, unsigned char **writeImage, float gauSigma, float edgeT, float backT, char *composedFilename) {
 	float *radiansImg;
 	short int *gsmoothImage, *deltaX, *deltaY, *magnitude;
 	unsigned char *nms;
 	// FILE *fp;

 	(*writeImage) = (unsigned char *) calloc(HEIGHT*WIDTH, sizeof (unsigned char));

 	if (VERBOSE) printf("Gaussian smoothing ...\n");
 	gaussianSmooth(readImage, &gsmoothImage, gauSigma);

 	if (VERBOSE) printf("Computing the X and Y first derivaties.\n");
 	derrXY(gsmoothImage, &deltaX, &deltaY);

 	radianDir(deltaX, deltaY, &radiansImg, -1, -1);

 	if (VERBOSE) printf("Computing the magnitude of the gradient.\n");
 	magXY(deltaX, deltaY, &magnitude);

 	if (VERBOSE) printf("Doing the non-maximal suppression.\n");
 	nms = (unsigned char *) calloc(HEIGHT*WIDTH, sizeof (unsigned char));
 	nonMaxSup(magnitude, deltaX, deltaY, nms);

 	if (VERBOSE) printf("Doing hysteresis thresholding.\n");
 	applyHysteresis(magnitude, nms, edgeT, backT, *writeImage);

 	free(gsmoothImage);
 	free(deltaX);
 	free(deltaY);
 	free(magnitude);
 	free(nms);
 }
Example #2
0
int aimAtSideMostTarget(int side){
	int most_blob, i, center, error;
	int attempts = 0;

	do{
		captureImage();
		openImage(SOURCE_FILE_NAME);
		gaussianSmooth();
		isolateRed();
		findObjects();
		if(numBlobs <= 0)
		{
			//printf("Couldn't find any targets =(\n");
			return(0);
		}

		most_blob = 0;
		if (side)
		{
			for(i = 1; i < numBlobs; i++)
			{
				if (blobs[most_blob].rightX < blobs[i].rightX && blobs[i].rightX - blobs[i].leftX > MIN_BLOB_WIDTH)
				{
					most_blob = i;
				}
			}
		}
		else
		{
			for(i = 1; i < numBlobs; i++)
			{
				if (blobs[most_blob].leftX > blobs[i].leftX && blobs[i].rightX - blobs[i].leftX > MIN_BLOB_WIDTH)
				{
					most_blob = i;
				}
			}
		}
		if(blobs[most_blob].rightX - blobs[most_blob].leftX >= MIN_BLOB_WIDTH)
		{
			//printf("Found target:\n");
			//printf("   Width: %d\n", blobs[most_blob].rightX-blobs[most_blob].leftX);
			center = (blobs[most_blob].rightX-blobs[most_blob].leftX)/2 + blobs[most_blob].leftX;
			//printf("   Center: %d\n", center);
			error = center - IMAGE_CENTER;
			if(abs(error) <= MAX_TARGET_ERROR)
			{
				break;
			}
			aimAtTarget(error);
		}
		attempts++;
	}
	while (abs(error) > MAX_TARGET_ERROR && attempts < MAX_AIM_ATTEMPTS);	

	return(1);
}