Пример #1
0
// Returns the area of black color captured of a certain image.
int NaoVision::getAreaBlackColor(Mat originalImage) {
    iLowH = 0;
    iHighH = 180;
    iLowS = 0;
    iHighS = 255;
    iLowV = 100;
    iHighV = 255;
    ColorFilter(originalImage);

    areaColorDetection = 195 - areaColorDetection;
    cout << areaColorDetection << endl;

    return areaColorDetection;
}
Пример #2
0
// Returns the area of yellow color captured of a certain image.
int NaoVision::getAreaYellowColor(Mat originalImage) {
/*Parametros de Cinta Amarilla
* LowH  = 020/179
* HighH = 071/179
* LowS  = 169/255
* HighS = 255/255
* LowV  = 141/255
* HighV = 255/255
*/
    iLowH = 20;
    iHighH = 100;
    iLowS = 80;
    iHighS = 255;
    iLowV = 141;
    iHighV = 255;

    ColorFilter(originalImage);

    return areaColorDetection;
}
Пример #3
0
// Returns the area of red color captured of a certain image.
int NaoVision::getAreaRedColor(Mat originalImage) {
/*Parametros de Cinta Rojo
* LowH  = 160/179
* HighH = 179/179
* LowS  = 100/255
* HighS = 255/255
* LowV  = 100/255
* HighV = 255/255
*/
    iLowH = 160;
    iHighH = 179;
    iLowS = 0;
    iHighS = 255;
    iLowV = 0;
    iHighV = 255;

    //calibrateColorDetection();
    ColorFilter(originalImage);

    return areaColorDetection;
}
Пример #4
0
/*
 * @brief Applies brightness, contrast and saturation to the specified image
 * while optionally computing the average color. Also handles image inversion
 * and monochrome. This is all munged into one function for performance.
 */
void R_FilterImage(r_image_t *image, GLenum format, byte *data) {
	vec_t brightness;
	uint32_t color[3];
	uint16_t mask;
	size_t i, j;

	if (image->type == IT_DIFFUSE) {// compute average color
		VectorClear(color);
	}

	if (image->type == IT_LIGHTMAP) {
		brightness = r_modulate->value;
		mask = 2;
	} else {
		brightness = r_brightness->value;
		mask = 1;
	}

	const size_t pixels = image->width * image->height;
	const size_t stride = format == GL_RGBA ? 4 : 3;

	byte *p = data;

	for (i = 0; i < pixels; i++, p += stride) {
		vec3_t temp;

		VectorScale(p, 1.0 / 255.0, temp); // convert to float

		// apply brightness, saturation and contrast
		ColorFilter(temp, temp, brightness, r_saturation->value, r_contrast->value);

		for (j = 0; j < 3; j++) {

			temp[j] = Clamp(temp[j] * 255, 0, 255); // back to byte

			p[j] = (byte) temp[j];

			if (image->type == IT_DIFFUSE) // accumulate color
				color[j] += p[j];
		}

		if (r_monochrome->integer & mask) // monochrome
			p[0] = p[1] = p[2] = (p[0] + p[1] + p[2]) / 3;

		if (r_invert->integer & mask) { // inverted
			p[0] = 255 - p[0];
			p[1] = 255 - p[1];
			p[2] = 255 - p[2];
		}
	}

	if (image->type == IT_DIFFUSE) { // average accumulated colors
		for (i = 0; i < 3; i++)
			color[i] /= (vec_t) pixels;

		if (r_monochrome->integer & mask)
			color[0] = color[1] = color[2] = (color[0] + color[1] + color[2]) / 3.0;

		if (r_invert->integer & mask) {
			color[0] = 255 - color[0];
			color[1] = 255 - color[1];
			color[2] = 255 - color[2];
		}

		for (i = 0; i < 3; i++)
			image->color[i] = color[i] / 255.0;
	}
}
Пример #5
0
/*
 * R_ResolveBspLightParameters
 *
 * Resolves ambient light, brightness, and contrast levels from Worldspawn.
 */
