Go to Post I know FIRST is all about changing society. But my approach is one person at a time. - Phil 33 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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: 33
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
  #2   Spotlight this post!  
Unread 02-02-2012, 14:08
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Getting BinaryImage write to work

A binary image, has by definition two possible states for each pixel. What color you make the two states appear as really doesn't matter. If you want them to be black and green because you have a green ring light, go for it. If you want them to orange and purple because those are you favorite colors, you can make it do that instead.

Your method seems to be the correct way of having the "true" pixels output as green to me.
Reply With Quote
  #3   Spotlight this post!  
Unread 04-02-2012, 12:14
mryfrmr's Avatar
mryfrmr mryfrmr is offline
Registered User
AKA: Mary Farmer
FRC #0191 (XCATS)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: rochester
Posts: 7
mryfrmr is an unknown quantity at this point
We have found this morning that the write method on the binaryImage does not work with .jpg format, everything comes out black. We changed the format to .png and everything looked as we expected. So use .png format.
Reply With Quote
  #4   Spotlight this post!  
Unread 04-02-2012, 18:33
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,073
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Getting BinaryImage write to work

Quote:
Originally Posted by mryfrmr View Post
We have found this morning that the write method on the binaryImage does not work with .jpg format, everything comes out black. We changed the format to .png and everything looked as we expected. So use .png format.
Or .bmp or .tiff
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:49.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi