Exemplo n.º 1
0
bool HedgeDetector::processColor(Image* input, Image* output,
                                 ColorFilter& filter,
                                 BlobDetector::Blob& leftBlob,
                                 BlobDetector::Blob& rightBlob,
                                 BlobDetector::Blob& outBlob)
{
    output->copyFrom(input);
    output->setPixelFormat(Image::PF_RGB_8);
    output->setPixelFormat(Image::PF_LCHUV_8);

    filter.filterImage(output);

    // Erode and dilate the image (only if necessary)
    if (m_erodeIterations > 0) {
        IplImage* img = output->asIplImage();
        cvErode(img, img, NULL, m_erodeIterations);
    }

    if (m_dilateIterations > 0) {
        IplImage* img = output->asIplImage();
        cvDilate(img, img, NULL, m_dilateIterations);
    }

    OpenCVImage debug(output->getWidth(), output->getHeight(),
                              Image::PF_BGR_8);
    m_blobDetector.processImage(output, &debug);
    //Image::showImage(&debug);
    BlobDetector::BlobList blobs = m_blobDetector.getBlobs();

    BOOST_FOREACH(BlobDetector::Blob blob, blobs)
    {
        // Sanity check blob
        double percent = (double) blob.getSize() /
            (blob.getHeight() * blob.getWidth());
        if (1.0/blob.getTrueAspectRatio() <= m_maxAspectRatio &&
            1.0/blob.getTrueAspectRatio() >= m_minAspectRatio &&
            m_minWidth < blob.getWidth() &&
            m_minHeight < blob.getHeight() &&
            percent > m_minPixelPercentage &&
            percent < m_maxPixelPercentage)
        {
            processSides(output, blob, leftBlob, rightBlob);
            outBlob = blob;
            return true;
        }
    }
Exemplo n.º 2
0
bool WindowDetector::processColor(Image* input, Image* output,
                                  ColorFilter& filter,
                                  BlobDetector::Blob& outerBlob,
                                  BlobDetector::Blob& innerBlob)
{
    tempFrame->copyFrom(input);
    tempFrame->setPixelFormat(Image::PF_RGB_8);
    tempFrame->setPixelFormat(Image::PF_LCHUV_8);

    filter.filterImage(tempFrame, output);

    // Erode the image (only if necessary)
    IplImage* img = output->asIplImage();
    if (m_erodeIterations > 0) {
        cvErode(img, img, NULL, m_erodeIterations);
    }

    // Dilate the image (only if necessary)
    if (m_dilateIterations > 0) {
        cvDilate(img, img, NULL, m_dilateIterations);
    }

    m_blobDetector.processImage(output);
    BlobDetector::BlobList blobs = m_blobDetector.getBlobs();

    BOOST_FOREACH(BlobDetector::Blob blob, blobs)
    {
        // Sanity check blob
        double pixelPercentage = blob.getSize() /
            (double) (blob.getHeight() * blob.getWidth());


        double aspect = blob.getTrueAspectRatio();
        if (aspect <= m_maxAspectRatio &&
            aspect >= m_minAspectRatio &&
            m_minHeight <= blob.getHeight() &&
            m_minWidth <= blob.getWidth() &&
            m_minPixelPercentage <= pixelPercentage &&
            m_maxPixelPercentage >= pixelPercentage &&
            processBackground(tempFrame, filter, blob, innerBlob))
        {
            int outerCenterX = (blob.getMaxX() - blob.getMinX()) / 2 + blob.getMinX();
            int innerCenterX = (innerBlob.getMaxX() - innerBlob.getMinX()) /
                2 + innerBlob.getMinX();

            int outerCenterY = (blob.getMaxY() - blob.getMinY()) / 2 + blob.getMinY();
            int innerCenterY = (innerBlob.getMaxY() - innerBlob.getMinY()) /
                2 + innerBlob.getMinY();

            int centerXdiff = abs(outerCenterX - innerCenterX);
            int centerYdiff = abs(outerCenterY - innerCenterY);

            double relHeight = (double) innerBlob.getHeight() / blob.getHeight();
            double relWidth = (double) innerBlob.getWidth() / blob.getWidth();

            if(centerXdiff < m_centerXDisagreement &&
               centerYdiff < m_centerYDisagreement &&
               relHeight > m_minRelInnerHeight &&
               relWidth > m_minRelInnerWidth) {

                outerBlob = blob;
                return true;

            }
        }
    }