static void R_ResolveBspLightParameters(void) {
	const char *c;

	// resolve ambient light
	if ((c = R_WorldspawnValue("ambient_light"))) {
		sscanf(c, "%f %f %f", &r_locals.ambient_light[0],
				&r_locals.ambient_light[1], &r_locals.ambient_light[2]);

		VectorScale(r_locals.ambient_light, BSP_LIGHT_AMBIENT_SCALE, r_locals.ambient_light);

		Com_Debug("Resolved ambient_light: %1.2f %1.2f %1.2f\n",
				r_locals.ambient_light[0], r_locals.ambient_light[1],
				r_locals.ambient_light[2]);
	} else { // ensure sane default
		VectorSet(r_locals.ambient_light, 0.1, 0.1, 0.1);
	}

	// resolve sun light
	if ((c = R_WorldspawnValue("sun_light"))) {
		r_locals.sun_light = atof(c) / 255.0;

		if (r_locals.sun_light > 1.0) // should never happen
			r_locals.sun_light = 1.0;

		Com_Debug("Resolved sun_light: %1.2f\n", r_locals.sun_light);
	} else {
		r_locals.sun_light = 0.0;
	}

	// resolve sun color
	if ((c = R_WorldspawnValue("sun_color"))) {
		sscanf(c, "%f %f %f", &r_locals.sun_color[0], &r_locals.sun_color[1],
				&r_locals.sun_color[2]);

		Com_Debug("Resolved sun_color: %1.2f %1.2f %1.2f\n",
				r_locals.sun_color[0], r_locals.sun_color[1],
				r_locals.sun_color[2]);
	} else { // ensure sane default
		VectorSet(r_locals.sun_color, 1.0, 1.0, 1.0);
	}

	// resolve brightness
	if ((c = R_WorldspawnValue("brightness"))) {
		r_locals.brightness = atof(c);
	} else { // ensure sane default
		r_locals.brightness = 1.0;
	}

	// resolve saturation
	if ((c = R_WorldspawnValue("saturation"))) {
		r_locals.saturation = atof(c);
	} else { // ensure sane default
		r_locals.saturation = 1.0;
	}

	// resolve contrast
	if ((c = R_WorldspawnValue("contrast"))) {
		r_locals.contrast = atof(c);
	} else { // ensure sane default
		r_locals.contrast = 1.0;
	}

	Com_Debug("Resolved brightness: %1.2f\n", r_locals.brightness);
	Com_Debug("Resolved saturation: %1.2f\n", r_locals.saturation);
	Com_Debug("Resolved contrast: %1.2f\n", r_locals.contrast);

#if 0
	//apply brightness, saturation and contrast to the colors
	ColorFilter(r_locals.ambient_light, r_locals.ambient_light,
			r_locals.brightness, r_locals.saturation, r_locals.contrast);

	Com_Debug("Scaled ambient_light: %1.2f %1.2f %1.2f\n",
			r_locals.ambient_light[0], r_locals.ambient_light[1], r_locals.ambient_light[2]);

	ColorFilter(r_locals.sun_color, r_locals.sun_color,
			r_locals.brightness, r_locals.saturation, r_locals.contrast);

	Com_Debug("Scaled sun_color: %1.2f %1.2f %1.2f\n",
			r_locals.sun_color[0], r_locals.sun_color[1], r_locals.sun_color[2]);
#endif
}
Пример #6
0
/**
 * @brief Resolves ambient light, brightness, and contrast levels from Worldspawn.
 */
static void R_ResolveBspLightParameters(void) {
	const char *c;
	vec3_t tmp;

	// resolve ambient light
	if ((c = Cm_WorldspawnValue("ambient"))) {
		vec_t *f = r_bsp_light_state.ambient;
		sscanf(c, "%f %f %f", &f[0], &f[1], &f[2]);

		VectorScale(f, r_modulate->value, f);

		Com_Debug(DEBUG_RENDERER, "Resolved ambient: %s\n", vtos(f));
	} else {
		VectorSet(r_bsp_light_state.ambient, 0.15, 0.15, 0.15);
	}

	// resolve sun light
	if ((c = Cm_WorldspawnValue("sun_light"))) {
		r_bsp_light_state.sun.diffuse = atof(c) * BSP_LIGHT_SUN_SCALE;

		Com_Debug(DEBUG_RENDERER, "Resolved sun_light: %1.2f\n", r_bsp_light_state.sun.diffuse);
	} else {
		r_bsp_light_state.sun.diffuse = 0.0;
	}

	// resolve sun angles and direction
	if ((c = Cm_WorldspawnValue("sun_angles"))) {
		VectorClear(tmp);
		sscanf(c, "%f %f", &tmp[0], &tmp[1]);

		Com_Debug(DEBUG_RENDERER, "Resolved sun_angles: %s\n", vtos(tmp));
		AngleVectors(tmp, r_bsp_light_state.sun.dir, NULL, NULL);
	} else {
		VectorCopy(vec3_down, r_bsp_light_state.sun.dir);
	}

	// resolve sun color
	if ((c = Cm_WorldspawnValue("sun_color"))) {
		vec_t *f = r_bsp_light_state.sun.color;
		sscanf(c, "%f %f %f", &f[0], &f[1], &f[2]);

		Com_Debug(DEBUG_RENDERER, "Resolved sun_color: %s\n", vtos(f));
	} else {
		VectorSet(r_bsp_light_state.sun.color, 1.0, 1.0, 1.0);
	}

	// resolve brightness
	if ((c = Cm_WorldspawnValue("brightness"))) {
		r_bsp_light_state.brightness = atof(c);
	} else {
		r_bsp_light_state.brightness = 1.0;
	}

	// resolve saturation
	if ((c = Cm_WorldspawnValue("saturation"))) {
		r_bsp_light_state.saturation = atof(c);
	} else {
		r_bsp_light_state.saturation = 1.0;
	}

	// resolve contrast
	if ((c = Cm_WorldspawnValue("contrast"))) {
		r_bsp_light_state.contrast = atof(c);
	} else {
		r_bsp_light_state.contrast = 1.0;
	}

	Com_Debug(DEBUG_RENDERER, "Resolved brightness: %1.2f\n", r_bsp_light_state.brightness);
	Com_Debug(DEBUG_RENDERER, "Resolved saturation: %1.2f\n", r_bsp_light_state.saturation);
	Com_Debug(DEBUG_RENDERER, "Resolved contrast: %1.2f\n", r_bsp_light_state.contrast);

	const vec_t brt = r_bsp_light_state.brightness;
	const vec_t sat = r_bsp_light_state.saturation;
	const vec_t con = r_bsp_light_state.contrast;

	// apply brightness, saturation and contrast to the colors
	ColorFilter(r_bsp_light_state.ambient, r_bsp_light_state.ambient, brt, sat, con);
	Com_Debug(DEBUG_RENDERER, "Scaled ambient: %s\n", vtos(r_bsp_light_state.ambient));

	ColorFilter(r_bsp_light_state.sun.color, r_bsp_light_state.sun.color, brt, sat, con);
	Com_Debug(DEBUG_RENDERER, "Scaled sun color: %s\n", vtos(r_bsp_light_state.sun.color));
}
Пример #7
0
/**
 * @brief Parse the entity string and resolve all static light sources. Sources which
 * are very close to each other are merged. Their colors are blended according
 * to their light value (intensity).
 */
