Jump to content

2 filtros de cor com AForge


Cronicle8

Recommended Posts

Objetivo, substituir a cara e as mãos na webcam por uma imagem, e como eu estou a fazer é a partir de filtros de cor (AForge), só que só consigo ter um filtro de cada vez.

private void cam_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
    {
	    Bitmap image = (Bitmap)eventArgs.Frame.Clone();
	    EuclideanColorFiltering filter = new EuclideanColorFiltering();
	    filter.CenterColor = new AForge.Imaging.RGB(colorDialog1.Color);
	    //Pure White 
	    filter.Radius = 100;
	    filter.FillOutside = true;
	    //Increase this to allow off-whites 
	    filter.ApplyInPlace(image);
	    //Cabeça
	    blobCounter.FilterBlobs = true;
	    blobCounter.ObjectsOrder = ObjectsOrder.Size;
	    blobCounter.ProcessImage(image);
	    Rectangle[] rects = blobCounter.GetObjectsRectangles();
	    Pen pen = new Pen(Color.Red, 1);
	    foreach (Rectangle recs in rects)
		    if (rects.Length > 0)
		    {
			    Graphics g = Graphics.FromImage(image);
			    g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\dog.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
			    //g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Hand.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
			    //g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Hand.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
			    g.Dispose();
		    }
	    pictureBox1.Image = image;
    }

Estou a fazer dessa maneira, será possivel usar dois filtros de cor, cada um com uma cor diferente, ou de outra maneira qulaquer?

Link to comment
Share on other sites

Nao estou pensando em algo mais no sentido de:

1) pegar a imagem, fazer uma cópia dela, temos então 2 imagens para trabalhar

2) aplicar um filtro numa imagem e outro filtro em outra.

3) mesclar o resultado em outra imagem (se este for seu objetivo). Ou daí trabalhar com as duas separadamente.

Fernando Lage Bastos - MCP/MCTS/MCPD

Link to comment
Share on other sites

Aqui está o código atualizado:

    private void cam_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
    {
	    Bitmap image1 = (Bitmap)eventArgs.Frame.Clone();
	    Bitmap image2 = (Bitmap)eventArgs.Frame.Clone();
	    EuclideanColorFiltering filter = new EuclideanColorFiltering();
	    EuclideanColorFiltering filter1 = new EuclideanColorFiltering();
	    filter.CenterColor = new AForge.Imaging.RGB(colorDialog1.Color);
	    filter1.CenterColor = new AForge.Imaging.RGB(Color.Yellow);
	    //Pure White 
	    filter.Radius = 100;
	    filter1.Radius = 100;
	    filter.FillOutside = true;
	    filter1.FillOutside = true;
	    //Increase this to allow off-whites 
	    filter.ApplyInPlace(image1);
	    filter1.ApplyInPlace(image2);
	    //Cabeça
	    blobCounter.FilterBlobs = true;
	    blobCounter.ObjectsOrder = ObjectsOrder.Size;
	    blobCounter.ProcessImage(image1);
	    Rectangle[] rects = blobCounter.GetObjectsRectangles();
	    Pen pen = new Pen(Color.Red, 1);
	    foreach (Rectangle recs in rects)
		    if (rects.Length > 0)
		    {
			    Graphics g = Graphics.FromImage(image1);
			    Graphics g2 = Graphics.FromImage(image2);
			    g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Platform Games\\dog.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
			    g2.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Hand.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
			    //g.DrawImage(Bitmap.FromFile("C:\\Documents and Settings\\NEXTV035\\Ambiente de trabalho\\Daniel\\Hand.png"), rects[0].Location.X, rects[0].Location.Y, rects[0].Width, rects[0].Height);
			    g.Dispose();
			    g2.Dispose();
		    }
	    pictureBox1.Image = image1;
	    pictureBox1.Image = image2;
    }

Eu sei que aa ultima linha de código anula a anterior, mas foi a unica maneira que eu consigo "juntar" as duas.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.