Esempio n. 1
0
 void
 configure(const tendrils& params, const tendrils& inputs, const tendrils& outputs)
 {
   colors_.clear();
   // Get a bunch of colors in HSV
   size_t n_colors = 30;
   cv::Mat_<cv::Vec3b> hsv(n_colors, 1), rgb;
   for (size_t i = 0; i < n_colors; ++i)
     hsv(i) = cv::Vec3b((i * 180) / n_colors, 255, 255);
   cv::cvtColor(hsv, rgb, CV_HSV2RGB);
   for (size_t i = 0; i < n_colors; ++i)
     colors_.push_back(cv::Scalar(rgb(i)[0], rgb(i)[1], rgb(i)[2]));
 }
Esempio n. 2
0
void RenderBuffer::DrawFadingCircle(int x0, int y0, int radius, const xlColor& rgb, bool wrap)
{
    HSVValue hsv(rgb);
    xlColor color(rgb);
    int r = radius;
    if (allowAlpha) {
        while(r >= 0)
        {
            color.alpha = (double)rgb.alpha * (1.0 - (double)(r) / (double)radius);
            DrawCircle(x0, y0, r, color, wrap);
            r--;
        }
    } else {
        double full_brightness = hsv.value;
        while(r >= 0)
        {
            hsv.value = full_brightness * (1.0 - (double)(r) / (double)radius);
            if( hsv.value > 0.0 )
            {
                color = hsv;
                DrawCircle(x0, y0, r, color, wrap);
            }
            r--;
        }
    }
}
Esempio n. 3
0
 HSVConeColor::HSVConeColor(const Color& c)
 {
   const RGBColor* rgbc = NULL;
   const HSVColor* hsvc = NULL;
   const HSVConeColor* hsvcc = NULL;
   if ( (rgbc = dynamic_cast<const RGBColor*>(&c)) != NULL)
   {
     HSVColor hsv(c);
     HSVConeColor hsvCone(hsv);
     c_ = hsvCone.c_;
     valueWeight_ = hsvCone.valueWeight_;
   }
   else if ( (hsvc = dynamic_cast<const HSVColor*>(&c)) != NULL)
   {
     Vector3 ec;
     ec.X() = std::cos(hsvc->H()) * hsvc->S() * hsvc->V();
     ec.Y() = std::sin(hsvc->H()) * hsvc->S() * hsvc->V();
     NUKLEI_RANGE_CHECK(HSV_METRIC_VALUE_WEIGHT, 0, 1);
     ec.Z() = hsvc->V()*HSV_METRIC_VALUE_WEIGHT;
     c_ = ec;
     valueWeight_ = HSV_METRIC_VALUE_WEIGHT;
   }
   else if ( (hsvcc = dynamic_cast<const HSVConeColor*>(&c)) != NULL)
   {
     c_ = hsvcc->c_;
     valueWeight_ = hsvcc->valueWeight_;
   }
   else NUKLEI_THROW("Unknown color type");
   assertConsistency();
 }
Esempio n. 4
0
void Quiddiards::perlin(QImage& image, QColor rgb, float factor){
	QColor hsv(rgb.toHsv());
	qreal value = hsv.valueF();
	const int rows = 64, cols = 64, octave = 7;
	float wNoise[rows][cols], pNoise[rows*octave][cols*octave];
	for (int i = 0; i < rows; i++){
		for (int j = 0; j < cols; j++){
			wNoise[i][j] = randf(factor, 1);
		}
	}
	image = QImage(rows*octave, cols*octave, QImage::Format_RGB32);
	image.fill(hsv);

	float tTable[octave];
	for (int i = 0; i < octave; i++){
		float t = i / float(octave);
		tTable[i] = t*t*t*(t*(6 * t - 15) + 10);
	}
	for (int i = 0; i < rows*octave; i++){
		int y0 = i / octave, y1 = (y0 + 1) % rows;
		for (int j = 0; j < cols*octave; j++){
			int x0 = j / octave, x1 = (x0 + 1) % cols;
			hsv.setHsvF(hsv.hueF(), hsv.saturationF(), value*quadricInter(wNoise[x0][y0], wNoise[x1][y0], wNoise[x0][y1], wNoise[x1][y1], tTable[j%octave], tTable[i%octave]));
			QRgb rgb = hsv.rgb();
			image.setPixel(j, i, hsv.rgb());
		}
	}
}
Esempio n. 5
0
TOOLS(Tuple3)<uchar_t> Color3::toHSV8() const {
    TOOLS(Tuple3)<uchar_t> hsv(0,0,0);
    Color3::const_iterator itmax = getMax();
    uchar_t rgb_max = *itmax;
    uchar_t rgb_min = *getMin();
    float rgb_extend = rgb_max - rgb_min;

    hsv[2] = rgb_max;
    if (hsv[2] == 0) return hsv;

    hsv[1] = uchar_t(255 * rgb_extend /rgb_max);
    if (hsv[1] == 0 ) return hsv;

    switch (std::distance(begin(), itmax)){
    case 0: // RED
        hsv[0] = 0 + 43 * (__GREEN - __BLUE) / rgb_extend;
        break;
    case 1: //GREEN
        hsv[0] = 85 + 43 * (__BLUE - __RED) / rgb_extend;
        break;
    default: // BLUE
        hsv[0] = 171 + 43 * (__RED - __GREEN) / rgb_extend;
    }
    
    return hsv;
}
Esempio n. 6
0
static void draw_bpm(SDL_Surface *surface, const struct rect *rect, double bpm,
                     SDL_Color bg_col)
{
    static const double min = 60.0, max = 240.0;
    char buf[32];
    double f, h;

    sprintf(buf, "%5.1f", bpm);

    /* Safety catch against bad BPM values, NaN, infinity etc. */

    if (bpm < min || bpm > max) {
        draw_token(surface, rect, buf, detail_col, bg_col, bg_col);
        return;
    }

    /* Colour compatible BPMs the same; cycle 360 degrees
     * every time the BPM doubles */

    f = log2(bpm);
    f -= floor(f);
    h = f * 360.0; /* degrees */

    draw_token(surface, rect, buf, text_col, hsv(h, 1.0, 0.3), bg_col);
}
Esempio n. 7
0
/*===========================================================================*/
kvs::RGBColor WidgetBase::get_darkened_color( const kvs::RGBColor& color, const float darkness )
{
    kvs::HSVColor hsv( color );
    hsv.set( hsv.h(), hsv.s(), hsv.v() * darkness );

    return kvs::RGBColor( hsv );
}
Esempio n. 8
0
 Color Color::HSVToRGB(float H, float S, float V, bool hdr)
 {
     assert(hdr == false);
     glm::vec3 hsv(H, S, V);
     glm::vec3 rgb = glm::rgbColor(hsv);
     return Color(rgb.r, rgb.g, rgb.b, 1.0f);
 }
  rgb
  operator()()
  {
      // use golden ratio
      rand += golden_ratio_conjugate;
      rand = std::fmod(rand,1);
      return (hsv2rgb(hsv(rand*360.0, 0.5, 0.95)));
 }
