View Single Post
  #8   Spotlight this post!  
Unread 05-02-2012, 14:28
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: Printing to the DriverStation LCD

The code is pretty much based on the VisionSample2012 code with more error checking and generalized so that the caller can provide parameters such as color space (RGB vs HSL), minimum particle size and particle filter criteria etc. Notice the time stamp code in there. That's how we found out how long it takes to process one frame.
Code:
void ProcessImage(void)
{
    if (IsEnabled() && m_camera->IsFreshImage())
    {
        int err = ERR_SUCCESS;
        BinaryImage *image;
        BinaryImage *thresholdImage;
        BinaryImage *bigObjImage;
        BinaryImage *convexHullImage;
        BinaryImage *filteredImage;
        UINT32 startTime = GetMsecTime();
        m_camera->GetImage(&m_cameraImage);
        //
        // Filter the image by color.
        //
        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:
            TErr(("Unsupported image type (type=%d).", m_imageType));
            break;
        }
        image = thresholdImage;
        if (thresholdImage == NULL)
        {
            err = imaqGetLastError();
            TErr(("Failed to filter image with thresholds (err=%d).",
                  err));
        }
        else if (m_sizeThreshold > 0)
        {
            //
            // Remove small objects
            //
            bigObjImage = image->RemoveSmallObjects(false, m_sizeThreshold);
            image = bigObjImage;
            if (bigObjImage == NULL)
            {
                err = imaqGetLastError();
                TErr(("Failed to filter image with size (err=%d).", err));
            }
        }
        if (err == ERR_SUCCESS)
        {
            convexHullImage = image->ConvexHull(false);
            image = convexHullImage;
            if (convexHullImage == NULL)
            {
                err = imaqGetLastError();
                TErr(("Failed to generate Convex Hull image (err=%d).",
                      err));
            }
        }
        if ((err == ERR_SUCCESS) && (m_filterCriteria != NULL))
        {
            filteredImage = image->ParticleFilter(m_filterCriteria,
                                                  m_numCriteria);
            image = filteredImage;
            if (filteredImage == NULL)
            {
                err = imaqGetLastError();
                TErr(("Failed to filter image based on criteria (err=%d).",
                      err));
            }
        }
        if (err == ERR_SUCCESS)
        {
            vector<ParticleAnalysisReport> *reports =
                    image->GetOrderedParticleAnalysisReports();
            if (reports == NULL)
            {
                err = imaqGetLastError();
                TErr(("Failed to get particle analysis reports (err=%d).",
                      err));
            }
            else
            {
                for (unsigned i = 0; i < reports->size(); i++)
                {
                    ParticleAnalysisReport *p = &(reports->at(i));
                    TInfo(("%d: (%d,%d) [%d,%d/%d,%d]: Q=%5.2f,Per=%5.2f",
                           i,
                           p->center_mass_x,
                           p->center_mass_y,
                           p->boundingRect.left,
                           p->boundingRect.top,
                           p->boundingRect.width,
                           p->boundingRect.height,
                           p->particleQuality,
                           p->particleToImagePercent));
                }
                Synchronized sync(m_semaphore);
                SAFE_DELETE(m_targets);
                m_targets = reports;
                reports = NULL;
            }
        }
        SAFE_DELETE(filteredImage);
        SAFE_DELETE(convexHullImage);
        SAFE_DELETE(bigObjImage);
        SAFE_DELETE(thresholdImage);
        TInfo(("Elapsed time = %d", GetMsecTime() - startTime));
    }
}   //ProcessImage
__________________
Reply With Quote