Exemple #1
0
PVideoFrame __stdcall ShapeMask::GetFrame(int n, IScriptEnvironment* env) {
	int colorspace;

	if (vi.IsRGB24())      colorspace = RGB24;
	else if (vi.IsRGB32()) colorspace = RGB32;
	else if (vi.IsYUY2())  colorspace = YUV2;
	else if (vi.IsYV12())  colorspace = YV12;
	else raiseError(env, "Unsupported color space, must be one of RGB24, RGB32, YUV2 or YV12");

	PClip srcClip = toGrayScale(env, child);
	PVideoFrame src = srcClip->GetFrame(n, env);
	PVideoFrame dst = env->NewVideoFrame(vi);

	const uchar* srcp = src->GetReadPtr();
	const int src_pitch = src->GetPitch();
	const int bpp = vi.BitsPerPixel();

	uchar* retp;

	// No change to the source pixels in the process steps, so ok to cast to non-const
	// returns a 1 channel gray scale image which needs to be converted to whatever format the source clip is in.
	retp = process_frame((uchar*)srcp, vi.width, vi.height, src_pitch, colorspace, threshold, minarea, rectonly);

	if (vi.IsPlanar()) copyPlanar(retp, dst, bpp);
	else if (vi.IsYUY2()) copyYUY2(retp, dst);
	else copyRGB(retp, dst, bpp);

	delete retp;
	return dst;
}
Exemple #2
0
void CSobel::sobel_function(String filename, String fileout)
{
	img = imread(filename, CV_LOAD_IMAGE_COLOR);
	if (!img.data)
		cout << "Could not open or find the image" << endl;
	else
	{
		vector<vector<double>> filter = createFilter(5, 5, 1);		
		grayscaled = Mat(toGrayScale());
		gFiltered = Mat(useFilter(grayscaled, filter));
		sFiltered = Mat(sobelFilter());		
		imwrite(fileout, sFiltered);
	}
}
Exemple #3
0
/**
* Converts the RGB Image to BlackAndWhite Scale.
*/
void JPGImage::toBlackAndWhiteScale(){

   setGrayScaleAvaliable(true);
   setBlackAndWhiteAvaliable(true);
   toGrayScale();

   for(int x = 0; x < getWidth(); x++){
      for(int y = 0; y < getHeight(); y++){
          Pixel *p = new Pixel(getPixel(x, y));
          p->toGrayScale();
          p->toBlackAndWhite();
          setPixel(x, y, p);
          delete(p);
      }
   }
}
Exemple #4
0
void StickyNoteActor::onThemeChanged()
{
	// reload all the necessary textures
	QDir texPath = winOS->GetUserThemesDirectory(true) / themeManager->getValueAsQString("textures.relativeRoot","");
	QDir iconRelPath = native(texPath / themeManager->getValueAsQString("textures.icon.relativeRoot","")).append('\\');
	QString iconCustomRelPath = native(iconRelPath / themeManager->getValueAsQString("textures.icon.custom.relativeRoot","")).append('\\');
	QString stickyNoteTexturePath = iconCustomRelPath + themeManager->getValueAsQString("textures.icon.custom.stickyNote","");
	if (exists(stickyNoteTexturePath))
	{
		qint64 filesize = QFileInfo(stickyNoteTexturePath).size();
		if (_stickyNoteBackgroundFileSize != filesize)
		{
			QImage tmp = _stickyNoteBackground = QImage(stickyNoteTexturePath);
			toGrayScale(_stickyNoteBackground, -120);
			_stickyNoteBackground = Blitz::blur(_stickyNoteBackground, 2);
			QPainter p;
				p.begin(&_stickyNoteBackground);
				p.drawImage(0, 0, tmp);
				p.end();
			_stickyNoteBackgroundFileSize = filesize;
		}
	}
}
Exemple #5
0
//this program tests the utils.c file with hardcoded values of my choice
int main(int argc, char **argv) {

  //degreesToRadians
  printf("degreesToRadians Function:\n");
  double number = 0, number2 = 0, number3 = 0;
  degreesToRadians(180, &number);
  degreesToRadians(90, &number2);
  degreesToRadians(0, &number3);
  printf("%f %f %f\n", number, number2, number3);
  printf("\n");
 
  //annualPercentageYield
  printf("annualPercentageYield:\n");
  double apy = 0, apy2 = 0, apy3 = 0;
  annualPercentageYield(.5, &apy);
  annualPercentageYield(.75, &apy2);
  annualPercentageYield(.25, &apy3);
  printf("%f %f %f\n", apy, apy2, apy3);
  printf("\n");

  //getAirDistance
  printf("getAirDistance:\n");
  double distance1 = 0, distance2 = 0, distance3 = 0;
  getAirDistance(40.8206, -96.7560, 41.8806, -87.6742, &distance1);
  getAirDistance(23, 63, 86, 124, &distance2);
  getAirDistance(64, 78, 23, 46, &distance3);
  printf("%f %f %f\n", distance1, distance2, distance3);
  printf("\n");

  //rgbToCMYK
  printf("rgbToCMYK:");
  double c = 0, m = 0, y = 0, k = 0;
    rgbToCMYK(23, 53, 34, &c, &m, &y, &k);
  	  printf("%f, %f, %f, %f\n", c, m, y, k);
    rgbToCMYK(40, 153, 89, &c, &m, &y, &k);
  	  printf("%f, %f, %f, %f\n", c, m, y, k);
    rgbToCMYK(232, 23, 145, &c, &m, &y, &k);
  	  printf("%f, %f, %f, %f\n", c, m, y, k);
  printf("\n");

  //cmykToRGB
  printf("cmykToRGB:\n");
  int r2 = 0, g2 = 0, b2 = 0;
  cmykToRGB(.2452, .2345, .3456, .6535, &r2, &g2, &b2);
  	  printf("%d %d %d\n", r2, g2, b2);
  cmykToRGB(.5234, .2452, .2345, .3456, &r2, &g2, &b2);
	  printf("%d %d %d\n", r2, g2, b2);
  cmykToRGB(.2412, .3456, .2452, .2345, &r2, &g2, &b2);
	  printf("%d %d %d\n", r2, g2, b2);
  printf("\n");

  //toGrayScale
  printf("toGrayScale:\n");
  int r=32, g=64, b=54;
  toGrayScale(&r, &g, &b, AVERAGE);
  printf("%d, %d, %d\n", r, g, b);
  r=64; g=74, b=123;
  toGrayScale(&r, &g, &b, LUMINOSITY);
  printf("%d, %d, %d\n", r, g, b);
  r=38; g=242, b=63;
  toGrayScale(&r, &g, &b, AVERAGE);
  printf("%d, %d, %d\n", r, g, b);
  printf("\n");



  return 0;
}
/**
 * @brief BallClasificationModule::blobOK
 * Utiliza el Metodo de Viola_Jones
 * @param blob: Region de interes
 * @return: true--> Blob clasifica como balon
 */