Esempio n. 10
0
File: color.c Progetto: mk12/chaos
void rainbow(unsigned char *out, double v) {
	if (v <= 0 || !isfinite(v)) {
		out[0] = 0;
		out[1] = 0;
		out[2] = 0;
	} else {
		hsv(out, v, RAINBOW_SAT, RAINBOW_VAL);
	}
}
Esempio n. 11
0
static inline RgbColor rgb_mandelbrot(const int its, const int max_iterations, const cmplx lastvector)
{
	if (its == 0 || its == max_iterations) return RgbColor(0, 0, 0);

	const double smoothed = its - log(   log(squ_abs(lastvector))/2.0 / log(max_iterations)   ) / log(2);
	const unsigned brightness = std::min(std::pow(std::max(smoothed-6, 0.0), 2), 255.0);
	HsvColor hsv(static_cast<unsigned>(its) % 256, 255, brightness);
	return RgbColor(hsv);
}
Esempio n. 12
0
QColor QColor::dark( int factor ) const
{
    if ( factor <= 0 )				// invalid darkness factor
	return *this;
    else if ( factor < 100 )			// makes color lighter
	return light( 10000/factor );
    int h, s, v;
    hsv( &h, &s, &v );
    v = (v*100)/factor;
    QColor c;
    c.setHsv( h, s, v );
    return c;
}
Esempio n. 13
0
void HudIconTextureSource::ColorForIcon(GdkPixbuf* pixbuf)
{
  if (GDK_IS_PIXBUF(pixbuf))
  {
    unsigned int width = gdk_pixbuf_get_width(pixbuf);
    unsigned int height = gdk_pixbuf_get_height(pixbuf);
    unsigned int row_bytes = gdk_pixbuf_get_rowstride(pixbuf);
    
    long int rtotal = 0, gtotal = 0, btotal = 0;
    float total = 0.0f;
    
    guchar* img = gdk_pixbuf_get_pixels(pixbuf);
    
    for (unsigned int i = 0; i < width; i++)
    {
      for (unsigned int j = 0; j < height; j++)
      {
        guchar* pixels = img + (j * row_bytes + i * 4);
        guchar r = *(pixels + 0);
        guchar g = *(pixels + 1);
        guchar b = *(pixels + 2);
        guchar a = *(pixels + 3);
        
        float saturation = (MAX(r, MAX(g, b)) - MIN(r, MIN(g, b))) / 255.0f;
        float relevance = .1 + .9 * (a / 255.0f) * saturation;
        
        rtotal += (guchar)(r * relevance);
        gtotal += (guchar)(g * relevance);
        btotal += (guchar)(b * relevance);
        
        total += relevance * 255;
      }
    }
    
    nux::color::RedGreenBlue rgb(rtotal / total,
                                 gtotal / total,
                                 btotal / total);
    nux::color::HueSaturationValue hsv(rgb);
    
    if (hsv.saturation > 0.15f)
      hsv.saturation = 0.65f;
    
    hsv.value = 0.90f;
    bg_color = nux::Color(nux::color::RedGreenBlue(hsv));
  }
  else
  {
    LOG_ERROR(logger) << "Pixbuf (" << pixbuf << ") passed is non valid";
    bg_color = nux::Color(255,255,255,255);
  }
}
 SRGBA CRGBACompositeChannels::get(double x, double y, double z, double w)
 {
     float r=(float)m_c1.get(x,y,z,w);
     float g=(float)m_c2.get(x,y,z,w);
     float b=(float)m_c3.get(x,y,z,w);
     float a=(float)m_c4.get(x,y,z,w);
     if(m_mode==RGB) return SRGBA(r,g,b,a);
     else
     {
         SRGBA hsv(r,g,b,a);
         SRGBA rgb;
         HSVtoRGBA(hsv,rgb);
         return rgb;
     }
 }
