Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Green Screen

  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Green Screen

    I have an assignment in my computer science class to write a code for a green screen (taking a picture in front of a green screen and changing the pixels that are green to a different picture)
    Heres the code I have now and I keep getting a few errors, any help would be greatly appreciated!

    Code:
    import java.awt.color;
     
    public class GreenScreen
    {
      
      public static void main (String[] args) 
      {
        // open the first picture
        String filename = FileChooser.pickAFile ();
        Picture p = new Picture (filename);
        
        // open the second picture
        String filename2 = FileChooser.pickAFile ();
        Picture p2 = new Picture (filename2);
        
    
      } 
    
        int xPos;
        int yPos;
        int yStart;
        int yEnd;
        int temp;
        Pixel pix1;
        Pixel pix2; 
        Pixel pix3;
        Pixel fromPix;
        Pixel toPix;
        int red;
        int green;
        int blue;
        Color c1 = new Color (18, 155, 51);
        
        for ( xPos = 0 ; xPos < width2 ; ++xPos )
        {
          
          for ( yPos = 0 ; yPos < height2 ; ++yPos )
          { 
            if ( xPos >= width1 || yPos >= height1 )
            {
              fromPix = p2.getPixel (xPos, yPos);
            }
            else
            {
              //  access the pixel to be modifed
              pix1 = p1.getPixel (xPos, yPos);
              if ( Pixel.colorDistance (c1, pix1.getColor()) < 10)
              {
                fromPix = p2.getPixel (xPos, yPos);
              }
              else
              {
                fromPix = p1.getPixel (xPos, yPos);
              }
            } 
            
            toPix = resultPicture.getPixel (xPos, yPos);
            
            red = fromPix.getRed();
            green = fromPix.getGreen();
            blue = fromPix.getBlue();
            
    
            toPix.setRed(red);
            toPix.setGreen(green);
            toPix.setBlue(blue);
          }
        }
        
        return resultPicture;
      }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The only immediate problem I can identify is you are missing a method declaration.
    All of this stuff here:
    PHP Code:
        int xPos;
        
    int yPos;
        
    int yStart;
        
    int yEnd;
        
    int temp;
        
    Pixel pix1;
        
    Pixel pix2
        
    Pixel pix3;
        
    Pixel fromPix;
        
    Pixel toPix;
        
    int red;
        
    int green;
        
    int blue;
        
    Color c1 = new Color (1815551);
        
        for ( 
    xPos xPos width2 ; ++xPos )
        {
          
          for ( 
    yPos yPos height2 ; ++yPos )
          { 
            if ( 
    xPos >= width1 || yPos >= height1 )
            {
              
    fromPix p2.getPixel (xPosyPos);
            }
            else
            {
              
    //  access the pixel to be modifed
              
    pix1 p1.getPixel (xPosyPos);
              if ( 
    Pixel.colorDistance (c1pix1.getColor()) < 10)
              {
                
    fromPix p2.getPixel (xPosyPos);
              }
              else
              {
                
    fromPix p1.getPixel (xPosyPos);
              }
            } 
            
            
    toPix resultPicture.getPixel (xPosyPos);
            
            
    red fromPix.getRed();
            
    green fromPix.getGreen();
            
    blue fromPix.getBlue();
            

            
    toPix.setRed(red);
            
    toPix.setGreen(green);
            
    toPix.setBlue(blue);
          }
        }
        
        return 
    resultPicture
    Is currently sitting in the class level definition. The return indicates it should be in a method somewhere.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •