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__ );
    }
}
Exemplo n.º 2
0
bool ImageThreshold::process()
{
    CvMatData in = m_inputPin->get();
    CvMatData out = CvMatData::create( in.width(), in.height(), in.type() );

    const cv::Mat& src = in;
    cv::Mat& dst = out;

    // perform threshold operation on the image
    cv::threshold( src, dst, m_threshold, m_maxValue, m_method.getSelectedValue() );

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

    return true;
}
Exemplo n.º 3
0
bool ImageFlip::process()
{
    CvMatData in = m_inputPin->get();
    CvMatData out = CvMatData::create(in.properties());

    // open for reading
    const cv::Mat& src = in;

    // open image for writing
    cv::Mat& target = out;

    // do a flip of the image
    cv::flip( src, target, m_method.getSelectedValue() );

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

    return true;
}
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 );

}
Exemplo n.º 5
0
bool Gray2RGB::process()
{
	assert(m_inputPin != 0);
    assert(m_outputPin != 0);

    CvMatData src = m_inputPin->get();

    // allocate a target buffer
    CvMatData target;
    target.create( src.width(), src.height(), src.type() );

    // do a flip of the image
    const cv::Mat in = src;
    cv::Mat out = target;
    cv::flip( in, out, 1);

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


//   CvMatData in = m_inputPin->get();
    //const cv::Mat& inputImage = in;
    //m_outputPin->put( inputImage );
    return true;

}
/**
 * The method in steps:
 *  - Check if input is initialized and retrieve the image data.
 *  - Check if the trigger input is active
 *     # Set doSave corresponding to the value of the trigger
 *  - Check if the image has to be saved.
 *     # Build the save path.
 *     # Save image to the correct file format
 *     # Check if the suffixNr needs to be increased and increase it.
 */
void SaveImageToFile::process()
{
    assert(m_inputImage != 0);
    CvMatData img = m_inputImage->get();
    if( m_inputTrigger->isConnected() )
    {
        if( !m_inputTrigger->getConnection()->hasData() )
        {
            return;
        }

        //If the trigger has been connected check if the trigger sent an activation.
        RefPtr<PlvBoolean> trig = m_inputTrigger->get();
        if( trig->getValue() )
            setDoSave(true);
    }

    if(m_doSave)
    {
        QString fn = m_directory;
        //Check if the string ends with a '/' character
        if(!fn.endsWith('/'))
            fn.append('/');
        fn.append(m_filename);
        fn.append(QString::number(m_suffixNr));
        fn.append(m_fileExt);

        const IplImage* saveImg = img->getImage();
        if(!cvSaveImage(fn.toAscii(), saveImg))
        {
            qDebug() << "Something went wrong with writing to a file: " << fn;
        }

        if(m_autoIncSuf)
            setSuffixNr(m_suffixNr+1);

        setDoSave(false);
    }
}
/**
Calculates the first, second, third or mixed image derivatives using an extended Sobel operator
Parameters:

    * src – The source image
    * dst – The destination image; will have the same size and the same number of channels as src
    * ddepth – The destination image depth
    * xorder – Order of the derivative x
    * yorder – Order of the derivative y
    * ksize – Size of the extended Sobel kernel, must be 1, 3, 5 or 7
    * scale – The optional scale factor for the computed derivative values (by default, no scaling is applied, see getDerivKernels() )
    * delta – The optional delta value, added to the results prior to storing them in dst
    * borderType – The pixel extrapolation method, see borderInterpolate()
*/
void EdgeDetectorSobel::process()
{
    CvMatData srcPtr = m_inputPin->get();
    CvMatData dstPtr = CvMatData::create( srcPtr.properties() );

    // open for reading
    const cv::Mat& src = srcPtr;

    // open image for writing
    cv::Mat& dst = dstPtr;

    assert( m_xOrder == 1 || m_xOrder == 0 );
    assert( m_yOrder == 1 || m_yOrder == 0 );
    assert( m_kernelSize == 1 || m_kernelSize == 3 || m_kernelSize == 5 || m_kernelSize == 7 );

    // do sobel operation
    cv::Sobel( src, dst, dst.depth() , m_xOrder, m_yOrder,
               m_kernelSize, m_scale, m_delta,
               m_borderType.getSelectedValue() );

    // publish output
    m_outputPin->put( dstPtr );
}
void ImageCornerHarris::process()
{
    assert(m_inputPin != 0);
    assert(m_outputPin != 0);

    // get the src image
    CvMatData in = m_inputPin->get();

    // make a target image
    // cv::CornerHarris expects a 32F dst image
    CvMatDataProperties props( in.width(), in.height(), CV_32FC1 );
    CvMatData out = CvMatData::create( props );

    const cv::Mat& src = in;
    cv::Mat& dst = out;

    // do a canny edge detection operator of the image
    cv::cornerHarris( src, dst, m_blockSize, m_kernelSize,
                      m_k, m_borderType.getSelectedValue() );

    // publish the new image
    m_outputPin->put( out );
}
bool EdgeDetectorCanny::process()
{
    // get the source
    CvMatData in = m_inputPin->get();

    // get a new target image with the same properties as the src
    CvMatData out = CvMatData::create( in.properties() );

    // open for reading
    const cv::Mat& src = in;

    // open image for writing
    cv::Mat& edges = out;

    // do a canny edge detection operator of the image
    // the input should be grayscaled
    cv::Canny( src, edges, m_thresholdLow, m_thresholdHigh, m_apertureSize, m_l2Gradient );

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

    return true;
}
Exemplo n.º 10
0
void OpenCVCamera::run()
{
    assert( m_state != CAM_UNINITIALIZED );
    assert( m_captureDevice != 0 );

    while( m_state == CAM_RUNNING || m_state == CAM_PAUSED )
    {
        // get a frame, blocking call
        CvMatData frame;
        if( !getFrame(frame) )
        {
            qWarning() << "Camera failed to grab frame. Exiting camera loop.";
            return;
        }

        // send a signal to subscribers
        if( frame.isValid() )
        {
            emit newFrame( frame );
        }

        if( m_state == CAM_PAUSED )
        {
            m_mutex.lock();

            // this will let this thread wait on the event
            // and unlocks the mutex so no deadlock is created
            m_condition.wait(&m_mutex);

            // we have woken up
            // mutex was relocked by the condition
            // unlock it here
            m_mutex.unlock();
        }
    }
}