Image processing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hunerajamshed
    New Member
    • Jul 2010
    • 3

    #1

    Image processing

    hi all there.

    im new in BYTES, this is my first post.
    i m working on a project regarding image processing. i m working on face detection from video. i hv played the video captured from webcam on a picture box.I hv splitted it into frames it plays like original(means no problem) but as i attach or call some algorithm with it bofore display it becomes slower and plays like slow motion. What could b the problem.

    thanks in advance.
    hony,
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I would say your algorithm code is slowing it down.
    It may be worth seeing if it can be optimised, otherwise multi-threading may be the answer

    Comment

    • hunerajamshed
      New Member
      • Jul 2010
      • 3

      #3
      That could be a problem, but i dont think that the algorithm is such a complex anyhow, here is the algorithm which applies on each frame of video.


      Code:
      static ArrayList points = new ArrayList();
              static Int32 xx = 0, yy = 0;
              static int clrdpix;
              static int rect_width = clrdpix;
              static int clr_line_count = 0;
              
              public static Bitmap DetectSkin(Bitmap original, Bitmap modified)
              {
                  Graphics g = Graphics.FromImage(original);
                  clr_line_count = 0;     //Skin Colored Lines Count
                  int strtpix = 0;        //Pixel from where rectangle begain to draw.
      
                  for (Int32 y = 0; y < original.Height; y++)
                  {
                      clrdpix = 0;
      
                      for (Int32 x = 0; x < original.Width; x++)
                      {
                          Color c = modified.GetPixel(x, y);
      
                          double I = (Math.Log(c.R) + Math.Log(c.B) + Math.Log(c.G)) / 3;
                          double Rg = Math.Log(c.R) - Math.Log(c.G);
                          double By = Math.Log(c.B) - (Math.Log(c.G) + Math.Log(c.R)) / 2;
                          double hue = Math.Atan2(Rg, By) * (180 / Math.PI);
      
                          if (I <= 6 && (hue >= 100 && hue <= 255))
                          {
                              clrdpix++;
                          
                              if (clr_line_count == 50 && clrdpix == 1)
                              {
                                  strtpix = x;
                              }              
                           }
                          
                          else
                          {
                              //modified.SetPixel(x, y, Color.Black);
                          }
                          
                          
                      }
                      if (clr_line_count == 50)
                      {
                          xx = strtpix;
                          yy = y;
                          rect_width = original.Width - (original.Width - clrdpix) - 20;
                          //Console.WriteLine("Colored Pixel Value =" + clrdpix);
                          //Console.WriteLine("xx Value =" + strtpix);
                          //Console.WriteLine("yy Value =" + yy);
                      }
                      if(clrdpix>0)
                      clr_line_count++;
                  }
      
                  return modified;
              }

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        There may be howls of derision but I would improve this
        Code:
        for (Int32 x = 0; x < original.Width; x++)
        By storing Width in a variable to avoid multiple class calls
        Code:
        w = original.Width;
        for (Int32 x = 0; x < w; x++)
        Same for height.

        Comment

        • hunerajamshed
          New Member
          • Jul 2010
          • 3

          #5
          Thanks alot dear;
          i got u.
          but i m waiting for ur reply with more mistakes u caught from this code.

          thanks again

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            If somebody on this forum suggested code optimization to me,
            I would eagerley rush off and study the subject.
            I would not lie back and expect an expert to optimise the code for me

            Comment

            Working...