View Single Post
  #1   Spotlight this post!  
Unread 02-02-2012, 14:02
loafdog loafdog is offline
Registered User
AKA: Maciej
FRC #2876 (DevilBotz)
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2009
Location: Burlington, MA
Posts: 35
loafdog is an unknown quantity at this point
Getting BinaryImage write to work

Hi,

My team has tried using BinaryImage write() but could not get any files to appear in root dir on crio. I was playing with it a bit last night and eventually got images to appear. I have a few questions.
Given something like:
BinaryImage img = image.thresholdRGB(0, 40, 25, 255, 0, 40);

1- img.write("thresh.jpg"); did not work. img.write("/tmp/thresh.jpg"); did not work. img.write("/tmp/thresh.png") works. I did not try other file types. Not sure if writing a .png to / works or not... it was late and I was happy to get something working. Any ideas why using jpg does not work? Any reason writing to / may not work? I don't remember if I tried writing png to /. I am able to ftp the camera test sample jpg images to /. I did not try creating/writing to a text file yet.

2- the png image was either all black or had some red pixels/particles. We are using a green ring light. Our camera, RGB values, and filters need tuning but we should get something other than black/red. I looked in sunspotfrcsdk/lib/WPILibJ/src/edu/wpi/first/wpilibj/image/BinaryImage.java and found:
Code:
   public void write(String fileName) throws NIVisionException{
        Pointer colorTable = new Pointer(1024);
        //Black Background
        colorTable.setByte(0, (byte)0);   //B
        colorTable.setByte(1, (byte)0);   //G
        colorTable.setByte(2, (byte)0);   //R
        colorTable.setByte(3, (byte)0);     //Alpha
        //Red Particles:
        colorTable.setByte(4, (byte)0);     //B
        colorTable.setByte(5, (byte)0);     //G
        colorTable.setByte(6, (byte)255);   //R
        colorTable.setByte(7, (byte)0);     //Alpha
        try {
            NIVision.writeFile(image, fileName, colorTable);
        } finally {
            colorTable.free();
        }
    }
I changed two lines to:
Code:
        colorTable.setByte(5, (byte)255);     //G
        colorTable.setByte(6, (byte)0);   //R
After that saved images contained green pixels. I could see what thresholdRGB and convexHull and other filters were doing. Is this the right thing to do to get green images to appear? Seems like a hacky kind of way to make it work, but I'll take it for now.

-Maciej
Reply With Quote