void render_segment_result (int ofstx, int ofsty, int draw_w, int draw_h, texture_2d_t *srctex, segmentation_result_t *segment_ret){ float *segmap = segment_ret->segmentmap; int segmap_w = segment_ret->segmentmap_dims[0]; int segmap_h = segment_ret->segmentmap_dims[1]; int segmap_c = segment_ret->segmentmap_dims[2]; int x, y, c; static unsigned int *imgbuf = NULL; float hair_color[4] = {0}; float back_color[4] = {0}; static float s_hsv_h = 0.0f;
if (imgbuf == NULL) { imgbuf = (unsigned int *)malloc (segmap_w * segmap_h * sizeof(unsigned int)); }
s_hsv_h += 5.0f; if (s_hsv_h >= 360.0f) s_hsv_h = 0.0f;
colormap_hsv (s_hsv_h / 360.0f, hair_color);
#if defined (RENDER_BY_BLEND) float lumi = (hair_color[0] * 0.299f + hair_color[1] * 0.587f + hair_color[2] * 0.114f); hair_color[3] = lumi;#endif
/* find the most confident class for each pixel. */ for (y = 0; y < segmap_h; y ++) { for (x = 0; x < segmap_w; x ++) { int max_id; float conf_max = 0; for (c = 0; c < MAX_SEGMENT_CLASS; c ++) { float confidence = segmap[(y * segmap_w * segmap_c)+ (x * segmap_c) + c]; if (c == 0 || confidence > conf_max) { conf_max = confidence; max_id = c; } }
float *col = (max_id > 0) ? hair_color : back_color; unsigned char r = ((int)(col[0] * 255)) & 0xff; unsigned char g = ((int)(col[1] * 255)) & 0xff; unsigned char b = ((int)(col[2] * 255)) & 0xff; unsigned char a = ((int)(col[3] * 255)) & 0xff;
imgbuf[y * segmap_w + x] = (a << 24) | (b << 16) | (g << 8) | (r); } }
GLuint texid; glGenTextures (1, &texid ); glBindTexture (GL_TEXTURE_2D, texid);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, segmap_w, segmap_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgbuf);
#if !defined (RENDER_BY_BLEND) draw_colored_hair (srctex, texid, ofstx, ofsty, draw_w, draw_h, 0, hair_color);#else draw_2d_texture_ex (srctex, ofstx, ofsty, draw_w, draw_h, 0);
unsigned int blend_add [] = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE}; draw_2d_texture_blendfunc (texid, ofstx, ofsty, draw_w, draw_h, 0, blend_add);#endif
glDeleteTextures (1, &texid);
render_hsv_circle (ofstx + draw_w - 100, ofsty + 100, s_hsv_h);}
评论