void R_LoadBspLights(r_bsp_model_t *bsp) {
	vec3_t origin, color;
	vec_t radius;

	memset(&r_bsp_light_state, 0, sizeof(r_bsp_light_state));

	const r_bsp_light_state_t *s = &r_bsp_light_state;

	R_ResolveBspLightParameters();

	// iterate the world surfaces for surface lights
	const r_bsp_surface_t *surf = bsp->surfaces;

	for (uint16_t i = 0; i < bsp->num_surfaces; i++, surf++) {

		// light-emitting surfaces are of course lights
		if ((surf->texinfo->flags & SURF_LIGHT) && surf->texinfo->value) {
			VectorMA(surf->center, 1.0, surf->normal, origin);

			radius = sqrt(surf->texinfo->light * sqrt(surf->area) * BSP_LIGHT_SURFACE_RADIUS_SCALE);

			R_AddBspLight(bsp, origin, surf->texinfo->emissive, radius * s->brightness);
		}
	}
	
	// parse the entity string for point lights
	const char *ents = Cm_EntityString();

	VectorClear(origin);

	radius = BSP_LIGHT_POINT_DEFAULT_RADIUS * s->brightness;
	VectorSet(color, 1.0, 1.0, 1.0);

	char class_name[MAX_QPATH];
	_Bool entity = false, light = false;

	while (true) {

		const char *c = ParseToken(&ents);

		if (!strlen(c)) {
			break;
		}

		if (*c == '{') {
			entity = true;
		}

		if (!entity) { // skip any whitespace between ents
			continue;
		}

		if (*c == '}') {
			entity = false;

			if (light) { // add it
				R_AddBspLight(bsp, origin, color, radius * BSP_LIGHT_POINT_RADIUS_SCALE);

				radius = BSP_LIGHT_POINT_DEFAULT_RADIUS;
				VectorSet(color, 1.0, 1.0, 1.0);

				light = false;
			}
		}

		if (!g_strcmp0(c, "classname")) {

			c = ParseToken(&ents);
			g_strlcpy(class_name, c, sizeof(class_name));

			if (!strncmp(c, "light", 5)) { // light, light_spot, etc..
				light = true;
			}

			continue;
		}

		if (!g_strcmp0(c, "origin")) {
			sscanf(ParseToken(&ents), "%f %f %f", &origin[0], &origin[1], &origin[2]);
			continue;
		}

		if (!g_strcmp0(c, "light")) {
			radius = atof(ParseToken(&ents)) * s->brightness;
			continue;
		}

		if (!g_strcmp0(c, "_color")) {
			sscanf(ParseToken(&ents), "%f %f %f", &color[0], &color[1], &color[2]);
			ColorFilter(color, color, s->brightness, s->saturation, s->contrast);
			continue;
		}
	}

	// allocate the lights array and copy them in
	bsp->num_bsp_lights = g_slist_length(r_bsp_light_state.lights);
	bsp->bsp_lights = Mem_LinkMalloc(sizeof(r_bsp_light_t) * bsp->num_bsp_lights, bsp);

	GSList *e = r_bsp_light_state.lights;
	r_bsp_light_t *bl = bsp->bsp_lights;
	while (e) {
		*bl++ = *((r_bsp_light_t *) e->data);
		e = e->next;
	}

	// reset state
	g_slist_free_full(r_bsp_light_state.lights, Mem_Free);
	r_bsp_light_state.lights = NULL;

	Com_Debug(DEBUG_RENDERER, "Loaded %d bsp lights\n", bsp->num_bsp_lights);
}