Esempio n. 15
0
// Display the count images in bgr and compute their HSV histograms.
// Then compare each histogram to the first one and report results.
//
static void showHistogramComparisons(int count,
                                     const char *name[],
                                     const cv::Mat bgr[])
{
    std::vector<cv::Mat> hsv(count);
    std::vector<cv::Mat> histogram(count);
    for (int i = 0; i < count; ++i) {
        makeWindow(name[i], bgr[i]);
        cv::cvtColor(bgr[i], hsv[i], cv::COLOR_BGR2HSV);
    }
    for (int i = 0; i < histogram.size(); ++i) {
        histogram[i] = calculateHistogram(hsv[i]);
    }
    compareHistograms(histogram, name);
    std::cout << "Press a key to quit." << std::endl;
    cv::waitKey(0);
}
Esempio n. 16
0
GModelSphere::GModelSphere(const int rows, const int cols, const float rad)
{
	VertexAttribute.clear();
	Index.clear();

	for (int i = 0; i < rows + 1; i++){
		float r = (float)M_PI / (float)rows * i;
		float ry = cos(r);
		float rr = sin(r);

		for (int j = 0; j < cols + 1; j++){
			float tr = (float)M_PI * 2 / (float)cols * j;
			float tx = rr * rad * cos(tr);
			float ty = ry * rad;
			float tz = rr * rad * sin(tr);
			float rx = rr * cos(tr);
			float rz = rr * sin(tr);

			GVertexAttribute vertexAttr;
			vertexAttr.position = vec3(tx, ty, tz);
			vertexAttr.normal = vec3(rx, ry, rz);
//			vertexAttr.color = vec4(1.0, 0.0, 1.0, 1.0);
			vec3 hsv(360.0f / (float)rows * i, 1.0, 1.0);
			vertexAttr.color = vec4(hsv2rgb(hsv), 1.0);

			VertexAttribute.push_back(vertexAttr);
		}

		for (int i = 0; i < rows; i++){
			for (int j = 0; j < cols; j++){
				int r = (cols + 1) * i + j;
				Index.push_back(u16vec3(r, r + 1, r + cols + 2));
				Index.push_back(u16vec3(r, r + cols + 2, r + cols + 1));
			}
		}

	}

	CreateVBO();
	CreateIBO();
	BindVBO();
	BindIBO();


}
Esempio n. 17
0
int main() {
    double a,b,c,d;
    char s[99];
    for(; ~(scanf("%s",s));) {
        if(*s=='(') {
            sscanf(s,"(%lf,%lf,%lf,%lf)",&a,&b,&c,&d);
            cmyk(a,b,c,d);
        } else if(s[2]=='L') {
            sscanf(s,"HSL(%lf,%lf,%lf)",&a,&b,&c);
            hsl(a,b/100,c/100);
        } else if(s[2]=='V') {
            sscanf(s,"HSV(%lf,%lf,%lf)",&a,&b,&c);
            hsv(a,b/100,c/100);
        } else {
            hex(s);
        }
    }
    return 0;
}
Esempio n. 18
0
QColor QColor::light( int factor ) const
{
    if ( factor <= 0 )				// invalid lightness factor
	return *this;
    else if ( factor < 100 )			// makes color darker
	return dark( 10000/factor );

    int h, s, v;
    hsv( &h, &s, &v );
    v = (factor*v)/100;
    if ( v > 255 ) {				// overflow
	s -= v-255;				// adjust saturation
	if ( s < 0 )
	    s = 0;
	v = 255;
    }
    QColor c;
    c.setHsv( h, s, v );
    return c;
}
Esempio n. 19
0
void doHistogram(int,void*) {
    done_hist = true;
    cv::Mat hsv(cam->frame.size(), CV_8UC3);
    cv::cvtColor(cam->frame, hsv, CV_RGB2HSV_FULL);
    int hbins = 256, sbins = 256;
    int histSize[] = {hbins,sbins};

    cv::Mat_<unsigned char> mask(cam->frame.size());

    for(int j = 0; j < mask.rows; ++j) {
        for(int i = 0; i < mask.cols; ++i) {
            float x = i - mask.cols/2;
            float y = mask.rows/2 - j;
            float d = sqrt(x*x + y*y);
            if(d > 25.0f) {
                mask(j,i) = 0;
            } else {
                mask(j,i) = 255;
            }
        }
    }

    calcHist(&hsv, 1, channels, mask, hist, 2, histSize, ranges, true, false);

    for(int j = 0; j < mask.rows; ++j) {
        for(int i = 0; i < mask.cols; ++i) {
            float x = i - mask.cols/2;
            float y = mask.rows/2 - j;
            float d = sqrt(x*x + y*y);
            if(d <= 30.0f) {
                mask(j,i) = 0;
            } else {
                mask(j,i) = 255;
            }
        }
    }

    calcHist(&hsv, 1, channels, mask, back_hist, 2, histSize, ranges, true, false);
}
Esempio n. 20
0
  sf::Color getThermalPixelColor(double temp)
  {
    // TTT = fmod(TTT+0.1, 80.0);
    // temp = TTT;

    double scalar = (
        (clamp(temp, thermalSpectrumTempMin, thermalSpectrumTempMax)-thermalSpectrumTempMin)
      * (1.0/(double)(thermalSpectrumTempMax-thermalSpectrumTempMin))
    );
    scalar = weibull(scalar, 0.3, 2.6);
    //std::cout << temp << " = " << scalar << std::endl;
    double hue = thermalSpectrumHueStart+scalar*(thermalSpectrumHueEnd-thermalSpectrumHueStart);
    double sat = 1.0;
    double val = 1.0;
    if(temp < thermalSpectrumTempMin) {
      val = (
          clamp(temp, thermalSpectrumTempAbsMin, thermalSpectrumTempMin)
        * (1.0/(double)(thermalSpectrumTempMin-thermalSpectrumTempAbsMin))
      );
    }
    return hsv(hue, sat, val);
  }
Esempio n. 21
0
	HSV RGBtoHSV( const RGB& rgb )
	{
		const float min = std::min<float>(std::min<float>(rgb.r,rgb.g),rgb.b);
		const float max = std::max<float>(std::max<float>(rgb.r,rgb.g),rgb.b);

		HSV hsv(0.0f,0.0f,max);	

		const float delta = max - min;

		if(delta!=0.0f)
		{
			hsv.s = delta / max;

			if(rgb.r==max)
			{
				hsv.h = (rgb.g-rgb.b) / delta;
			}
			else if(rgb.g==max)
			{
				hsv.h = 2.0f + (rgb.b-rgb.r) / delta;
			}
			else
			{
				hsv.h = 4.0f + (rgb.r-rgb.g) / delta;
			}
		
			hsv.h /= 6.0f;

			if(hsv.h<0.0f)
			{
				hsv.h += 1.0f;
			}
		}

		return hsv;
	}
 std::tuple<double, double, double> rgb() { return hsv_to_rgb(hsv()); }
