コード例 #1
0
void MotionTrackerFB::drawOpticalFlow(cv::Mat& output, float maxmotion)
{
    // determine motion range:
    maxrad = maxmotion;

    if (maxmotion <= 0) {
        maxrad = 1;
        for (int y = 0; y < flow.rows; ++y)
        {
            for (int x = 0; x < flow.cols; ++x)
            {
                cv::Point2f u = flow(y, x);

                if (!isFlowCorrect(u))
                    continue;

                maxrad = std::max(maxrad, (float)sqrt(u.x * u.x + u.y * u.y));
            }
        }
    }

    for (int y = 0; y < flow.rows; ++y) {
        for (int x = 0; x < flow.cols; ++x) {
            cv::Point2f u = flow(y, x);

            if (isFlowCorrect(u))
                output.at<cv::Vec3b>(y, x) = computeColor(u.x / maxrad, u.y / maxrad);
        }
    }
}
コード例 #2
0
	void FractalTexture::create() {
		if(glIsTexture(texture.id)) glDeleteTextures(1, &texture.id); //cleaning gl memory up
		m_iMaxIterations = (long)((double)m_iStdMaxIterations * 1.0); //todo?
		m_dInvMaxIterations = 1.0 / (m_iMaxIterations+0.0001);
		const double winv = 1.0/(texture.width -1);
		const double hinv = 1.0/(texture.height-1);
		util::timeDiff();
		for (int x = 0; x < texture.width; ++x) {
			for (int y = 0; y < texture.height; ++y) {
#ifdef ROE_FRACTAL_GMP_USE_C
				mpf_set_d(m_xPos, x*winv);
				mpf_set_d(m_yPos, y*hinv);
				mpf_mul(m_xPos, m_xPos, m_width);
				mpf_mul(m_yPos, m_yPos, m_height);
				mpf_add(m_xPos, m_xUpLt, m_xPos);
				mpf_sub(m_yPos, m_yUpLt, m_yPos);
#else
				m_xPos = m_xUpLt + (x*winv)*m_width;
				m_yPos = m_yUpLt - (y*hinv)*m_height;
#endif
				computeColor(&(texture.data[((texture.height-1-y)*texture.width+x)*texture.bpp]));
			}
		}
		cout << "dt: " << util::timeDiff() << endl;
		cout << getCenterX() << endl;
		cout << getCenterY() << endl;
		cout << getZoomW() << endl;
		updateMipmaps();
		Texture::loadTextureIntoGL(&texture);
	}
