View Single Post
  #3   Spotlight this post!  
Unread 20-02-2012, 17:46
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Camera Tracking Delay

Quote:
Originally Posted by Stonemotmot View Post
Hello, My team has finally gotten camera targeting to work in c++. The only issue is there is about a 3-5 sec wait between when the function is called and when it actually begins to auto correct to the target. My code is full of "printf" commands and I was wondering if this could cause the delay by using up more resources or is 3-5 sec the best speeds we are going to get. I dont have the code on me to post sry.
When we started playing with the Vision code, we got a long delay too. There are several factors:
1. Make sure your camera resolution is 320x240. If you had it 640x480, it will take a long time to process the image. At first, we thought we had it set at 320x240 because we have the line m_camera.WriteResolution(AxisCamera::kResolution_3 20x240). But for some reason, we had to go to the web interface of the camera to force it to 320x240 before the performance started to improve.
2. Make sure you filter the image correctly. For example, if your light source is red, make sure your color thresholds are towards red. If not, you may end up with lots of false positive targets that require a long time to process.

In order to diagnose performance issues, it may be helpful to add timing code to check who takes a long time. For example, this is an excerpt of our image processing code based on the sample:
Code:
#define SAFE_DELETE(p)          if ((p) != NULL)    \
                                {                   \
                                    delete (p);     \
                                    (p) = NULL;     \
                                }
#define GetMsecTime()           (GetFPGATime()/1000)
    void
    ProcessImage(
        void
        )
    {
        if (m_camera->IsFreshImage())
        {
            int err = ERR_SUCCESS;
            BinaryImage *image = NULL;
            BinaryImage *thresholdImage = NULL;
            BinaryImage *bigObjImage = NULL;
            BinaryImage *convexHullImage = NULL;
            BinaryImage *filteredImage = NULL;
#ifdef _CHECK_PERF
            UINT32 totalTime = 0;
            UINT32 startTime;
            UINT32 deltaTime;
#endif
#ifdef _CHECK_PERF
            startTime = GetMsecTime();
#endif
            m_camera->GetImage(&m_cameraImage);
#ifdef _CHECK_PERF
            deltaTime = GetMsecTime() - startTime;
            totalTime += deltaTime;
            printf("AcquireImageTime = %d", deltaTime);
#endif
            //
            // Filter the image by color.
            //
#ifdef _CHECK_PERF
            startTime = GetMsecTime();
#endif
            switch (m_imageType)
            {
            case IMAQ_IMAGE_RGB:
                thresholdImage =
                    m_cameraImage.ThresholdRGB(*m_colorThresholds);
                break;
            case IMAQ_IMAGE_HSL:
                thresholdImage =
                    m_cameraImage.ThresholdHSL(*m_colorThresholds);
                break;
            default:
                printf("Unsupported image type (type=%d).", m_imageType);
                break;
            }
#ifdef _CHECK_PERF
            deltaTime = GetMsecTime() - startTime;
            totalTime += deltaTime;
            printf("ColorThresholdTime = %d", deltaTime);
#endif
            image = thresholdImage;
            if (thresholdImage == NULL)
            {
                err = imaqGetLastError();
                printf("Failed to filter image with thresholds (err=%d).", err);
            }
            else if (m_sizeThreshold > 0)
            {
                //
                // Remove small objects
                //
#ifdef _CHECK_PERF
                startTime = GetMsecTime();
#endif
                bigObjImage = image->RemoveSmallObjects(
                                false, m_sizeThreshold);
#ifdef _CHECK_PERF
                deltaTime = GetMsecTime() - startTime;
                totalTime += deltaTime;
                printf("BigObjFilterTime = %d", deltaTime);
#endif
                image = bigObjImage;
                if (bigObjImage == NULL)
                {
                    err = imaqGetLastError();
                    printf("Failed to filter image with size (err=%d).", err);
                }
            }
            if (err == ERR_SUCCESS)
            {
#ifdef _CHECK_PERF
                startTime = GetMsecTime();
#endif
                convexHullImage = image->ConvexHull(false);
#ifdef _CHECK_PERF
                deltaTime = GetMsecTime() - startTime;
                totalTime += deltaTime;
                printf("ConvexHullTime = %d", deltaTime);
#endif
                image = convexHullImage;
                if (convexHullImage == NULL)
                {
                    err = imaqGetLastError();
                    printf("Failed to generate Convex Hull image (err=%d).", err);
                }
            }
            if ((err == ERR_SUCCESS) && (m_filterCriteria != NULL))
            {
#ifdef _CHECK_PERF
                startTime = GetMsecTime();
#endif
                filteredImage = image->ParticleFilter(m_filterCriteria,
                                                      m_numCriteria);
#ifdef _CHECK_PERF
                deltaTime = GetMsecTime() - startTime;
                totalTime += deltaTime;
                printf("ParticleFilterTime = %d", deltaTime);
#endif
                image = filteredImage;
                if (filteredImage == NULL)
                {
                    err = imaqGetLastError();
                    printf("Failed to filter image based on criteria (err=%d).", err);
                }
            }
            if (err == ERR_SUCCESS)
            {
#ifdef _CHECK_PERF
                startTime = GetMsecTime();
#endif
                vector<ParticleAnalysisReport> *reports =
                        image->GetOrderedParticleAnalysisReports();
#ifdef _CHECK_PERF
                deltaTime = GetMsecTime() - startTime;
                totalTime += deltaTime;
                printf("GetReportTime = %d", deltaTime);
#endif
                if (reports == NULL)
                {
                    err = imaqGetLastError();
                    printf("Failed to get particle analysis reports (err=%d).", err);
                }
                else
                {
#ifdef _DUMP_REPORTS
                    printf("NumParticles = %d", reports->size());
                    for (unsigned i = 0; i < reports->size(); i++)
                    {
                        ParticleAnalysisReport *p = &(reports->at(i));
                        printf("%d: (%d,%d) [%d,%d/%d,%d]: AR=%5.2f,Q=%5.2f,Per=%4.2f",
                               i,
                               p->center_mass_x,
                               p->center_mass_y,
                               p->boundingRect.left,
                               p->boundingRect.top,
                               p->boundingRect.width,
                               p->boundingRect.height,
                               (float)p->boundingRect.width/(float)p->boundingRect.height,
                               p->particleQuality,
                               p->particleToImagePercent);
                    }
#endif
                    Synchronized sync(m_semaphore);
                    SAFE_DELETE(m_targets);
                    m_targets = reports;
                    reports = NULL;
                }
            }
#ifdef _CHECK_PERF
            printf("Total Elapsed Time = %d", totalTime);
#endif
            SAFE_DELETE(filteredImage);
            SAFE_DELETE(convexHullImage);
            SAFE_DELETE(bigObjImage);
            SAFE_DELETE(thresholdImage);
        }
    }   //ProcessImage
__________________
Reply With Quote