Go to Post I didn't feel like reading this whole thread, which, as I understand, is talking about people not wanting to read long threads. - Mike [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 10-10-2012, 05:04 PM
Stonemotmot Stonemotmot is offline
Registered User
FRC #0486
 
Join Date: Sep 2011
Location: United States, Pa
Posts: 53
Stonemotmot is an unknown quantity at this point
Using thresholds on WPICameraExtension classes

Hello, This year my team is looking into utilizing camera tracking more than last year. We are using java and I understand the process used for on robot tracking already. Now I am looking into laptop based tracking. I already know how to create a WPI camera extension.

Using some code provided by team 237 I have made some progress. The biggest problem right now comes from thresholding. In there code they have

Code:
WPIBinaryImage red = image.getRedChannel().getThreshold(64),

                   green = image.getGreenChannel().getThreshold(64),
                   blue = image.getRedChannel().getThreshold(64);

    
    
    WPIBinaryImage threshold = red.getAnd(green).getAnd(blue);

I was under the impression Thresholds required a range of values. How is each channel only using one value?
A location for some sort of API documentation would also be appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 10-10-2012, 10:29 PM
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Using thresholds on WPICameraExtension classes

from WPIGrayscaleImage.java (from the WPIJavaCV project):
Code:
    /**
     * Returns a black and white image where every pixel that is higher (in the 0-255 scale) than the given threshold is <bold>white</bold>,
     * and everything below is <bold>black</bold>.
     * @param threshold a value 0-255. if a pixel has a value below the theshold, it becomes black
     * if the pixel value is above or equal to the threshold, the pixel becomes white
     * @return a new {@link WPIBinaryImage} that represents the threshold
     */
    public WPIBinaryImage getThreshold(int threshold) {
        validateDisposed();

        IplImage bin = IplImage.create(image.cvSize(), 8, 1);
        cvThreshold(image, bin, threshold, 255, CV_THRESH_BINARY);
        return new WPIBinaryImage(bin);
    }
It says that getThreshold() is black for [0,threshold) and white for [threshold, 255] - though, if you look at the OpenCV documentation for cvThreshold, it says that it's black for [0,threshold] and white for (threshold,255]. Either way, white is somewhere above, black is somewhere below.
The companion function getThresholdInverted() simply reverses the ranges, and if you compare getThreshold() and getThresholdInverted() from the same image with the same threshold, they should be perfect negatives.
Reply With Quote
  #3   Spotlight this post!  
Unread 10-11-2012, 02:32 PM
Stonemotmot Stonemotmot is offline
Registered User
FRC #0486
 
Join Date: Sep 2011
Location: United States, Pa
Posts: 53
Stonemotmot is an unknown quantity at this point
Re: Using thresholds on WPICameraExtension classes

Thanks for the info. i think I understand how the thresholds work. But I’m not clear on how to isolate a color. I can see using a combination of inverted and normal thresholds to do this. But in my testing I have had very little success. This is partly because im not sure how to combine them. team 237 used a variant of the code below but I don’t see much logic in how this executes.
There is also a .getOr() function which I might be able to use.
Code:
WPIBinaryImage threshold = red.getAnd(green).getAnd(blue);


on a side note where did you get that code snippet?
Reply With Quote
  #4   Spotlight this post!  
Unread 10-11-2012, 06:20 PM
Stonemotmot Stonemotmot is offline
Registered User
FRC #0486
 
Join Date: Sep 2011
Location: United States, Pa
Posts: 53
Stonemotmot is an unknown quantity at this point
Re: Using thresholds on WPICameraExtension classes

Ok I understand the thresholds now, but I'm still unsure how to isolate a color.
I can see how I might be able to utilize the getInverseThreshold() function but my testing has had little success.
This is compounded by the fact that I don't understand the threshold combination command seen below.
Code:
WPIBinaryImage threshold = red.getAnd(green).getAnd(blue);
There is also a getOr() function.
I don't fully understand how the implementation of these works.

on a side note where can I find the actual code for all these functions. If i had that it might be unnecessary for me to pose these questions.
Reply With Quote
  #5   Spotlight this post!  
Unread 10-12-2012, 09:27 PM
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Using thresholds on WPICameraExtension classes

All the functions you're asking about are in the WPIJavaCV project, which should be in the SmartDashboard repository (I see you found it in another thread). getAnd() applies a logical AND to each pixel in 2 binary images:
Code:
on  AND on  = on
on  AND off = off
off AND on  = off
off AND off = off
getOr() does the same thing but with an OR operation:
Code:
on  OR on  = on
on  OR off = on
off OR on  = on
off OR off = off
So to do a threshold of red between [100,150] and green outside [75,100], you'd do:
Code:
    WPIBinaryImage red = image.getRedChannel(),
                   green = image.getGreenChannel();
    WPIBinaryImage redThresh = red.getThreshold(100).getAnd(red.getThresholdInverted(150)),
                   greenThres = green.getThresholdInverted(75).getOr(green.getThreshold(100));
    
    WPIBinaryImage threshold = red.getAnd(green);
Reply With Quote
  #6   Spotlight this post!  
Unread 10-16-2012, 07:53 PM
Stonemotmot Stonemotmot is offline
Registered User
FRC #0486
 
Join Date: Sep 2011
Location: United States, Pa
Posts: 53
Stonemotmot is an unknown quantity at this point
Talking Re: Using thresholds on WPICameraExtension classes

Thanks for the info. Once I knew that getAnd and getOr worked just like the basic programming commands it all fell into place.
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:26 AM.

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