コード例 #3
0
ファイル: main.c プロジェクト: nphyx/justen.us
void main(void) {
	// calculate aspect ratio from resolution
	float aspectRatio = u_resolution.x / u_resolution.y;
	// ray origin from eye position uniform
	vec3 ro = u_eye;
	// calculate the ray direction normal
	vec3 rd = normalize(u_camForward * g_focalLength + u_camRight * uv.x * aspectRatio + u_camUp * uv.y);
	// start the color calculation
	vec4 color = computeColor(ro, rd);
	gl_FragColor = vec4(color.xyz, 1.0);
}
コード例 #4
0
ファイル: color_flow.cpp プロジェクト: angusforbes/optiflow
void MotionToColor(CFloatImage motim, CByteImage &colim, float maxmotion)
{
    CShape sh = motim.Shape();
    int width = sh.width, height = sh.height;
    colim.ReAllocate(CShape(width, height, 3));
    int x, y;
    // determine motion range:
    float maxx = -999, maxy = -999;
    float minx =  999, miny =  999;
    float maxrad = -1;
    for (y = 0; y < height; y++) {
	for (x = 0; x < width; x++) {
	    float fx = motim.Pixel(x, y, 0);
	    float fy = motim.Pixel(x, y, 1);
	    if (unknown_flow(fx, fy))
		continue;
	    maxx = __max(maxx, fx);
	    maxy = __max(maxy, fy);
	    minx = __min(minx, fx);
	    miny = __min(miny, fy);
	    float rad = sqrt(fx * fx + fy * fy);
	    maxrad = __max(maxrad, rad);
	}
    }
    printf("max motion: %.4f  motion range: u = %.3f .. %.3f;  v = %.3f .. %.3f\n",
	   maxrad, minx, maxx, miny, maxy);


    if (maxmotion > 0) // i.e., specified on commandline
	maxrad = maxmotion;

    if (maxrad == 0) // if flow == 0 everywhere
	maxrad = 1;

    if (verbose)
	fprintf(stderr, "normalizing by %g\n", maxrad);

    for (y = 0; y < height; y++) {
	for (x = 0; x < width; x++) {
	    float fx = motim.Pixel(x, y, 0);
	    float fy = motim.Pixel(x, y, 1);
	    uchar *pix = &colim.Pixel(x, y, 0);
	    if (unknown_flow(fx, fy)) {
		pix[0] = pix[1] = pix[2] = 0;
	    } else {
		computeColor(fx/maxrad, fy/maxrad, pix);
	    }
	}
    }
}
コード例 #5
0
void computeColors(int n, std::vector< std::vector<T> > &colours) {
	static_assert(std::is_same<T, int>::value or std::is_same<T, double>::value, "Error computeColors. It only accepts floats or ints");
	T max;
	if (std::is_same<T, int>::value) {
		max = 255;
	} else {
		max = 1.0;
	}
	colours = std::vector< std::vector<T> >(n, std::vector<T>(3));

	for(int i = 0; i < n; i++) {
		computeColor(i, n, colours[i]);
	}
}
コード例 #6
0
	static void drawOpticalFlow(const Mat_<Point2f>& flow, Mat& dst, float maxmotion = -1)
	{
	    dst.create(flow.size(), CV_8UC3);
	    dst.setTo(Scalar::all(0));
	
	    // determine motion range:
	    float maxrad = maxmotion;
	
	    if (maxmotion <= 0)
	    {
	        maxrad = 1;
	        for (int y = 0; y < flow.rows; ++y)
	        {
	            for (int x = 0; x < flow.cols; ++x)
	            {
	                Point2f u = flow(y, x);
	
	                if (!isFlowCorrect(u))
	                    continue;
	
	                maxrad = max(maxrad, sqrt(u.x * u.x + u.y * u.y));
	            }
	        }
	    }
	
	    for (int y = 0; y < flow.rows; ++y)
	    {
	        for (int x = 0; x < flow.cols; ++x)
	        {
	            Point2f u = flow(y, x);
	
	            if (isFlowCorrect(u))
	                dst.at<Vec3b>(y, x) = computeColor(u.x / maxrad, u.y / maxrad);
	        }
	    }
	}
コード例 #7
0
ファイル: flow_mod.cpp プロジェクト: lowks/hindemith
static PyObject*
run(PyObject *self, PyObject *args, PyObject *kwargs)
{

  /* get the number of arguments */
  Py_ssize_t argc = PyTuple_Size(args);
  if(argc != 3)
  {
    std::cout << "Not the right number of arguments" << std::endl;
    Py_INCREF(Py_None);
    return Py_None;
  }

  /* get the first argument (kwargs) */
  PyObject *dxObj = PyTuple_GetItem(args, 0); 
  PyObject *dyObj = PyTuple_GetItem(args, 1); 
  PyObject *fmObj = PyTuple_GetItem(args, 2); 
  assert(PyArray_Check(dxObj));
  assert(PyArray_Check(dyObj));

  // Found variable, now copy it into the C/OCL data structure
  PyArrayObject * dxArray = (PyArrayObject*)dxObj;
  PyArrayObject * dyArray = (PyArrayObject*)dyObj;

  npy_intp * dims = PyArray_DIMS(dxArray);
  npy_intp out_dims[3];
  out_dims[0] = dims[0];
  out_dims[1] = dims[1];
  out_dims[2] = 3;

  double * dxData = (double *)dxArray->data;
  double * dyData = (double *)dyArray->data;
  unsigned char * out_data = (unsigned char *) calloc(out_dims[0] * out_dims[1] * out_dims[2], sizeof(unsigned char));

  double flowmax = 0.0;

  double input_fm;
  PyArray_ScalarAsCtype(fmObj, &input_fm);

  if(input_fm <= 0)
  {

    for(int i = 0 ; i < out_dims[0] ; i++)
    {
      for(int j = 0 ; j < out_dims[1] ; j++)
      {
        double fx = dxData[j + i * out_dims[1]];
        double fy = dyData[j + i * out_dims[1]];
        double mag = sqrt(fx * fx + fy * fy);
        if(mag > flowmax) flowmax = mag;
      }
    }
  }
  else
  {
    flowmax = input_fm;
  }


  for(int i = 0 ; i < out_dims[0] ; i++)
  {
    for(int j = 0 ; j < out_dims[1] ; j++)
    {
      double fx = dxData[j + i * out_dims[1]];
      double fy = dyData[j + i * out_dims[1]];
      computeColor(fx / flowmax, fy / flowmax , &out_data[j * 3 + i * out_dims[1] * 3]);
    }
  }

  PyObject * retArray = PyArray_New(&PyArray_Type, 3, out_dims, NPY_UINT8, NULL, out_data, 0, NPY_C_CONTIGUOUS, NULL);

  return retArray;

}
コード例 #8
0
ファイル: RipplingMOO.cpp プロジェクト: falkin/gpu-1213
void RipplingMOO::setPixel(int i, int j, float t)
    {
    unsigned char r, g, b;
    r = g = b = computeColor(i, j, t, getW(), getH());
    setRGBA(i, j, r, g, b);
    }
