Loading ...
Sorry, an error occurred while loading the content.

Java in Cygwin / Color detection

Expand Messages
  • isilondo
    One comment and a question, first, I noticed several posts back that some people were having problems with the ControllerGUI under Cygwin, specifically getting
    Message 1 of 5 , Feb 1 11:19 AM
    • 0 Attachment
      One comment and a question, first, I noticed several posts back that
      some people were having problems with the ControllerGUI under Cygwin,
      specifically getting a getting a class not found error. I was having
      the same problem but eventually found that adding the class path
      argument to the ControllerGUI script solved the problem. In my case
      the line

      java org.tekkotsu.mon.ControllerGUI $* &

      Becomes:

      java -Xmx256M -cp D:\\cygwin\\usr\\local\\Tekkotsu\\tools\\mon\\
      org.tekkotsu.mon.ControllerGUI $* &

      Similarly, calling the EasyTrain tool with:

      java -cp D:\\cygwin\\usr\\local\\Tekkotsu\\tools\\easytrain\\
      EasyTrain -isYUV $*

      Solves the error I was getting when trying to call that.

      ---------

      Second, I need to be able to detect what color background the AIBO's
      pink ball is appearing on. Detecting the dominant segmented color
      should be sufficient for my purposes but I am not sure where to start.
      Any suggestions would be extremely helpful.

      Thanks,
      Daniel C.
    • Ethan Tira-Thompson
      Thanks for the suggestion for ControllerGUI -- I m not sure why that isn t consistent between Cygwin installations... we definitely have machines where it
      Message 2 of 5 , Feb 1 12:10 PM
      • 0 Attachment
        Thanks for the suggestion for ControllerGUI -- I'm not sure why that isn't consistent between Cygwin installations... we definitely have machines where it works fine as is... might indicate some Java installations don't have the current directory (".") set in the default classpath...?  Anyway, should help those who run into this :)

        Second, I need to be able to detect what color background the AIBO's
        pink ball is appearing on. Detecting the dominant segmented color
        should be sufficient for my purposes but I am not sure where to start.
        Any suggestions would be extremely helpful.
        If you've set up your segmentation thresholds to recognize the color(s) in question, then you should be able to use the RegionGenerator to determine the largest region in the image for each color:
        #include "Shared/ProjectInterface.h"
        
        //long line: get the regions from the default region generator
        //have to cast it to the type actually returned by the generator in question (see documentation)
        RegionGenerator::region_stats * regions=(RegionGenerator::region_stats)ProjectInterface::defRegionGenerator->getImage(ProjectInterface::fullLayer,0);
        
        //do some processing on the regions
        for(unsigned int i=0; i<ProjectInterface::defSegmentedColorGenerator->getNumColors(); i++) {
            //region list is sorted by size, so first entry is the largest:
            cout << "largest region of color " << regions[i]->name << " is " << regions[i]->list->area << endl;
            //but you might prefer the total size of all regions of that color:
            cout << "total area for color " << regions[i]->name << " is " << regions[i]->total_area << endl;
        }
        
        Sorry if that doesn't quite compile, but it should give you the general idea.

        -ethan
      • isilondo
        Ethan, thanks a lot for the help. I modified the code you gave me slightly to the point that it compiles but I am getting output which isn t what I expected.
        Message 3 of 5 , Feb 3 5:05 PM
        • 0 Attachment
          Ethan, thanks a lot for the help. I modified the code you gave me
          slightly to the point that it compiles but I am getting output which
          isn't what I expected. Here is the code I am compiling in a very
          simple test behavior:

          #include "Shared/ProjectInterface.h"
          #include "Vision/RegionGenerator.h"
          #include "Vision/SegmentedColorGenerator.h"

          //long line: get the regions from the default region generator
          //have to cast it to the type actually returned by the generator in
          question (see documentation)
          RegionGenerator::region_stats * regions=(RegionGenerator::region_stats
          *)ProjectInterface::defRegionGenerator->getImage(ProjectInterface::fullLayer,0);

          cout << "The number of colors is: " <<
          ProjectInterface::defSegmentedColorGenerator->getNumColors() << endl;

          //do some processing on the regions
          for(unsigned int i=0;
          i<ProjectInterface::defSegmentedColorGenerator->getNumColors(); i++) {
          cout << "total area for color " << (regions[i]).name << " is " <<
          (regions[i]).total_area << endl;
          }


          Which produces the output:

          The number of colors is: 4
          total area for color ßHßTøÝäGñ<HñÜXñ\cñ@gñ¸kñ4mñDrññ|iÝß\jÝß<kÝñìkÝ
          ñ
          ñp
          ñLlÝÀñxñlÝÌlÝñöõÝT÷ßXߨõÝ is 22524

          Where the long string of characters is the same every time I run the
          test program after a given compile and doesn't change when the AIBO's
          view is changed. I've been looking at the documentation for
          RegionGenerator SegmentedColorGenerator and BallDetectionGenerator
          trying to figure out what I am missing but haven't figured out what I
          am missing yet. Is there something I need to call before getImage to
          get it to update/build the array before returning it? Also what should
          the color names be? "red" "blue" and "green" corresponding to my
          calibration file or something else? and what about the scale of the
          size returned. Many thanks again,

          Daniel T. C.



          --- In tekkotsu_dev@yahoogroups.com, Ethan Tira-Thompson <ejt@...> wrote:
          > If you've set up your segmentation thresholds to recognize the color(s)
          > in question, then you should be able to use the RegionGenerator to
          > determine the largest region in the image for each color:
          >
          > #*include* *"Shared/ProjectInterface.h"*
          >
          > ///long line: get the regions from the default region generator
          > ////have to cast it to the type actually returned by the generator
          in question (see documentation)
          > /RegionGenerator::region_stats *
          regions=(RegionGenerator::region_stats)ProjectInterface::defRegionGenerator->getImage(ProjectInterface::fullLayer,0);
          >
          > ///do some processing on the regions
          > /*for*(*unsigned* *int* i=0;
          i<ProjectInterface::defSegmentedColorGenerator->getNumColors(); i++) {
          > ///region list is sorted by size, so first entry is the largest:/
          > cout << *"largest region of color "* << regions[i]->name << *"
          is "* << regions[i]->list->area << endl;
          > ////but you might prefer the total size of all regions of that
          color://
          > cout << *"total area for color "* << regions[i]->name << *" is
          "* << regions[i]->total_area << endl;
          > }
          >
          > Sorry if that doesn't quite compile, but it should give you the general
          > idea.
          >
          > -ethan
          >
        • Daniel T. Casner
          Thanks, Dave and Ethan for the help. Putting the code inside an event and subscribing the visRegionEGID events did help. Now instead of getting random stuff I
          Message 4 of 5 , Feb 4 8:39 PM
          • 0 Attachment
            Thanks, Dave and Ethan for the help. Putting the code inside an event
            and subscribing the visRegionEGID events did help. Now instead of
            getting random stuff I am getting the following output:
            total area for color unclassified is 0
            total area for color blue is 0
            total area for color green is 0
            total area for color red is 0

            Which is a big improvement but I think I still must be doing something
            wrong, getting only the first frame produced and never subsequent ones
            perhapses? I tried installing version 2.5 (which I assume the is the
            version you meant) and after removing tools and sim from the make file
            (both of which generated errors, tools with a templated class and sim
            with the erouter) I got it to compile but I had the same problem so I
            resume that once again there is something I'm missing one again. Here's
            my code again:


            //-*-c++-*-
            #ifndef TEST_h_
            #define TEST_h_

            // This is an empty Behavior template file.
            // Replace YOURNAMEHERE, CLASSNAME, and DESCRIPTION as appropriate, and
            go to town!


            #include "Behaviors/BehaviorBase.h"
            #include "Shared/ProjectInterface.h"
            #include "Vision/RegionGenerator.h"
            #include "Vision/SegmentedColorGenerator.h"
            #include "Events/VisionObjectEvent.h"

            //! DESCRIPTION
            class TestBehavior : public BehaviorBase {
            public:
            TestBehavior() : BehaviorBase("TestBehavior"), looptimes(0) {}

            virtual void DoStart() {
            BehaviorBase::DoStart(); // do this first (required)
            std::cout << "Test behavior is starting" << std::endl;
            looptimes = 0;
            erouter->addListener(this,EventBase::visRegionEGID);
            // DoStop();
            }

            virtual void DoStop() {
            erouter->removeListener(this);
            BehaviorBase::DoStop();
            }

            virtual void processEvent(const EventBase& e) {
            if(looptimes++ < 10) {
            ProjectInterface::defRegionGenerator->freeCaches();
            //long line: get the regions from the default region generator
            //have to cast it to the type actually returned by the
            generator in question (see documentation)
            RegionGenerator::region_stats * regions=NULL;
            regions = (RegionGenerator::region_stats
            *)ProjectInterface::defRegionGenerator->getImage(ProjectInterface::fullLayer,0);

            //do some processing on the regions
            for(unsigned int i=0;
            i<ProjectInterface::defSegmentedColorGenerator->getNumColors(); i++) {
            cout << "total area for color " << (regions[i]).name <<
            " is " << (regions[i]).total_area << endl;
            }
            }
            }


            static std::string getClassDescription() { return "A simple scratch
            work test behavior"; }
            virtual std::string getDescription() const { return
            getClassDescription(); }


            protected:
            short looptimes;
            private:
            TestBehavior(const TestBehavior&); //!< don't call (copy constructor)
            TestBehavior& operator=(const TestBehavior&); //!< don't call
            (assignment operator)
            };

            #endif




            Ethan Tira-Thompson wrote:
            >> what you need to do is put your code inside processEvent and
            >> subscribe to visRegionEGID events.
            > Alternatively, at this point I'd almost say get a leg up on the next
            > release and run a 'cvs update -dPA' to get the bug fix(es) now. ;)
            > I'm still finishing up some stuff in the simulator, but it's stable as
            > long as you aren't using timers in the simulator or other features
            > which weren't in 2.4 anyway. Really trying to get it out ASAP!!!
            >
            > -ethan
            >
          • Ethan Tira-Thompson
            ... Aha, I stumbled over this today -- it turns out there s a function for calculating the total area, but nothing s calling it! So total_area forever stays
            Message 5 of 5 , Feb 7 11:50 AM
            • 0 Attachment
              Daniel T. Casner wrote:
              Thanks, Dave and Ethan for the help. Putting the code inside an event
              and subscribing the visRegionEGID events did help. Now instead of
              getting random stuff I am getting the following output:
                  total area for color unclassified is 0
                  total area for color blue is 0
                  total area for color green is 0
                  total area for color red is 0
              Aha, I stumbled over this today -- it turns out there's a function for calculating the total area, but nothing's calling it!  So total_area forever stays 0.

              If you want to use total area, you can either add your own call to CMVision::CalcTotalArea(...), or run through the region list and add them up yourself (which is all CalcTotalArea does anyway).
              Here's what CalcTotalArea does:
                http://www.cs.cmu.edu/~tekkotsu/dox/cmv__region_8h-source.html#l01034

              For future releases, I've already checked into CVS a call to this in RegionGenerator itself, and a configuration item to disable it in case anyone wants to save a little CPU since apparently no one is using it at the moment.

              Also, as for the code I originally sent, be sure to check regions[i].num is non-zero, and/or regions[i].list is non-NULL before trying to access the first (largest) item -- can't assume there is necessarily something of that color in view... the region list could be empty.

              So, to put it all together, this time I've actually written a test behavior and also checked it in:
              http://cvs.tekkotsu.org/cgi/viewcvs.cgi/Tekkotsu/Behaviors/Demos/RegionTestBehavior.h?rev=1.1&content-type=text/vnd.viewcvs-markup

              For quick reference, the core code is included below.

              -ethan
              #include "Shared/ProjectInterface.h"
              #include "Vision/RegionGenerator.h"
              #include "Vision/SegmentedColorGenerator.h"
              
              //long line: get the regions from the default region generator
              //have to cast it to the type actually returned by the generator in question (see documentation)
              RegionGenerator::region_stats * regions=(RegionGenerator::region_stats*)ProjectInterface::defRegionGenerator->getImage(ProjectInterface::fullLayer,0);
              
              unsigned int num_colors=ProjectInterface::defSegmentedColorGenerator->getNumColors();
              
              //do some processing on the regions
              for(unsigned int i=0; i<num_colors; i++) {
              
                  std::cout << "There are " << regions[i].num << " " << regions[i].name << " regions:" << std::endl;
                  
                  //Won't be necessary after next release or if you do a CVS update
                  CMVision::CalcTotalArea(regions,num_colors); 
                  
                  if(regions[i].num>0 && regions[i].list!=NULL) { //really only need to check one
                      //region list is sorted by size, so first entry (if list isn't empty) is the largest:
                      std::cout << "\tlargest region has area " << regions[i].list->area << std::endl;
                      //but you might prefer the total size of all regions of that color:
                      std::cout << "\ttotal area is " << regions[i].total_area << std::endl;
                  }
              }
              

            Your message has been successfully submitted and would be delivered to recipients shortly.