Exemplo n.º 1
0
void CvMatDataInputPin::checkImageFormat( const CvMatData& mat )
{
    if( !supportsDepth( mat.depth()) )
    {
        QString msg = QString("Depth \"%1\" unsupported by input pin \"%2\"")
                      .arg( CvMatData::depthToString( mat.depth() ) )
                      .arg( this->getName() );
        throw PlvRuntimeException( msg, __FILE__, __LINE__ );
    }

    if( !supportsChannels(mat.channels()) )
    {
        QString msg = "Number of channels " %
                      QVariant(mat.channels()).toString() %
                      " unsupported by input pin \"" % this->getName() %
                      "\". Supports channels (";
        QString channelsStr;
        channelsStr.reserve( (2 * m_channels.size()) + 2 );

        QList<int> channelList = m_channels.toList();
        int lastIdx = channelList.size() - 1;
        for( int i = 0; i < channelList.size(); ++i )
        {
            channelsStr += QVariant(channelList.at(i)).toString();
            if( i != lastIdx )
                channelsStr += ",";
        }
        msg += channelsStr + ").";
        throw PlvRuntimeException( msg, __FILE__, __LINE__ );
    }
}
void DistanceTransform::process()
{
    //get the input image
    CvMatData img = m_inputPin->get();

    // open input images for reading
    const cv::Mat& src = img;

    if(img.channels() != 1)
        qDebug() << "Wrong number of channels";
    if(img.depth() != CV_8U && img.depth() != CV_8S)
        qDebug() << "Wrong depth in the image";

    //get a destination image with the distance values.
    CvMatData out = CvMatData::create( img.width(), img.height(), CV_32FC1 );
    // open output image for writing
    cv::Mat& dst = out;

    //DistanceTransform both images
    try{
        cv::distanceTransform(src, dst, m_distanceType.getSelectedValue(), m_maskSize.getSelectedValue());
    }
    catch(std::exception &e){
        //Don't know why but this try/catch block prevents exception troubles.
        qDebug() << "exception: " << e.what();
        throw;
    }

    // publish the new image
    m_outputPin->put( out );

}