bool BallClasificationModule::blobOK(Blob *blob)
{
//    AppendToLog("Blob: " + QString::number(blob->id));
    int label = blob->component_label;
    int *labels = m_data->labelMatrix;

    if(label < 0 || labels == NULL)
        return true;

    Rectangle<int> &rect = blob->bbox;
    QImage *f = m_data->fgImage;
    uchar *pixels = f->bits();
    uchar *color_pixels = m_data->currentImage->bits();
    int color_bpl = m_data->currentImage->bytesPerLine();
    int x, y, x0 = rect.xleft, y0 = rect.ytop, w = f->width(),
        x1 = std::min(w - 1, x0 + rect.width), h=f->height(),
        y1 = std::min(f->height() - 1, y0 + rect.height),
        bpl = f->bytesPerLine();

    int N_pixel = 0, sum =0;
    int fg_pos;
    int color_pos;
    int B,G,R,I;

    for(y = y0; y <= y1; y++)
        for(x = x0; x <= x1; x++)
        {
            fg_pos = y*bpl + x;
            color_pos = y*color_bpl + 4*x;
            if(pixels[fg_pos] != 0 && labels[y*w + x] == label)
            {
                N_pixel++;
                B = color_pixels[color_pos+0];
                G = color_pixels[color_pos+1];
                R = color_pixels[color_pos+2];
                I = (B+G+R)/3;
                sum = sum + I;
            }
        }

    if(sum/N_pixel > 100)
    {
        int xc = (x0+x1)/2;
        int yc = (y0+y1)/2;

        int ancho = 40/2;
        //CASO BORDES
        if(xc-ancho<0)
            return true;
        if(xc+ancho>w)
            return true;
        if(yc-ancho<0)
            return true;
        if(yc+ancho>h)
            return true;

        QImage FImage = this->m_data->currentImage->copy(xc-ancho,yc-ancho,ancho*2,ancho*2);
        QString filename = "False" + QString("%4").arg(number_image);
        QImage gray = toGrayScale(&FImage);
//        qDebug() << gray.format();qDebug() << number_image << " is ball";
        VioJones Ball_dect("/home/dcardenasn/ViolaJones/ball_LBP_15x15.xml");
        if(gray.isNull())
            qDebug() << "No cago imagen en gris";
        else
            Ball_dect.set_image(gray);
        Ball_dect.detectAndDisplay();
//        if(Ball_dect.containobject())
//        {
//            qDebug() << number_image << " is ball";
//            return true;
//        }
//        else
//        {
//            qDebug() << number_image << " is NOT ball";
//            return false;
//        }
//        Ball_dect.showimage();
//        FImage.save("/home/dcardenasn/DATABASE/Ball Dataset/TEST/" + filename + ".png","PNG");
        number_image++;
//        for(y = y0; y <= y1; y++)
//            for(x = x0; x <= x1; x++)
//            {
//                fg_pos = y*bpl + x;
//                color_pos = y*color_bpl + 4*x;
//                if(pixels[fg_pos] != 0 && labels[y*w + x] == label)
//                {
//                    color_pixels[color_pos+0] = sum/N_pixel;
//                    color_pixels[color_pos+1] = sum/N_pixel;
//                    color_pixels[color_pos+2] = sum/N_pixel;
//                }
//            }
        return true;
    }
    return false;
}