コード例 #9
0
ossimRefPtr<ossimImageData> ossimBumpShadeTileSource::getTile(
   const  ossimIrect& tileRect,
   ossim_uint32 resLevel)
{
   if(!getInput(0)) return 0;

   if(!m_tile.get())
   {
      allocate();
   }
   if(!m_tile.valid())
   {
      return m_tile;
   }
   ossimImageSource* normalSource =
      PTR_CAST(ossimImageSource, getInput(0));
   ossimImageSource* colorSource =
      PTR_CAST(ossimImageSource, getInput(1));
   
   if(!m_tile.get())
   {
      return ossimRefPtr<ossimImageData>();
   }

   m_tile->setImageRectangle(tileRect);
 
   ossimRefPtr<ossimImageData> inputTile = 0;

   if(isSourceEnabled())
   {
      m_tile->makeBlank();
      
      if(colorSource)
      {
         
         inputTile = colorSource->getTile(tileRect, resLevel);
      }
      ossimRefPtr<ossimImageData> normalData = normalSource->getTile(tileRect, resLevel);
      if(!normalData)
      {
         return ossimRefPtr<ossimImageData>();
      }
      if ( (normalData->getDataObjectStatus() == OSSIM_NULL) ||
           (normalData->getDataObjectStatus() == OSSIM_EMPTY)||
           (normalData->getNumberOfBands() != 3)||
           (normalData->getScalarType() != OSSIM_DOUBLE))
      {
         return ossimRefPtr<ossimImageData>();
      }
      ossim_float64* normalBuf[3];
      normalBuf[0] = static_cast<ossim_float64*>(normalData->getBuf(0));
      normalBuf[1] = static_cast<ossim_float64*>(normalData->getBuf(1));
      normalBuf[2] = static_cast<ossim_float64*>(normalData->getBuf(2));
      ossim_float64 normalNp = normalData->getNullPix(0);
      // if we have some color data then use it for the bump
      // else we will default to a grey scale bump shade
      //
      if(inputTile.get() &&
         (inputTile->getDataObjectStatus() != OSSIM_EMPTY) &&
         (inputTile->getDataObjectStatus() != OSSIM_NULL))
         
      {
         switch(inputTile->getScalarType())
         {
            case OSSIM_UCHAR:
            {
               ossim_uint8* resultBuf[3];
               ossim_uint8* colorBuf[3];
               resultBuf[0] = static_cast<ossim_uint8*>(m_tile->getBuf(0));
               resultBuf[1] = static_cast<ossim_uint8*>(m_tile->getBuf(1));
               resultBuf[2] = static_cast<ossim_uint8*>(m_tile->getBuf(2));
               colorBuf[0]  = static_cast<ossim_uint8*>(inputTile->getBuf(0));
               if(inputTile->getBuf(1))
               {
                  colorBuf[1] = static_cast<ossim_uint8*>(inputTile->getBuf(1));
               }
               else
               {
                  colorBuf[1] = colorBuf[0];
               }
               if(inputTile->getBuf(2))
               {
                  colorBuf[2] = static_cast<ossim_uint8*>(inputTile->getBuf(2));
               }
               else
               {
                  colorBuf[2] = colorBuf[0];
               }
            
               long h = m_tile->getHeight();
               long w = m_tile->getWidth();
               for(long y = 0; y < h; ++y)
               {
                  for(long x = 0; x < w; ++x)
                  {
                     if((*normalBuf[0] != normalNp) &&
                        (*normalBuf[1] != normalNp) &&
                        (*normalBuf[2] != normalNp) )
                     {
                        if((*colorBuf[0])||(*colorBuf[1])||(*colorBuf[2]))
                        {
                           computeColor(*resultBuf[0],
                                        *resultBuf[1],
                                        *resultBuf[2],
                                        *normalBuf[0],
                                        *normalBuf[1],
                                        *normalBuf[2],
                                        *colorBuf[0],
                                        *colorBuf[1],
                                        *colorBuf[2]);
                        }
                        else 
                        {
                           computeColor(*resultBuf[0],
                                        *resultBuf[1],
                                        *resultBuf[2],
                                        *normalBuf[0],
                                        *normalBuf[1],
                                        *normalBuf[2],
                                        m_r,
                                        m_g,
                                        m_b);
                        }
                     }
                     else
                     {
                        *resultBuf[0] = *colorBuf[0];
                        *resultBuf[1] = *colorBuf[1];
                        *resultBuf[2] = *colorBuf[2];
                     }
                     resultBuf[0]++;
                     resultBuf[1]++;
                     resultBuf[2]++;
                     colorBuf[0]++;
                     colorBuf[1]++;
                     colorBuf[2]++;
                     normalBuf[0]++;
                     normalBuf[1]++;
                     normalBuf[2]++;
                  }
               }
               break;
            }
            default:
            {
               ossimNotify(ossimNotifyLevel_NOTICE)
                  << "ossimBumpShadeTileSource::getTile NOTICE:\n"
                  << "only 8-bit unsigned char is supported." << endl;
            }
         }
      }
      else
      {
         ossim_uint8* resultBuf[3];
         resultBuf[0] = static_cast<ossim_uint8*>(m_tile->getBuf(0));
         resultBuf[1] = static_cast<ossim_uint8*>(m_tile->getBuf(1));
         resultBuf[2] = static_cast<ossim_uint8*>(m_tile->getBuf(2));
         long h = m_tile->getHeight();
         long w = m_tile->getWidth();
         for(long y = 0; y < h; ++y)
         {
            for(long x = 0; x < w; ++x)
            {
               if((*normalBuf[0] != normalNp) &&
                  (*normalBuf[1] != normalNp) &&
                  (*normalBuf[2] != normalNp) )
               {
                     computeColor(*resultBuf[0],
                                  *resultBuf[1],
                                  *resultBuf[2],
                                  *normalBuf[0],
                                  *normalBuf[1],
                                  *normalBuf[2],
                                  m_r,
                                  m_g,
                                  m_b);
               }
               else
               {
                  *resultBuf[0] = 0;
                  *resultBuf[1] = 0;
                  *resultBuf[2] = 0;
               }
               resultBuf[0]++;
               resultBuf[1]++;
               resultBuf[2]++;
               normalBuf[0]++;
               normalBuf[1]++;
               normalBuf[2]++;
            }
         }
      }      
   }
   m_tile->validate();
   return m_tile;
}
コード例 #10
0
bool ossimBumpShadeTileSource::getTile(ossimImageData* tile, ossim_uint32 resLevel)
{
   if (!getInput(0) || !tile) return false;
   if(!isSourceEnabled()) return true;
   
   tile->makeBlank();
   
   ossimIrect tileRect = tile->getImageRectangle();
   ossimImageSource* colorSource = PTR_CAST(ossimImageSource, getInput(1));
   ossimRefPtr<ossimImageData> colorData = 0;
   if(colorSource)
   {
      colorData = new ossimImageData(colorSource, colorSource->getOutputScalarType(),
                                     colorSource->getNumberOfOutputBands(),
                                     tile->getWidth(), tile->getHeight());

      // Caution: Must set rect prior to getTile:
      colorData->setImageRectangle(tileRect);
      
      colorSource->getTile(colorData.get(), resLevel);
   }

   ossimImageSource* normalSource = PTR_CAST(ossimImageSource, getInput(0));
   ossimRefPtr<ossimImageData> normalData =
         new ossimImageData(normalSource, normalSource->getOutputScalarType(),
                            normalSource->getNumberOfOutputBands(),
                            tile->getWidth(), tile->getHeight());

   // Caution: Must set rect prior to getTile:
   normalData->setImageRectangle(tileRect);

   normalSource->getTile(normalData.get(), resLevel);
   ossimDataObjectStatus status = normalData->getDataObjectStatus();
   if ((status == OSSIM_NULL) || (status == OSSIM_EMPTY) ||
       (normalData->getNumberOfBands() != 3) ||
       (normalData->getScalarType() != OSSIM_DOUBLE))
   {
      return false;
   }

   ossim_float64* normalBuf[3];
   normalBuf[0] = static_cast<ossim_float64*>(normalData->getBuf(0));
   normalBuf[1] = static_cast<ossim_float64*>(normalData->getBuf(1));
   normalBuf[2] = static_cast<ossim_float64*>(normalData->getBuf(2));
   ossim_float64 normalNp = normalData->getNullPix(0);

   //---
   // If we have some color data then use it for the bump
   // else we will default to a grey scale bump shade.
   //---
   if ( colorData.get() &&
        (colorData->getDataObjectStatus() != OSSIM_EMPTY) &&
        (colorData->getDataObjectStatus() != OSSIM_NULL) )
   {
      switch(colorData->getScalarType())
      {
         case OSSIM_UCHAR:
         {
            ossim_uint8* resultBuf[3];
            ossim_uint8* colorBuf[3];
            resultBuf[0] = static_cast<ossim_uint8*>(tile->getBuf(0));
            resultBuf[1] = static_cast<ossim_uint8*>(tile->getBuf(1));
            resultBuf[2] = static_cast<ossim_uint8*>(tile->getBuf(2));
            colorBuf[0]  = static_cast<ossim_uint8*>(colorData->getBuf(0));
            if(colorData->getBuf(1))
            {
               colorBuf[1] = static_cast<ossim_uint8*>(colorData->getBuf(1));
            }
            else
            {
               colorBuf[1] = colorBuf[0];
            }
            if(colorData->getBuf(2))
            {
               colorBuf[2] = static_cast<ossim_uint8*>(colorData->getBuf(2));
            }
            else
            {
               colorBuf[2] = colorBuf[0];
            }

            long h = m_tile->getHeight();
            long w = m_tile->getWidth();
            for(long y = 0; y < h; ++y)
            {
               for(long x = 0; x < w; ++x)
               {
                  if((*normalBuf[0] != normalNp) &&
                     (*normalBuf[1] != normalNp) &&
                     (*normalBuf[2] != normalNp) )
                  {
                     if((*colorBuf[0])||(*colorBuf[1])||(*colorBuf[2]))
                     {
                        computeColor(*resultBuf[0],
                                     *resultBuf[1],
                                     *resultBuf[2],
                                     *normalBuf[0],
                                     *normalBuf[1],
                                     *normalBuf[2],
                                     *colorBuf[0],
                                     *colorBuf[1],
                                     *colorBuf[2]);
                     }
                     else
                     {
                        computeColor(*resultBuf[0],
                                     *resultBuf[1],
                                     *resultBuf[2],
                                     *normalBuf[0],
                                     *normalBuf[1],
                                     *normalBuf[2],
                                     m_r,
                                     m_g,
                                     m_b);
                     }
                  }
                  else
                  {
                     *resultBuf[0] = *colorBuf[0];
                     *resultBuf[1] = *colorBuf[1];
                     *resultBuf[2] = *colorBuf[2];
                  }
                  resultBuf[0]++;
                  resultBuf[1]++;
                  resultBuf[2]++;
                  colorBuf[0]++;
                  colorBuf[1]++;
                  colorBuf[2]++;
                  normalBuf[0]++;
                  normalBuf[1]++;
                  normalBuf[2]++;
               }
            }
            break;
         }
         default:
         {
            ossimNotify(ossimNotifyLevel_NOTICE)
               << "ossimBumpShadeTileSource::getTile NOTICE:\n"
               << "only 8-bit unsigned char is supported." << endl;
         }
      }
   }
   else
   {
      ossim_uint8* resultBuf[3];
      resultBuf[0] = static_cast<ossim_uint8*>(tile->getBuf(0));
      resultBuf[1] = static_cast<ossim_uint8*>(tile->getBuf(1));
      resultBuf[2] = static_cast<ossim_uint8*>(tile->getBuf(2));
      long h = tile->getHeight();
      long w = tile->getWidth();
      for(long y = 0; y < h; ++y)
      {
         for(long x = 0; x < w; ++x)
         {
            if((*normalBuf[0] != normalNp) &&
                  (*normalBuf[1] != normalNp) &&
                  (*normalBuf[2] != normalNp) )
            {
               computeColor(*resultBuf[0],
                            *resultBuf[1],
                            *resultBuf[2],
                            *normalBuf[0],
                            *normalBuf[1],
                            *normalBuf[2],
                            m_r,
                            m_g,
                            m_b);
            }
            else
            {
               *resultBuf[0] = 0;
               *resultBuf[1] = 0;
               *resultBuf[2] = 0;
            }
            resultBuf[0]++;
            resultBuf[1]++;
            resultBuf[2]++;
            normalBuf[0]++;
            normalBuf[1]++;
            normalBuf[2]++;
         }
      }
   }

   tile->validate();
   return true;
}