Log in

View Full Version : How to view a binary image


Gmercer
03-02-2013, 13:49
I'm working on refining my auto aim code and noticed a couple bugs when the robot is looking from a certain angle. Is there a way i can save the binary image to the robot in a format maybe MS paint could open so i could view the image and check to make sure my code it right? Here is what i have for my camera function:

public void cameraCapture() throws AxisCameraException, NIVisionException {
if (joy2.getRawButton(3)) {
//Color Image will be our MAIN image, Binary image will be the manipulated data
ColorImage initImg;
BinaryImage dataImg;
//array of particles to pass into aim function, plus the target count of particles
ParticleAnalysisReport[] particle;
int trgCnt;
SmartDashboard.putString("Taken Picture", "Picture begun...");
//if camera is 'fresh'
if (camera.freshImage()) {
//grab an image, set binaryImg to it and start manipulating the image
initImg = camera.getImage();
dataImg = initImg.thresholdRGB(0, 144, 153, 243, 34, 167); //set threshold to bright colors(UNFINISHED)
dataImg = dataImg.removeSmallObjects(false, 1); //remove small pixles from image
dataImg = dataImg.convexHull(false); //fill in rectangles selected
dataImg = dataImg.particleFilter(critCollection); //filter rectangles
trgCnt = dataImg.getNumberParticles();
//if there are any particles, aim at them
if (trgCnt > 0) {
//assign particle array of values
particle = dataImg.getOrderedParticleAnalysisReports();
SmartDashboard.putString("Taken Picture", "binary mapping finished....calling Aim");
Aim(particle);
} else {
SmartDashboard.putString("Taken Picture", "No particles to manipulate, picture was not taken?");
}
//free images used
dataImg.free();
initImg.free();
}
}
}

Criteria collection params:

critCollection.addCriteria(MeasurementType.IMAQ_MT _BOUNDING_RECT_WIDTH, 30, 400, false);
critCollection.addCriteria(MeasurementType.IMAQ_MT _BOUNDING_RECT_HEIGHT, 20, 400, false);

joelg236
03-02-2013, 16:53
Just as a guess, you could use ObjectMemorySerializer.save() to save a serialized image to the CRIO's memory, then FTP to get it and find a way to convert it from a desktop setting. I'm sure you aren't talking about converting it onboard the computer right? You wouldn't be opening ms paint during competition. :p As to how to convert it, you could use a java library that allows you to construct jpeg/bmp/png/gif/etc using pure data and use the wpilibj.jar to access the serialized object you saved. Probably a complex answer, but I've never done it so I don't know a better way.

RufflesRidge
03-02-2013, 18:54
It's way easier than what Joel suggested. Just call ImageName.write(/ImageName.bmp) then FTP to the cRIO (no client needed, jut type FTP://10.XX.YY.2 in Windows Explorer) to get the image. Replace ImageName with the name of your image and you should be good to go. Note that .jpeg does not appear to work with binary images, but .bmp does.

joelg236
03-02-2013, 23:20
It's way easier than what Joel suggested. Just call ImageName.write(/ImageName.bmp) then FTP to the cRIO (no client needed, jut type FTP://10.XX.YY.2 in Windows Explorer) to get the image. Replace ImageName with the name of your image and you should be good to go. Note that .jpeg does not appear to work with binary images, but .bmp does.

Go with this. I've never touched image manipulation stuff in the wpilibj/squawk libraires so I didn't know where to look.