void MainWindow::on_pushCheck_clicked()
{
    cv::Mat mat = cv::imread(path.toLocal8Bit().data()/*,CV_LOAD_IMAGE_GRAYSCALE*/);
    cv::Mat img_matches;
    QTime tm;
    tm.start();//大图片崩溃
//    cv::Mat mat2 = cv::imread(path2.toLocal8Bit().data(),CV_LOAD_IMAGE_GRAYSCALE);
//    ObjectMat objm(mat2,cv::xfeatures2d::SIFT::create(),new cv::FlannBasedMatcher);
    std::vector<cv::Point2f>  pont;
    objm.matchToPoint(mat,pont,&img_matches);
    qDebug() << " get point :" << tm.elapsed();
    if (pont.size() == 4) {
        QPainter pain(&image);
        QPen pen(Qt::SolidLine);
        pen.setColor(QColor(Qt::red));
        pen.setWidth(3);
        pain.setPen(pen);
        pain.drawLine(QPointF(pont[0].x,pont[0].y),QPointF(pont[1].x,pont[1].y));
        pain.drawLine(QPointF(pont[1].x,pont[1].y),QPointF(pont[2].x,pont[2].y));
        pain.drawLine(QPointF(pont[2].x,pont[2].y),QPointF(pont[3].x,pont[3].y));
        pain.drawLine(QPointF(pont[3].x,pont[3].y),QPointF(pont[0].x,pont[0].y));
        pain.end();
        this->ui->image->setPixmap(QPixmap::fromImage(image.scaled(450,450)));
        cv::imshow( "Good Matches & Object detection", img_matches );
    }

}
int main() 
{	long bos;	// bottom of stack
	pbos = &bos;
	continuation one;
	int n=0;
	
	one.save();
	pain(&n, &one);
	
	
	printf("n = %d\n", n);
	
	getchar();
}
Exemple #3
0
main() {
  pain();
  printf("main result=%g\n",f2(3.14,2)); // f2() is compiled
  StubClass a;
  double y=a.set(2,3.14);
  int x=a.disp();
  printf("main x,y: %d %g\n",x,y);

  StubBase *ary[5];
  ary[0] = new StubClass(3,1.2);
  ary[1] = new StubBase(34);
  ary[2] = new StubBase(56);
  ary[3] = new StubClass(-2,2.3);
  ary[4] = new StubBase(-12);
  for(int i=0;i<5;i++) if (i!=0 && i!=3) ary[i]->disp();
}
Exemple #4
0
void p_wid::paintEvent(QPaintEvent *event)
{
//    Struct_poz s = this->getSelectionBoundings();


    QPainter pain( this );

    //drawing the bg-MUSTER
    for ( unsigned int i = 0; i < this->current_tilesets_height; i ++)
        pain.drawPixmap( 0, 32*i, 256, 32, QPixmap( ":/resources/img/p_wid_background_rib.png" ) );

    QPixmap tmp_pixmap = this->tilesets.at( this->current_tileset );
    pain.drawPixmap(0, 0, 256, tmp_pixmap.height(), tmp_pixmap );

    //*** now the advanced stuff

    //drawing the grid

    QImage template1 = QImage( 32,32, QImage::Format_ARGB32 );
    template1.fill( 0 );
    QPainter tP( &template1 );
    tP.setPen( QColor( 100, 100, 100, 100 ) );
    tP.drawLine( 0,0,  31,0 );
    tP.drawLine( 0,0,  0,31 );
    tP.drawLine( 0,31, 31,31 );
    tP.drawLine( 31,0, 31,31 );
    if ( this->right_click_menu->actions()[ 0 ]->isChecked() )
    {
        for ( int hz = 0; hz < this->tilesets[ this->current_tileset ].height(); hz += 32 )
        {
            for ( int w = 0; w < 8; w++ )
            {
                pain.drawImage( QPoint(w*32, hz), template1);
            }
        }
    }
    //drawing the dim

    //framing the selection
    Struct_poz rec;
    rec.first_tile  = 0;
    rec = this->getSelectionBoundings();

    // mid white rect
    QRect frame;
    frame.setY( (       rec.first_tile / 8 ) * 32 );
    frame.setX( (       rec.first_tile % 8 ) * 32 );
    frame.setWidth(     rec.width * 32 );
    frame.setHeight(    rec.height * 32 );
    pain.setPen( Qt::white );
    pain.drawRect( frame );

    // outa black frame
    frame.setY( (       rec.first_tile / 8 ) * 32   -1);
    frame.setX( (       rec.first_tile % 8 ) * 32   -1);
    frame.setWidth(     rec.width * 32   +2);
    frame.setHeight(    rec.height * 32  +2);
    pain.setPen( Qt::black );
    pain.drawRect( frame );

    //inna black frame
    frame.setY( (       rec.first_tile / 8 ) * 32   +1);
    frame.setX( (       rec.first_tile % 8 ) * 32   +1);
    frame.setWidth(     rec.width * 32    -2);
    frame.setHeight(    rec.height * 32   -2);
    pain.setPen( Qt::black );
    pain.drawRect( frame );


    pain.end();
    event->accept();
}
void QGIPiece::propertySet( char const *pname, QVariant const & var )
{
    // FIXME: treat QVariant::Invalid appropriately for each property
    typedef QMap<QString,int> PMAP;
    static PMAP pmap;
    if( pmap.isEmpty() )
    {
#define MAP(S,V) pmap[S] = Impl::V;
	MAP("color",PropColor);
	MAP("alpha",PropAlpha);
	MAP("colorAlpha",PropAlpha); // older name
	MAP("borderColor",PropBorderColor);
	MAP("borderSize",PropBorderSize);
	MAP("borderAlpha",PropBorderAlpha);
	MAP("borderStyle",PropBorderStyle);
	MAP("zLevel",PropZLevel);
	MAP("pos",PropPos);
	MAP("scale",PropScale);
	MAP("size",PropSize);
	MAP("angle",PropAngle);
	MAP("dragDisabled",PropDragDisabled);
	MAP("pixmap",PropPixmap);
#undef MAP
    }

    const QString key(pname?pname:"");
    int kid = pmap.value( key, Impl::PropUnknown );
    if( Impl::PropUnknown == kid ) return;
    if(0) qDebug() << "QGIPiece::propertySet("<<key<<")] val ="<<var;
    if( Impl::PropZLevel == kid )
    {
	this->setZValue(var.toDouble());
	this->update();
    }
    else if( Impl::PropPos == kid )
    {
	this->setPos( var.value<QPointF>() );
	this->update();
    }
    else if( Impl::PropColor == kid )
    {
 	QColor col = var.value<QColor>();
	qreal alpha = impl->pen.color().alphaF();
 	if( 255 == col.alpha() ) // keep original alpha level
 	{
	    if( alpha > 1 )
	    {
		col.setAlpha( int(alpha) );
	    }
	    else
	    {
		col.setAlphaF( alpha );
	    }
 	}
	impl->pen.setColor( col );
	if(0) qDebug() << "QGIPiece::propertySet(color):"<<impl->pen.color()<<" alpha ="<<impl->alpha;
	impl->clearCache();
	this->update();
    }
    else if( Impl::PropAlpha == kid )
    {
	qreal a = var.toDouble();
	QColor col = impl->pen.color();
	if( a > 1.0 )
	{ // assume it's int-encoded
	    col.setAlpha( int(a) );
	}
	else
	{
	    col.setAlphaF( a );
	}
	impl->pen.setColor( col );
	impl->clearCache();
    	this->update();
    }
    else if( Impl::PropBorderColor == kid )
    {
	QColor col = var.value<QColor>();
 	if( 255 == col.alpha() )
 	{
	    col.setAlphaF( impl->penB.color().alphaF() );
 	}
	impl->penB.setColor( col );
	impl->clearCache();
	this->update();
    }
    else if( Impl::PropBorderAlpha == kid )
    {
	qreal a = var.toDouble();
	QColor col( impl->penB.color() );
	if( a > 1.0 )
	{ // assume it's int-encoded
	    col.setAlpha( int(a) );
	}
	else
	{
	    col.setAlphaF( a );
	}
	impl->penB.setColor( col );
	impl->clearCache();
	this->update();
    }
    else if( Impl::PropBorderSize == kid )
    {
	double bs = var.toDouble();
	impl->penB.setWidth( (bs >= 0) ? bs : 0 );
	impl->clearCache();
	this->update();
    }
    else if( Impl::PropBorderStyle == kid )
    {
	impl->clearCache();
	impl->penB.setStyle( s11n::qt::stringToPenStyle(var.toString()) );
	this->update();
    }
    else if( (Impl::PropScale == kid) || (Impl::PropAngle == kid) )
    {
	this->refreshTransformation();
    }
    else if( Impl::PropDragDisabled == kid )
    {
	if( var.isValid() )
	{
	    this->setFlag( QGraphicsItem::ItemIsMovable, var.toInt() ? false : true );
	}
	else
	{
	    this->setFlag( QGraphicsItem::ItemIsMovable, true );
	}
    }
    else if( Impl::PropPixmap == kid )
    {
	this->prepareGeometryChange();
	impl->clearCache();
	QPixmap pix;
	if( var.canConvert<QPixmap>() )
	{
	    pix = var.value<QPixmap>();
	}
	else if( var.canConvert<QString>() )
	{
	    QString fname( qboard::homeRelative(var.toString()) );
	    if( pix.load( fname ) )
	    {
		this->setProperty("size",pix.size());
	    }
	    else
	    {
		pix = QPixmap(300,40);
		QPainter pain(&pix);
		pain.fillRect( pix.rect(), Qt::yellow );
		QFont font( "courier", 8 );
		pain.setFont( font ); 
		pain.setPen( QPen(Qt::red) );
		pain.drawText(5,font.pointSize()+6,"Error loading pixmap:");
		pain.drawText(5,pix.height()-6,fname);
	    }
	} // var.canConvert<QString>()
	this->impl->pixmap = pix;
	if(1)
	{
	    // Kludge to ensure that this type's shape is properly set. We don't want
	    // the parent class to have the real pixmap, so that we can control all
	    // painting ourselves.
	    QPixmap bogus( pix.size() );
	    bogus.fill( QColor(Qt::transparent) );
	    this->setPixmap(bogus);
	}
	this->update();
    } // pixmap property
    if( Impl::PropSize == kid )
    {
	impl->clearCache();
	if( impl->pixmap.isNull() )
	{
	    QPixmap bogus( var.toSize() );
	    bogus.fill( QColor(Qt::transparent) );
	    impl->pixmap = bogus;
	    // Kludge to ensure bounding rect is kept intact
	    this->setPixmap(bogus);
	}
    }
}