void NWcolorGradientWidget::deleteColor( void )
{
    CFcolorGradient& colorGradient( m_gradientPlug->editableValue<CFcolorGradient>() );

    colorGradient.deleteKey( m_selectedHandle );
    
    m_gradientPlug->notifyChange();
    update();
}
void NWcolorGradientWidget::setSmoothInterp( void )
{
    CFcolorGradient& colorGradient( m_gradientPlug->editableValue<CFcolorGradient>() );

    colorGradient.setInterpolation( CFcolorGradient::kSmooth );

    m_gradientPlug->notifyChange();
    update();
}
void NWcolorGradientWidget::changeColor( void )
{
    CFcolorGradient& colorGradient( m_gradientPlug->editableValue<CFcolorGradient>() );

    QColor newColor( QColorDialog::getColor( colorGradient[ m_selectedHandle ].value().asQColor(), this ) );

    if( newColor.isValid() )
    {
        colorGradient.setKeyValue( m_selectedHandle, newColor );

        m_gradientPlug->notifyChange();
        update();
    }
}
void NWcolorGradientWidget::mouseMoveEvent( QMouseEvent* event )
{
    if( m_dragging )
    {
        CFfloat position = toGradientSpace( event->x() );
        
        if( position < 0.0 ) position = 0.0;
        if( position > 1.0 ) position = 1.0;

        CFcolorGradient& colorGradient( m_gradientPlug->editableValue<CFcolorGradient>() );

        m_selectedHandle = colorGradient.moveKey( m_selectedHandle, position );

        m_gradientPlug->notifyChange();
        update();
    }
}
示例#5
0
void EdgeDetector::canny(Mat src,vector<Mat> &dst,vector<double> lower,vector<double> higher,int aperture)
{

    Mat fmag,fori,disp;

    s=Size(src.cols,src.rows);
    smoothing(src,src,aperture);


    if(src.channels()>1)
    colorGradient(src,fmag,fori,aperture);
    else
    {
    Mat dx,dy;
    //computing gradients along x and y direction
    cv::Sobel(src,dx,CV_32F,1,0,aperture,1, 0, cv::BORDER_REPLICATE);
    cv::Sobel(src,dy,CV_32F,0,1,aperture,1, 0, cv::BORDER_REPLICATE);
    //compute magnitude and orientation of gradient
    cv::cartToPolar(dx,dy,fmag,fori,true);
    }


    //perform non maxima suppression
    nonMaxima(fmag,fori);
    Mat hout;


    dst.resize(lower.size());
    for(int i=0;i<lower.size();i++)
    {
    //apply lower and higher gradient thresholds
    cv::threshold(fmag,hout,lower[i],255,CV_THRESH_BINARY);
    cv::threshold(fmag,lout,higher[i],255,CV_THRESH_BINARY);
    connectedComponent(hout);
    _lable.copyTo(dst[i]);
    }


}
void NWcolorGradientWidget::mousePressEvent( QMouseEvent* event )
{
    unsigned int i;

    CFcolorGradient& colorGradient( m_gradientPlug->editableValue<CFcolorGradient>() );
    
    //  If clicked on the gradient
    //
    if( m_gradiantArea.contains( event->pos(), true ) )
    {
        //  Insert a new color handle
        //
        if( event->button() == Qt::LeftButton )
        {
            CFfloat position = toGradientSpace( event->x() );
            
            m_selectedHandle = colorGradient.insertKey
            (
                CFcolorGradient::Key( position, colorGradient.evaluate( position ) )
            );

            m_gradientPlug->notifyChange();
            update();
    
            //  And begin dragging it
            //
            m_dragging = true;
        }
        else if( event->button() == Qt::RightButton )
        {
            m_interpolationMenu->exec( event->globalPos() );
        }
    }

    //  Else find ( if any ) the handle which was clicked on
    //
    else for( i = 0; i < m_handlePositions.size(); i++ )
    {
        if( ( event->pos() - m_handlePositions[ i ] ).manhattanLength() < ( m_handleRadius + 3 ) )
        {
            //  Select the handle which was clicked on
            //
            m_selectedHandle = i;

            update();

            //  Show context menu
            //
            if( event->button() == Qt::RightButton )
            {
                m_deleteColorAction->setEnabled( colorGradient.keyCount() > 1 );
                m_handleMenu->exec( event->globalPos() );
            }

            //  Or begin dragging the handle
            //
            else if( event->button() == Qt::LeftButton )
            {
                m_dragging = true;
            }

            break;
        }
    }
}