-1

I am making an windows form application in which i am overlaying an image during a webcam stream from the laptop. the overlayed image is showing absurd colours. it is showing alot of pink colour. is there anything i can do to make the overlayed image look properly. i am using the camera_Net Library to connect to the webcam suggestions for overlaying an image during during a webcam video shall also be appreciated.

here is my code to draw the image

string filepath = @"E:\office\lux desktop app\Camera_Net-master\Camera_Net-master\Samples\CameraControlTool\water_PNG3290.png";
                    Bitmap bitmap1 = new Bitmap(filepath);
                    g.DrawImage(bitmap1, new Rectangle(400 , 0, 250, 600));

here is the look of the image during webcam stream  .

and here is the orignal image being overlayed .

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3094279
  • 39
  • 2
  • 10
  • why the two images' shapes differs a lot? – Lei Yang Jul 06 '17 at 06:22
  • because i have given the overlayed image cordinates so it comes within the rectangle range i.e. new Rectangle(400 , 0, 250, 600) – user3094279 Jul 06 '17 at 06:24
  • 1
    is `g` already showing a live camera content? – Lei Yang Jul 06 '17 at 06:26
  • g is the object of the graphics library in c# – user3094279 Jul 06 '17 at 06:28
  • i mean i'm afraid you cannot just simply put a image upon another video? – Lei Yang Jul 06 '17 at 06:30
  • the library itself says it can be used to overlay an frame into a video.. github link https://github.com/free5lot/Camera_Net is there any color correction properties in the bitmap that i can use to solve this issue? – user3094279 Jul 06 '17 at 06:35
  • Here goes the long shot: your `g` is receiving data in wrong format. `g.DrawImage` paints correctly on incorrect background. Then you detach `g` and the data is reinterpreted back to supposed format but correctly paint overlay is reinterpreted in an unexpected way. That is, the way you get your `g` is wrong. – Roman R. Jul 06 '17 at 09:25

2 Answers2

0

I think the problem is the image itself. It's an .png image, so I it has the possibility of an alpha-value. The white in the back is cropped out but in between the water, the light blue values are pink.

I would first try to use an easier image. Something like this. I think this will work just fine. Then search for some more complex images and try to find the weak-spot and find some alternative options to bring the image in to the cam.

  • is there anyway i can tweek something with the alpha value ? to make it look the way it is ? – user3094279 Jul 06 '17 at 07:38
  • yes to some extent ..but i tried many other different png images but they tend to be not working. they all are having pink color at their edges – user3094279 Jul 06 '17 at 07:57
0

As @Roman R pointed out that g point correctly to an incorrect background, the problem was indeed with color format, so the solution is to use the correct image pixelformat based on your image.

here is the complete code

Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppRgb);

            Graphics g = Graphics.FromImage(bmp);
            Image newImage;

                newImage = Properties.Resources.red_frame_03;
using (Bitmap oldBmp = new Bitmap(newImage))
            using (Bitmap newBmp = new Bitmap(oldBmp))
            using (Bitmap targetBmp = newBmp.Clone(new Rectangle(0, 0, newBmp.Width, newBmp.Height), PixelFormat.Format16bppArgb1555))

            {
                g.DrawImage(targetBmp, new Rectangle(100, 0, 350, 350));


            }
user3094279
  • 39
  • 2
  • 10