Esempio n. 23
0
ossimRefPtr<ossimImageData> ossimRgbToHsvSource::getTile(
   const  ossimIrect& tileRect,
   ossim_uint32 resLevel)
{
   if(!theInputConnection)
   {
      return ossimRefPtr<ossimImageData>();  // This filter requires an input.
   }

   ossimRefPtr<ossimImageData> inputTile =
      theInputConnection->getTile(tileRect, resLevel);   
   if(!isSourceEnabled() || !inputTile.valid())
   {
      return inputTile;
   }

   if(!theTile.valid())
   {
      allocate(); // First time through...
   }
   
   if (!theTile.valid()) // throw exeption...
   {
      return inputTile;
   }
   
   if( inputTile->getDataObjectStatus() == OSSIM_NULL ||
       inputTile->getDataObjectStatus() == OSSIM_EMPTY )
   {
      theBlankTile->setImageRectangle(tileRect);
      return theBlankTile;
   }

   if((inputTile->getNumberOfBands()==3)&&
      (inputTile->getScalarType()==OSSIM_UCHAR)&&
      (inputTile->getDataObjectStatus()!=OSSIM_NULL))
   {
      // Set the origin, resize if needed of the output tile.
      theTile->setImageRectangle(tileRect);

      float* outputBands[3];
      ossim_uint8* inputBands[3];
      outputBands[0] = static_cast<float*>(theTile->getBuf(0));
      outputBands[1] = static_cast<float*>(theTile->getBuf(1));
      outputBands[2] = static_cast<float*>(theTile->getBuf(2));
      inputBands[0] = static_cast<ossim_uint8*>(inputTile->getBuf(0));
      inputBands[1] = static_cast<ossim_uint8*>(inputTile->getBuf(1));
      inputBands[2] = static_cast<ossim_uint8*>(inputTile->getBuf(2));
      
      long height = inputTile->getHeight();
      long width  = inputTile->getWidth();
      long offset = 0;
      for(long row = 0; row < height; ++row)
      {
         for(long col = 0; col < width; ++col)
         {
            ossimRgbVector rgb(inputBands[0][offset],
                               inputBands[1][offset],
                               inputBands[2][offset]);
            
            ossimHsvVector hsv(rgb);
            
            outputBands[0][offset] = hsv.getH();
            outputBands[1][offset] = hsv.getS();
            outputBands[2][offset] = hsv.getV();
            
            ++offset;
         }
      }
   }
   else // Input tile not of correct type to process...
   {
      return inputTile;
   }
   theTile->validate();
   return theTile;
}
Esempio n. 24
0
hsv hsv::operator+(const hsv b) const {
	return hsv(h + b.h, s + b.s, v + b.v);
}
Esempio n. 25
0
hsv hsv::operator*(const float x) const {
	return hsv(h * x, s * x, v * x);
}
Esempio n. 26
0
void GalaxyEffect::Render(Effect *effect, const SettingsMap &SettingsMap, RenderBuffer &buffer) {
    int center_x = SettingsMap.GetInt("SLIDER_Galaxy_CenterX");
    int center_y = SettingsMap.GetInt("SLIDER_Galaxy_CenterY");
    int start_radius = SettingsMap.GetInt("SLIDER_Galaxy_Start_Radius");
    int end_radius = SettingsMap.GetInt("SLIDER_Galaxy_End_Radius");
    int start_angle = SettingsMap.GetInt("SLIDER_Galaxy_Start_Angle");
    int revolutions = SettingsMap.GetInt("SLIDER_Galaxy_Revolutions");
    int start_width = SettingsMap.GetInt("SLIDER_Galaxy_Start_Width");
    int end_width = SettingsMap.GetInt("SLIDER_Galaxy_End_Width");
    int duration = SettingsMap.GetInt("SLIDER_Galaxy_Duration");
    int acceleration = SettingsMap.GetInt("SLIDER_Galaxy_Accel");
    bool reverse_dir = SettingsMap.GetBool("CHECKBOX_Galaxy_Reverse");
    bool blend_edges = SettingsMap.GetBool("CHECKBOX_Galaxy_Blend_Edges");
    bool inward = SettingsMap.GetBool("CHECKBOX_Galaxy_Inward");

    if( revolutions == 0 ) return;
    std::vector< std::vector<double> > temp_colors_pct(buffer.BufferWi, std::vector<double>(buffer.BufferHt));
    std::vector< std::vector<double> > pixel_age(buffer.BufferWi, std::vector<double>(buffer.BufferHt));

    double eff_pos = buffer.GetEffectTimeIntervalPosition();
    int num_colors = buffer.palette.Size();
    xlColor color, c_old, c_new;
    HSVValue hsv1;
    double eff_pos_adj = buffer.calcAccel(eff_pos, acceleration);
    double revs = (double)revolutions;

    double pos_x = buffer.BufferWi * center_x/100.0;
    double pos_y = buffer.BufferHt * center_y/100.0;

    double head_duration = duration/100.0;    // time the head is in the frame
    double tail_length = revs * (1.0 - head_duration);
    double color_length = tail_length / num_colors;
    if(color_length < 1.0) color_length = 1.0;


    double tail_end_of_tail = ((revs + tail_length) * eff_pos_adj) - tail_length;
    double head_end_of_tail = tail_end_of_tail + tail_length;

    double radius1 = start_radius;
    double radius2 = end_radius;
    double width1 = start_width;
    double width2 = end_width;

    double step = buffer.GetStepAngle(radius1, radius2);

    for( int x = 0; x < buffer.BufferWi; x++ )
    {
        for( int y = 0; y < buffer.BufferHt; y++ )
        {
            temp_colors_pct[x][y] = 0.0;
            pixel_age[x][y] = 0.0;
        }
    }
    buffer.ClearTempBuf();

    double last_check = (inward ? std::min(head_end_of_tail,revs) : std::max(0.0, tail_end_of_tail) ) + (double)start_angle;

    for( double i = (inward ? std::min(head_end_of_tail,revs) : std::max(0.0, tail_end_of_tail));
        (inward ? i >= std::max(0.0, tail_end_of_tail) : i <= std::min(head_end_of_tail,revs));
        (inward ? i -= step : i += step) )
    {
        double adj_angle = i + (double)start_angle;
        if( reverse_dir )
        {
            adj_angle *= -1.0;
        }
        double color_val = (head_end_of_tail-i) / color_length;
        int color_int = (int)color_val;
        double color_pct = color_val - (double)color_int;
        int color2 = std::min(color_int+1, num_colors-1);
        if( color_int < color2 )
        {
            buffer.Get2ColorBlend(color_int, color2, std::min( color_pct, 1.0), color);
        }
        else
        {
            buffer.palette.GetColor(color2, color);
        }
        HSVValue hsv(color);
        double full_brightness = hsv.value;
        double pct = i/revs;
        double current_radius = radius2 * pct + radius1 * (1.0 - pct);
        double current_width = width2 * pct + width1 * (1.0 - pct);
        double half_width = current_width / 2.0;
        double inside_radius = current_radius - half_width;
        for( double r = inside_radius; ; r += 0.5 )
        {
            if( r > current_radius ) r = current_radius;
            double x1 = buffer.sin(ToRadians(adj_angle)) * r + (double)pos_x;
            double y1 = buffer.cos(ToRadians(adj_angle)) * r + (double)pos_y;
            double outside_radius = current_radius + (current_radius - r);
            double x2 = buffer.sin(ToRadians(adj_angle)) * outside_radius + (double)pos_x;
            double y2 = buffer.cos(ToRadians(adj_angle)) * outside_radius + (double)pos_y;
            double color_pct2 = (r-inside_radius)/(current_radius-inside_radius);
            if( blend_edges )
            {
                if( hsv.value > 0.0 )
                {
                    if ((int)x1 >= 0 && (int)x1 < buffer.BufferWi && (int)y1 >= 0 && (int)y1 < buffer.BufferHt)
                    {
                        buffer.SetTempPixel((int)x1,(int)y1,color);
                        temp_colors_pct[(int)x1][(int)y1] = color_pct2;
                        pixel_age[(int)x1][(int)y1] = adj_angle;
                    }
                    if ((int)x2 >= 0 && (int)x2 < buffer.BufferWi && (int)y2 >= 0 && (int)y2 < buffer.BufferHt)
                    {
                        buffer.SetTempPixel((int)x2,(int)y2,color);
                        temp_colors_pct[(int)x2][(int)y2] = color_pct2;
                        pixel_age[(int)x2][(int)y2] = adj_angle;
                    }
                }
            }
            else
            {
                hsv.value = full_brightness * color_pct2;
                if( hsv.value > 0.0 )
                {
                    buffer.SetPixel(x1,y1,hsv);
                    buffer.SetPixel(x2,y2,hsv);
                }
            }
            if( r >= current_radius ) break;
        }
        // blend old data down into final buffer
        if( blend_edges && ( (inward ? (last_check-adj_angle) : (adj_angle-last_check)) >= 90.0) )
        {
            for( int x = 0; x < buffer.BufferWi; x++ )
            {
                for( int y = 0; y < buffer.BufferHt; y++ )
                {
                    if( temp_colors_pct[x][y] > 0.0 && ((inward ? (pixel_age[x][y]-adj_angle) : (adj_angle-pixel_age[x][y])) >= 180.0) )
                    {
                        buffer.GetTempPixel(x,y,c_new);
                        buffer.GetPixel(x,y,c_old);
                        buffer.Get2ColorAlphaBlend(c_old, c_new, temp_colors_pct[x][y], color);
                        buffer.SetPixel(x,y,color);
                        temp_colors_pct[x][y] = 0.0;
                        pixel_age[x][y] = 0.0;
                    }
                }
            }
            last_check = adj_angle;
        }
    }

    // blend remaining data down into final buffer
    if( blend_edges )
    {
        for( int x = 0; x < buffer.BufferWi; x++ )
        {
            for( int y = 0; y < buffer.BufferHt; y++ )
            {
                if( temp_colors_pct[x][y] > 0.0 )
                {
                    buffer.GetTempPixel(x,y,c_new);
                    buffer.GetPixel(x,y,c_old);
                    buffer.Get2ColorAlphaBlend(c_old, c_new, temp_colors_pct[x][y], color);
                    buffer.SetPixel(x,y,color);
                }
            }
        }
    }

}
Esempio n. 27
0
GModelCube::GModelCube(const float side){
	const float hs = side*0.5f;
	VertexAttribute.resize(4 * 6);
	int i = 0;
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, -hs);

	VertexAttribute[i++].position = vec3(-hs, hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);

	VertexAttribute[i++].position = vec3(hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, -hs);
	VertexAttribute[i++].position = vec3(hs, hs, hs);
	VertexAttribute[i++].position = vec3(hs, -hs, hs);

	VertexAttribute[i++].position = vec3(-hs, -hs, -hs);
	VertexAttribute[i++].position = vec3(-hs, -hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, hs);
	VertexAttribute[i++].position = vec3(-hs, hs, -hs);

	i = 0;
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);

	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);

	VertexAttribute[i++].normal = vec3(1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, -1.0);
	VertexAttribute[i++].normal = vec3(1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(1.0, -1.0, 1.0);

	VertexAttribute[i++].normal = vec3(-1.0, -1.0, -1.0);
	VertexAttribute[i++].normal = vec3(-1.0, -1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, 1.0);
	VertexAttribute[i++].normal = vec3(-1.0, 1.0, -1.0);


	for (int i = 0; i < VertexAttribute.size(); i++){
		vec3 hsv(360.0f / (float)i, 1.0, 1.0);
		VertexAttribute[i].color = vec4(hsv2rgb(hsv), 1.0);
	}


	Index.resize(2 * 6);
	i = 0;
	Index[i++] = u16vec3(0, 1, 2);
	Index[i++] = u16vec3(0, 2, 3);

	Index[i++] = u16vec3(4, 5, 6);
	Index[i++] = u16vec3(4, 6, 7);

	Index[i++] = u16vec3(8, 9, 10);
	Index[i++] = u16vec3(8, 10, 11);

	Index[i++] = u16vec3(12, 13, 14);
	Index[i++] = u16vec3(12, 14, 15);

	Index[i++] = u16vec3(16, 17, 18);
	Index[i++] = u16vec3(16, 18, 19);

	Index[i++] = u16vec3(20, 21, 22);
	Index[i++] = u16vec3(20, 22, 23);

	CreateVBO();
	CreateIBO();
	BindVBO();
	BindIBO();

}
Esempio n. 28
0
/**
 * Process a single frame.
 *
 * Currently this converts the RGB image from the camera
 * to the BGR format expected by OpenCV, then displays
 * the image using OpenCV. In the future, image processing
 * will happen here.
 *
 * This does not have to be a global function; it could also
 * be put inline as a lambda function.
 *
 * @param frame the frame to be processed.
 */
