Go to Post FIRST is not about building a robot, it's about the experience of it all... - Beth Sweet [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 28-01-2012, 09:24
dominique dominique is offline
Registered User
FTC #0211 (MK211)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Rochester,NY
Posts: 9
dominique is an unknown quantity at this point
Standalone image analysis.

Hello,

I am stuck at home without the possibility to connect to a cRio but I would like to help my team in the image processing part. How can I use the java vision library to process a local image (on my c drive) ?

I have modified the CameraTest project but when I execute "new RGBImage (filename)" then Netbeans wants to connect to the cRio and program fails.

Any clue to help me to work stand alone ? Thanks.
Reply With Quote
  #2   Spotlight this post!  
Unread 03-02-2012, 11:37
dominique dominique is offline
Registered User
FTC #0211 (MK211)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Rochester,NY
Posts: 9
dominique is an unknown quantity at this point
Re: Standalone image analysis.

Ok - I will reply to myself as it may help others.
1- I downloaded and installed smartDashboard on my laptop (has a built-in camera).
2- In Netbeans, I created the following (from New Project but no Main Class - in other words it is a class - bot a package).
Quote:
import edu.wpi.first.smartdashboard.camera.WPICameraExten sion;
import edu.wpi.first.wpijavacv.WPIColorImage;
import edu.wpi.first.wpijavacv.WPIImage;

public class BasicCameraExtension extends WPICameraExtension {
@Override
public WPIImage processImage(WPIColorImage rawImage) {
return rawImage.getRedChannel();
}
}
3- Right click on project - select properties and add the following jar to the libraries (Compile):
Quote:
C:\Program Files\SmartDashboard\extension\WPICameraExtension. jar
C:\Program Files\SmartDashboard\SmartDashboard.jar
C:\Program Files\SmartDashboard\extension\WPICameraExtension. jar
This should solve the problems with the imports.

4- Right click on the project and select BUILD
5- Copy the resulting jar file from folder NetBeansProjects\projectname\dist
to folder C:\Program Files\SmartDashboard\extensions (next to WPICameraExtension.jar)
6- Double click on C:\Program Files\SmartDashboard\SmartDashboard.jar, the smartdashboard should launch. Click on View\Add and select the class name of your program : BasicCameraExtension in this example.

You should see the red channel of the image taken by the laptop camera since this is what is returned.

Now...from this how to do image analysis is another story...

Last edited by dominique : 03-02-2012 at 13:24.
Reply With Quote
  #3   Spotlight this post!  
Unread 04-02-2012, 20:20
FourPenguins's Avatar
FourPenguins FourPenguins is offline
Back in the Game
AKA: Ed Venator
FRC #2399
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 2005
Location: Mount Olive, NJ
Posts: 261
FourPenguins has much to be proud ofFourPenguins has much to be proud ofFourPenguins has much to be proud ofFourPenguins has much to be proud ofFourPenguins has much to be proud ofFourPenguins has much to be proud ofFourPenguins has much to be proud ofFourPenguins has much to be proud ofFourPenguins has much to be proud ofFourPenguins has much to be proud of
Re: Standalone image analysis.

You can either work with OpenCV directly (using the Java interface that WPI has supplied), or you can use the WPIImage object's method's to do a lot of basic image processing.
Someone named Greg Granito wrote this code that my team has been riffing off of.
__________________
MORT 11
-2005 New Jersey Regional Chairman's Award Winner
-2006 Palmetto Regional Winner
-2007 New York Regional Delphi Driving Tomorrow's Technology Award
-2008 New Jersey Regional Finalist, Chesapeake Regional Winner, Championship Event Overall Top Seed
HB 2399
-2009 Buckeye Regional Delphi Driving Tomorrow's Technology Award, Pittsburgh Regional GM Industrial Design Award
Reply With Quote
  #4   Spotlight this post!  
Unread 05-02-2012, 01:02
PaulDavis1968's Avatar
PaulDavis1968 PaulDavis1968 is offline
Embedded Software/Systems Engineer
AKA: Master of Complexity
FRC #2053 (TigerTronics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Endicot NY
Posts: 91
PaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nice
Re: Standalone image analysis.

