Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   general image tracking commands (http://www.chiefdelphi.com/forums/showthread.php?t=102975)

Method 16-02-2012 04:21

general image tracking commands
 
Hello- simple playing around with wrappers
I have two errors highlighted in red and would appreciate a nudge in the right direction(they're different instances of the same error).

Also, I'd love some more simple commands examples like this: particularly the one which uses a particle filter to add or remove particles based on %Area/(Particle & Holes' Area) which is in the NI Vision Assistant.

One last:There are many references to reading and writing image files. Is this only necessary in Java or when making an example which uses pictures from the a folder, e.g., 'vision images' in the project?

Thankyou for any help!

Code:

#include "WPILib.h"
#include "Vision/RGBImage.h"
#include "Vision/BinaryImage.h"

#define RL 200
#define RH 260
#define GL 140
#define GH 210
#define BL 90
#define BH 135

#define BS 1.0f
#define CT 1.0f
#define GA 1.0f

static AxisCamera &eyeOfSauron = AxisCamera::GetInstance("255.255.255.255");
DriverStationLCD* driverOut = DriverStationLCD::GetInstance();

class VisionSample2012 : public SimpleRobot
{
DriverStationLCD* driverOut;
Joystick pilot;
public:
        VisionSample2012(void):
                pilot(1)
        {
                GetWatchdog().Kill();
                driverOut  = DriverStationLCD::GetInstance();
               
                eyeOfSauron.WriteBrightness(30);
                eyeOfSauron.WriteWhiteBalance(AxisCamera::kWhiteBalance_Hold);
                eyeOfSauron.WriteResolution(AxisCamera::kResolution_320x240);
                eyeOfSauron.WriteColorLevel(100);
                eyeOfSauron.WriteCompression(30);
                eyeOfSauron.WriteMaxFPS(5);
                //lower easier on CRIO and harder on cam
        }
       
        void Autonomous(void)
        {
                GetWatchdog().Kill();               
                while (IsAutonomous() && IsEnabled())
                {
                        GetWatchdog().Kill();
                        CamAnOut();
                }
        }
        void OperatorControl(void)
        {
                GetWatchdog().Kill();
                while (IsOperatorControl() && IsEnabled())
                {
                        GetWatchdog().Kill();
                        CamAnOut();
                }
        }
        void CamAnOut (void)
        {
//used to remove red, green or blue particles out of range
                Threshold threshold(RL, RH, GL, GH, BL, BH);

//used to remove particles out of criteria
                ParticleFilterCriteria2 criteria[] = {
                                                                                        {IMAQ_MT_BOUNDING_RECT_WIDTH, 10, 200, false, false},
                                                                                        {IMAQ_MT_BOUNDING_RECT_HEIGHT, 10, 200, false, false}};
                               
                ColorImage image(IMAQ_IMAGE_RGB);
                //make image
               

                if (eyeOfSauron.IsFreshImage())//if latest from cam not recieved
                {
                        eyeOfSauron.GetImage(&image);
                        //store camera feed to image
                        //out new im # ()  ---  add a big number to it

                }
                else
                {
                        //out old im  ---  sub a small number from it
                        //play till refreshes at 0 for awesomeness XD

                       


                        /*        AxisCamera::GetImage returns ColorImage* ... (or HSLImage* due to inheritance)
                                ColorImage::ThresholdHSL returns BinaryImage*
                                BinaryImage:: has the particle analysis routines
                        */       

                       
                       
//changes brightness, contrast and gamma
                        Image* BCG = image.GetImaqImage();
                        delete ℑ
                        BCGOptions bcg;
                        bcg.brightness = BS;
                        bcg.contrast = CT;
                        bcg.gamma = GA;
                        imaqBCGTransform(BCG, BCG, &bcg, NULL);
                       
                        HSLImage *thresholdLUM = BCG->ThresholdHSL(1,2,1,2,1,2);
//would remove out of range HSL particles
                        delete &BCG;

//separates luminance
                        MonoImage* luminance = thresholdLUM->GetLuminancePlane();
                        delete thresholdLUM;
                        imaqDispose(BCG);
                        image.ReplaceRedPlane(luminance);
                        image.ReplaceGreenPlane(luminance);
                        image.ReplaceBluePlane(luminance);
                       
//not with HSL image and threshold-removes out of range RGB        BinaryImage *thresholdImage = BCG->ThresholdRGB(threshold);
                        //pixel range       
       

//change img type
                        BinaryImage *binImg = luminance;
                                delete luminance;
//complete particles
                        imaqConvexHull(binImg->GetImaqImage(),binImg->GetImaqImage(),1);
       
                        BinaryImage *bigObjectsImage = binImg->RemoveSmallObjects(false, 2);
                        // remove small objects (noise)
                        delete binImg;
                       
                        BinaryImage *convexHullImage = bigObjectsImage->ConvexHull(false);
                        // fill in partial and full rectangles
                        delete bigObjectsImage;

                       
                        BinaryImage *filteredImage = convexHullImage->ParticleFilter(criteria, 2);
                        // find the rectangles by above cruteria
                        delete convexHullImage;
                       
                        vector<ParticleAnalysisReport> *particles = filteredImage->GetOrderedParticleAnalysisReports();
                        // get the results
                        delete filteredImage;
                       
                       
                        ParticleAnalysisReport *high = &(particles)->at(1);
                        ParticleAnalysisReport *particle = &(particles)->at(2);
                        for (unsigned int i = 1; i <= particles->size(); i++)
                        {
                                particle = &(particles)->at(i);
                                                       
                                //target select
                                if(particle->center_mass_y_normalized > high->center_mass_y_normalized)
                                {
                                        high = &(particles)->at(i);
                                }
                                delete particle;
                        }
                       
                        //LCD output
                        driverOut->UpdateLCD();
                       
        //                        delete reports;
                       
                        delete particles;
                        delete high;
                       
                }
               
        }
};

START_ROBOT_CLASS(VisionSample2012);


frdrake 16-02-2012 17:11

Re: general image tracking commands
 
I had a problem with my BinaryImage file because they released a new update for WindRiver on Feb. 4 with additional functions in this class. Have you already gotten that update?

Method 16-02-2012 20:53

Re: general image tracking commands
 
yes, i have, but my main point of interest is how to do the %Area/(Particle & Holes' Area) criteria

Method 16-02-2012 21:33

Re: general image tracking commands
 
bool AxisCamera::IsFreshImage ( )
Return true if the latest image from the camera has not been retrieved by calling GetImage() yet.

Returns:
true if the image has not been retrieved yet.


Im having trouble believing this.. can someone confirm?

mikets 17-02-2012 01:59

Re: general image tracking commands
 
Yes, according to the source code of the WPILib, IsFreshImage() returns the member variable m_freshImage. This variable is set by the UpdatePublicImageFromCamera() function in the camera task and cleared when you call GetImage(). So yes, once an image is available, as long as you haven't retrieved it by calling GetImage, it will remain "fresh".

Method 17-02-2012 02:10

Re: general image tracking commands
 
Thankyou! XD

mikets 17-02-2012 02:21

Re: general image tracking commands
 
Quote:

Originally Posted by mikets (Post 1128586)
Yes, according to the source code of the WPILib, IsFreshImage() returns the member variable m_freshImage. This variable is set by the UpdatePublicImageFromCamera() function in the camera task and cleared when you call GetImage(). So yes, once an image is available, as long as you haven't retrieved it by calling GetImage, it will remain "fresh".

BTW, it is possible that you haven't retrieved the image yet but another image is available so it will update the image with the new one. In other words, you don't have to worry about the image being stale.


All times are GMT -5. The time now is 17:41.

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