void process_frame(cv::Mat frame) {
    ++n;
    cv::Mat_<cv::Vec3b> hsv(frame.size());
    cv::Mat_<unsigned char> binary(frame.size());
    cv::Mat_<unsigned char> back(frame.size());
    cv::Mat_<cv::Vec3b> disp(frame.size());
    cv::cvtColor(frame, hsv, CV_RGB2HSV_FULL);
    frame.copyTo(disp);
    //cv::cvtColor(frame, disp, CV_RGB2BGR);
    //int min[] = {hue-range, 0, 0};
    //int max[] = {hue+range, 255, 255};
    /*
    cv::inRange(hsv, cv::Scalar(hue-range, s_min, v_min), cv::Scalar(hue+range, s_max, v_max), binary);
    */
    int numP = 0;
    if(done_hist) {
        cv::calcBackProject(&hsv, 1, channels, hist, binary, ranges, 1);
        cv::calcBackProject(&hsv, 1, channels, back_hist, back, ranges, 1);
        //cv::inRange(binary, 150, 255, binary);
        //cv::morphologyEx(binary, binary, cv::MORPH_CLOSE, getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(20, 20)));
        //cv::close(binary, binary, getStructuringElement(MORPH_ELLIPSE, cv::Size(2*10+1, 2*10+1), cv::Point(10, 10)));

        float centroid_x = 0.0f;
        float centroid_y = 0.0f;
        for(int j = 0; j < frame.rows; ++j) {
            for(int i = 0; i < frame.cols; ++i) {
                float weight = binary(j, i);
                float back_weight = back(j, i);
                if(weight > back_weight * (threshold / 500.0f)) {
                    binary(j, i) = 255;
                    //if(weight > 200) {
                    numP += weight;
                    centroid_x += i * weight;
                    centroid_y += j * weight;
                } else {
                    binary(j, i) = 0;
                }
            }
        }
        centroid_x /= numP;
        centroid_y /= numP;

        cv::circle(disp, cv::Point((int)centroid_x, (int)centroid_y), 5, cv::Scalar(255, 0, 0), -1);

        float r = sqrt(centroid_x*centroid_x + centroid_y*centroid_y);
    }
    /*
    cv::Mat hue(frame.size(), CV_8U);
    const int fromto[] = {0, 0};
    cv::mixChannels(&frame, 1, &hue, 1, fromto, 1);
    cv::Mat binary(frame.size(), CV_8U);
    cv::inRange(frame, 0, 50, binary);
    */



    //cv::Mat_<unsigned char> binary = cv::Mat_<unsigned char>::zeros(frame.rows, frame.cols);
    /*
    for(int j = 0; j < frame.rows; ++j) {
        for(int i = 0; i < frame.cols; ++i) {
            int r = frame.at<cv::Vec3b>(j, i)[0];
            int b = frame.at<cv::Vec3b>(j, i)[1];
            int g = frame.at<cv::Vec3b>(j, i)[2];
            binary(j, i) = r - r*(b + g)/(2*255);
            float r = frame.at<cv::Vec3b>(j, i)[0]/255.0f;
            float b = frame.at<cv::Vec3b>(j, i)[1]/255.0f;
            float g = frame.at<cv::Vec3b>(j, i)[2]/255.0f;
            float h = 0;

            if(r>=g) {
                if(g>=b) {
                    h = 60*(2-(g-b)/(r-b));
                } else {
                    60*(4-(g-r)/(b-r));
                }
            } else {

            }

            if(r>=g && g>=b)        h = 60*(2-(g-b)/(r-b));
            else if(g>r && r>=b)    h = 60*(2-(r-b)/(g-b));
            else if(g>=b && b>r)    h = 60*(2+(b-r)/(g-r));
            else if(b>g && g>r)     h = 60*(4-(g-r)/(b-r));
            else if(b>r && r>=g)    h = 60*(4+(r-g)/(b-g));
            else if(r>=b && b>g)    h = 60*(6-(b-g)/(r-g));

            h *= 255.0f/360.0f;

            //binary(j, i) = target - (unsigned char)h;
            if( (target -(unsigned char)h) < 10 ||  ((unsigned char)h - target) < 10) {
                binary(j, i) = 255;
            } else {
                binary(j, i) = 0;
            }
        }
    }
    */

    /*
    cv::Mat blurred(binary.size(), CV_8U);
    cv::GaussianBlur(binary, blurred, cv::Size(9, 9), 2, 2);
    std::vector<cv::Vec3f> circles;
    cv::HoughCircles(blurred, circles, CV_HOUGH_GRADIENT, 2, frame.rows, 30, 100, 5, 100);

    for(size_t i = 0; i < circles.size(); ++i) {
        cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
        cv::circle(disp, center, 5, cv::Scalar(0, 255, 0), -1, 8, 0);
        //cv::circle(frame, center, radius, cv::Scalar(0), 3, 8, 0);
    }


    */
    cv::circle(disp, cv::Point(frame.size().width/2,frame.size().height/2), 25, cv::Scalar(0, 255, 0));


    VC_RECT_T dst_rect;
    vc_dispmanx_rect_set( &dst_rect, 0, 0, 160, 120);
    int ret = vc_dispmanx_resource_write_data(  display_resource,
              VC_IMAGE_RGB888,
              160*3,
              disp.data,
              &dst_rect);
    assert(ret==0);
    DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start( 10 );
    vc_dispmanx_element_modified(update, element, &dst_rect);
    vc_dispmanx_update_submit_sync(update);


    //cv::imshow("RPi Cam Raw", disp);
    //cv::imshow("RPi Cam Proc", binary);
}
Esempio n. 29
0
void TestApp::test_hsv()
{
	Console::write_line(" Header: color_hsv.h");
	Console::write_line("  Class: ColorHSVi");
	
	Console::write_line("   Function: ColorHSVi()");
	{
		ColorHSVi hsv;
		if (hsv.h !=0) fail();
		if (hsv.s !=0) fail();
		if (hsv.v !=0) fail();
		if (hsv.a !=0) fail();
	}
	
	Console::write_line("   Function: ColorHSVi(int h, int s, int v, int a)");
	{
		ColorHSVi hsv(1,2,3,4);
		if (hsv.h != 1) fail();
		if (hsv.s != 2) fail();
		if (hsv.v != 3) fail();
		if (hsv.a != 4) fail();
	}
	
	Console::write_line("   Function: ColorHSVi(const ColorHSVi &copy)");
	{
		ColorHSVi hsv(1,2,3,4);
		ColorHSVi hsv_copy(hsv);
		if (hsv_copy.h != 1) fail();
		if (hsv_copy.s != 2) fail();
		if (hsv_copy.v != 3) fail();
		if (hsv_copy.a != 4) fail();
	}
	
	Console::write_line("   Function: ColorHSVi(const Color &color)");
	{
		Color color(255, 0, 0, 64);
		ColorHSVi hsv(color);
		if (hsv.h != 0) fail();
		if (hsv.s != 255) fail();
		if (hsv.v != 255) fail();
		if (hsv.a != 64) fail();
	}
	
	
	
	{
		Color color(128, 255, 128, 64);
		ColorHSVi hsv(color);
		if (hsv.h != 120) fail();
		if (hsv.s != 127) fail();
		if (hsv.v != 255) fail();
		if (hsv.a != 64) fail();
	}
	
	{
		Colorf colorf(0.5f, 1.0f, 0.5f, 1.0f);
		ColorHSVi hsv(colorf);
		if (hsv.h != 120) fail();
		if (hsv.s != 128) fail();
		if (hsv.v != 255) fail();
		if (hsv.a != 255) fail();
	}

	{
		Color color(0, 0, 128, 64);
		ColorHSVi hsv(color);
		if (hsv.h != 240) fail();
		if (hsv.s != 255) fail();
		if (hsv.v != 128) fail();
		if (hsv.a != 64) fail();
	}
	{
		Color color(64, 90, 136, 90);
		ColorHSVi hsv(color);
		if (hsv.h != 218) fail();
		if (hsv.s != 135) fail();
		if (hsv.v != 136) fail();
		if (hsv.a != 90) fail();
	}
	{
		Color color(128, 128, 128, 90);
		ColorHSVi hsv(color);
		if (hsv.h != 0) fail();
		if (hsv.s != 0) fail();
		if (hsv.v != 128) fail();
		if (hsv.a != 90) fail();
	}

	{
		Color color(64, 90, 136, 90);
		ColorHSVi hsv(color);
		Color color2(hsv);
		int red = color2.get_red();
		int green = color2.get_green();
		int blue = color2.get_blue();
		int alpha = color2.get_alpha();
		if (red != 64) fail();
		if (green != 90) fail();
		if (blue != 136) fail();
		if (alpha != 90) fail();

	}
	

	
	Console::write_line("  Class: ColorHSVf");

	Console::write_line("   Function: ColorHSVf()");
	{
		ColorHSVf hsv;
		if (hsv.h !=0.0f) fail();
		if (hsv.s !=0.0f) fail();
		if (hsv.v !=0.0f) fail();
		if (hsv.a !=0.0f) fail();
	}

	Console::write_line("   Function: ColorHSVf(float h, float s, float v, float a)");
	{
		ColorHSVf hsv(0.1f, 0.2f, 0.3f, 0.4f);
		if (hsv.h != 0.1f) fail();
		if (hsv.s != 0.2f) fail();
		if (hsv.v != 0.3f) fail();
		if (hsv.a != 0.4f) fail();
	}

	Console::write_line("   Function: ColorHSVf(const ColorHSVf &copy)");
	{
		ColorHSVf hsv(0.1f, 0.2f, 0.3f, 0.4f);
		ColorHSVf hsv_copy(hsv);
		if (hsv_copy.h != 0.1f) fail();
		if (hsv_copy.s != 0.2f) fail();
		if (hsv_copy.v != 0.3f) fail();
		if (hsv_copy.a != 0.4f) fail();
	}
	Console::write_line("   Function: ColorHSVf(const Colorf &color)");
	{
		Colorf color(1.0f, 0.0f, 0.0f, 0.2f);
		ColorHSVf hsv(color);
		if (hsv.h != 0.0f) fail();
		if (hsv.s != 1.0f) fail();
		if (hsv.v != 1.0f) fail();
		if (hsv.a != 0.2f) fail();
	}

	{
		Colorf color(0.5f, 1.0f, 0.5f, 0.2f);
		ColorHSVf hsv(color);
		if (hsv.h != 120.0f) fail();
		if (hsv.s != 0.5f) fail();
		if (hsv.v != 1.0f) fail();
		if (hsv.a != 0.2f) fail();
	}

	{
		Color color(127, 255, 127, 255);
		ColorHSVf hsv(color);
		if (hsv.h != 120.0f) fail();
		if (hsv.s < 0.49f) fail();
		if (hsv.s > 0.51f) fail();
		if (hsv.v != 1.0f) fail();
		if (hsv.a != 1.0f) fail();
	}

	{
		Colorf color(0.0f, 0.0f, 0.5, 0.3f);
		ColorHSVf hsv(color);
		if (hsv.h != 240.0f) fail();
		if (hsv.s != 1.0f) fail();
		if (hsv.v != 0.5f) fail();
		if (hsv.a != 0.3f) fail();
	}
	
	{
		Colorf color(0.2f, 0.4f, 0.7f, 0.3f);
		ColorHSVf hsv(color);
		Colorf color2(hsv);
		if (color.r < 0.1999f) fail();
		if (color.r > 0.2001f) fail();
		if (color.g < 0.3999f) fail();
		if (color.g > 0.4001f) fail();
		if (color.b < 0.6999f) fail();
		if (color.b > 0.7001f) fail();
		if (color.a < 0.2999f) fail();
		if (color.a > 0.3001f) fail();
	}
	
	Console::write_line("  Class: ColorHSVd");


}
Esempio n. 30
0
cv::Mat flow_2_RGB( const cv::Mat &inpFlow, const float &max_size )
{

        //////////////////////////
        bool    use_value = false;
        cv::Mat sat;
        cv::Mat rgbFlow;
        //////////////////////////

        if (inpFlow.empty())                                                                                                             exit(1);
        if (inpFlow.depth() != CV_32F)  {   std::cout << "FlowTo RGB: error inpFlow wrong data type ( has be CV_32FC2" << std::endl;     exit(1);     }
        if (!sat.empty() )
            if( sat.type() != CV_8UC1)  {   std::cout << "FlowTo RGB: error sat must have type CV_8UC1"                << std::endl;     exit(1);     }

        const float grad2deg = (float)(90/3.141);
        double satMaxVal = 0;
        double minVal = 0;
        if(!sat.empty())
        {
            cv::minMaxLoc(sat, &minVal, &satMaxVal);
            satMaxVal = 255.0/satMaxVal;
        }

        cv::Mat pol(inpFlow.size(), CV_32FC2);

        float mean_val = 0, min_val = 1000, max_val = 0;

        for(int r = 0; r < inpFlow.rows; r++)
        {
            for(int c = 0; c < inpFlow.cols; c++)
            {
                cv::Mat1f inX( 1,1);  inX(0,0)=inpFlow.at<cv::Point2f>(r,c).x;
                cv::Mat1f inY( 1,1);  inY(0,0)=inpFlow.at<cv::Point2f>(r,c).y;
                cv::Mat1f outX(1,1);
                cv::Mat1f outY(1,1);
                cv::cartToPolar( inX, inY, outX, outY, false );
                cv::Point2f polar;
                            polar.x = outX(0,0);
                            polar.y = outY(0,0);

                polar.y *= grad2deg;
                mean_val +=polar.x;
                max_val = MAX(max_val, polar.x);
                min_val = MIN(min_val, polar.x);
                pol.at<cv::Point2f>(r,c) = cv::Point2f(polar.y,polar.x);
            }
        }
        mean_val /= inpFlow.size().area();
        float scale = max_val - min_val;
        float shift = -min_val;
        scale = 255.f/scale;
        if( max_size > 0)
        {
            scale = 255.f/max_size;
            shift = 0;
        }

        //calculate the angle, motion value
        cv::Mat hsv(inpFlow.size(), CV_8UC3);
        uchar * ptrHSV = hsv.ptr<uchar>();
        int idx_val  = (use_value) ? 2:1;
        int idx_sat  = (use_value) ? 1:2;


        for(int r = 0; r < inpFlow.rows; r++, ptrHSV += hsv.step1())
        {
            uchar * _ptrHSV = ptrHSV;
            for(int c = 0; c < inpFlow.cols; c++, _ptrHSV+=3)
            {
                cv::Point2f vpol = pol.at<cv::Point2f>(r,c);

                _ptrHSV[0] = cv::saturate_cast<uchar>(vpol.x);
                _ptrHSV[idx_val] = cv::saturate_cast<uchar>( (vpol.y + shift) * scale);
                if( sat.empty())
                    _ptrHSV[idx_sat] = 255;
                else
                    _ptrHSV[idx_sat] = 255-  cv::saturate_cast<uchar>(sat.at<uchar>(r,c) * satMaxVal);

            }
        }
        std::vector<cv::Mat> vec;
        cv::split(hsv, vec);
        cv::equalizeHist(vec[idx_val],vec[idx_val]);
        cv::merge(vec,hsv);
        cv::Mat rgbFlow32F;
        cv::cvtColor(hsv, rgbFlow32F, CV_HSV2BGR);
        rgbFlow32F.convertTo(rgbFlow, CV_8UC3);

        ///////////////
        return rgbFlow;
        ///////////////
}