Quote:
Originally Posted by FourPenguins View Post
You can either work with OpenCV directly (using the Java interface that WPI has supplied), or you can use the WPIImage object's method's to do a lot of basic image processing.
Someone named Greg Granito wrote this code that my team has been riffing off of.
Awesome. I spent 2 days getting detection to work in openCV (the c++ version) and then I see this ... Doh. This will help get me the rest of the way home though.


Thanks,

Paul
Reply With Quote
  #5   Spotlight this post!  
Unread 05-02-2012, 09:33
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 102
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Standalone image analysis.

We are trying to use the WPIBinaryImage class as well for finding contour lines. It seems to work well. However, we are struggling to use it continuously.

To us it appears that there is a huge native memory leak (something inside the native code) when the findContours() method actually finds contour lines.

Could you tell me whether or not your code includes a line like the following (where findBin is instance of a WPIBinaryImage)?

Code:
WPIContour[] contours = finalBin.findContours();
If so, do you see your process start to consume vast amounts of memory when continuously processing images from the camera (looking at its status using the Windows Task Manager)?

We've found that we can process a few images without issues, but if we try to run continuously (processing hundreds of frames), our process hits 1 GB of RAM usage and quickly continues to grow until memory is exhausted.

We don't seem to hit the memory issue if we don't use the findContours() method, or if the findContours() method doesn't locate anything (memory usage only appears to explode when contours are found).

In any case, I'd be curious to know if you've run across this issue as well and if so how you worked around it.

Here's our "do nothing" minimal vision processing code which demonstrates the memory leak using only the WPI classes and methods:

Code:
package com.techhounds.camera;
import edu.wpi.first.smartdashboard.camera.WPICameraExtension;
import edu.wpi.first.wpijavacv.WPIBinaryImage;
import edu.wpi.first.wpijavacv.WPIColorImage;
import edu.wpi.first.wpijavacv.WPIContour;
import edu.wpi.first.wpijavacv.WPIGrayscaleImage;
import edu.wpi.first.wpijavacv.WPIImage;

/**
 * A "trivial" SmartDashboard camera extension demonstrating the memory
 * leak issue in the
 *
 * @author pkb
 */
public class MemoryLeakExtension extends WPICameraExtension {

    @Override
    public WPIImage processImage(WPIColorImage colorImg) {

        // Pull out one color
        WPIGrayscaleImage grayImg = colorImg.getBlueChannel();

        // Reduce to black and white for contour tracing
        WPIBinaryImage binImg = grayImg.getThreshold(200);

        // Find the contours within the image (unfortunately memory
        // is leaked big time as soon as it starts finding contours)
        WPIContour[] contours = binImg.findContours();

        // Let the dash board display the gray image
        return grayImg;
    }

}
Thanks,
Paul
Reply With Quote
  #6   Spotlight this post!  
Unread 05-02-2012, 10:57
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 102
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Standalone image analysis.

It looks like the WPI guys are working on the memory leak in the WPIJavaCV.jar file (there were some commits yesterday - revision 213).

I was successful in downloading the latest source from the SmartDashboard project and rebuilding the WPIJavaCV.jar file. Things are running much better now. I've been able to process the same image over 250000 times using the WPI methods without running out of memory (which is a lot more than we'll ever hope to get through in a single match).

In case anyone else is hitting this issue and wants to try an updated build of the WPIJavaCV.jar file I've attached a zip file containing what I'm currently running with. To use:

1. Download the ZIP file
2. Extract the WPIJavaCV.jar file from the ZIP file
3. Rename your existing WPIJavaCV.jar file (in the SmartDashboard/extensions/lib directory).
4. Copy the new WPIJavaCV.jar file into your SmarDashboard/extensions/lib/ directory (folder).
Attached Files
File Type: zip WPIJavaCV-20120205.zip (12.8 KB, 201 views)
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 07:09.

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