dlpy_main::dlpy_main(int state,string filename,QWidget *parent) : QMainWindow(parent), ui(new Ui::dlpy_main) { ui->setupUi(this); setGeometry(697, 50, 220, 480); wid = new widget(); wid->setWindowFlags(Qt::FramelessWindowHint); wid->show(); frame = new dlpy_frames(state,filename); frame->setWindowFlags(Qt::FramelessWindowHint); //隐藏标题栏 frame->show(); connect(this,SIGNAL(setparasignal(int,int,int,int,int)),frame,SLOT(setparaslot(int,int,int,int,int))); connect(frame,SIGNAL(setalertsignal(int)),this,SLOT(setalertslot(int))); //每一帧图像信号槽初始化警报参数 connect(this,SIGNAL(setlinesignal(int)),frame,SLOT(setlineslot(int))); ///////////////////////////////////////////////////////////////////////////////////////////// //img_alert: 显示所有 //img_alert_1: 红色警报 //img_alert_3: 无警报 //img_temp:所有 //img:所有 //////////////////////////////////////////////////////////////////////////////////////////// img_alert = cv::imread("/home/hugo/code/bin/alert.bmp"); img_alert_1 = cv::imread("/home/hugo/code/bin/alert_2.bmp"); img_alert_2 = cv::imread("/home/hugo/code/bin/alert_3.bmp"); img_temp = cv::imread("/home/hugo/code/bin/alert.bmp"); roi_l=Rect(0, 0, (img_alert.cols-1)/2, img_alert.rows-1); roi_r=Rect((img_alert.cols-1)/2, 0, (img_alert.cols-1)/2, img_alert.rows-1); QGraphicsScene *scene = new QGraphicsScene; QImage img; img.load("/home/hugo/code/bin/alert.bmp"); QPixmap mp; mp=mp.fromImage(img); times_alert=0; last_alert=0; w0=weatherobj(10,20,30,40,50); w1=weatherobj(60,70,80,90,100); w2=weatherobj(100,110,120,130,140); w3=weatherobj(10,60,0,42,100); w4=weatherobj(150,160,170,180,190); w5=weatherobj(200,210,220,230,240); w6=weatherobj(10,25,10,32,90); w7=weatherobj(200,240,220,250,123); QImage *qimg=new QImage; *qimg=mat2qimage(img_temp); /*cvtColor(img_temp, img_temp, CV_BGR2RGB); qimg = new QImage((unsigned char*)img_temp.data, // uchar* data img_temp.cols, img_temp.rows, // width height img_temp.step, //bytesPerLine QImage::Format_RGB888); //format*/ scene->addPixmap(QPixmap::fromImage(*qimg)); ui->graphicsView->setScene(scene); ui->graphicsView->resize(qimg->width() + 10, qimg->height() + 10); ui->graphicsView->show(); timer = new QTimer(this); timer->setInterval(30); connect(timer,SIGNAL(timeout()),this,SLOT(alertFrame())); //每隔30s读取一次报警图片 timer->start(); }
bool ImageCalibrator::init(QString imgPath) { QList<QString > tmp; QString imgFileM; QString imgOrig; QFileInfo ourFile(imgPath); tmp = ourFile.fileName().split(".", QString::SkipEmptyParts); if(tmp.size()==2) imgFileM = tmp[0] + "m." + tmp[1]; else imgFileM = ""; //mask = ; imgOrig = ourFile.absoluteDir().path() + "/" + tmp[0] + "_orig.png"; bool createOrig=false; if(!QFile::exists(imgOrig)) { createOrig=true; } //Scene->mSpriteImage = QPixmap(fileName); if(createOrig) { sprite = QPixmap::fromImage( Graphics::setAlphaMask( Graphics::loadQImage( imgPath ) ,Graphics::loadQImage( ourFile.absoluteDir().path() + "/" + imgFileM )) ); if(sprite.isNull()) return false; sprite.save(imgOrig, "PNG"); // Generate backup image } else sprite = QPixmap::fromImage( Graphics::loadQImage( imgOrig ) ); // load original sprite instead current if(sprite.isNull()) return false; targetPath = imgPath; pngPath = ourFile.absoluteDir().path() + "/" + tmp[0] + ".png"; gifPath = ourFile.absoluteDir().path() + "/" + tmp[0] + ".gif"; gifPathM = ourFile.absoluteDir().path() + "/" + tmp[0] + "m.gif"; iniPath = ourFile.absoluteDir().path() + "/" + tmp[0] + "_orig_calibrates.ini"; //generate scene ui->PreviewGraph->setScene(new QGraphicsScene(ui->PreviewGraph)); QGraphicsScene * sc = ui->PreviewGraph->scene(); frmX=0; frmY=0; frameOpts xyCell; xyCell.offsetX=0; xyCell.offsetY=0; xyCell.W=0; xyCell.H=0; xyCell.used=false; xyCell.isDuck=false; xyCell.isRightDir=false; xyCell.showGrabItem=false; // Write default values QVector<frameOpts > xRow; for(int i=0; i<10; i++) { xRow.clear(); for(int j=0; j<10; j++) { xRow.push_back(xyCell); } imgOffsets.push_back(xRow); } loadCalibrates(); imgFrame = sc->addPixmap(sprite.copy(frmX*100,frmY*100,100,100)); imgFrame->setZValue(0); imgFrame->setPos(0,0); phsFrame = sc->addRect(0,0,99,99, QPen(QBrush(Qt::gray), 1)); phsFrame->setZValue(-2); phsFrame->setOpacity(0.5f); phsFrame->setPos(0,0); physics = sc->addRect(0,0,99,99, QPen(QBrush(Qt::green), 1)); physics->setZValue(4); physics->setPos(0,0); updateScene(); return true; }
FenPrincipale::FenPrincipale() { // setFixedSize(1200,800); // Dimensions fixées à 850x480px QGridLayout *layout0 = new QGridLayout; // c le layout de base de la page1 QGraphicsScene *scene = new QGraphicsScene; QGraphicsView *vue = new QGraphicsView(scene,this); scene->setSceneRect(0,0,mapLargeur+50,mapHauteur+50); // taille de la scene vue->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing); vue->setFixedSize(mapLargeur+100,mapHauteur+100); //taille de la vue //Mise en place de la map QPixmap map_im ; map_im.load("map.png"); map=scene->addPixmap(map_im); map->setPos(0,0); map->setZValue(-1); //Rectangle test_debug QRect rectangle1(15,15,618,418); scene->addRect(rectangle1); //rectangle1.moveCenter(QPoint(0,0)); // met le centre au centre //Création de l'origine QRect rectangle(0,0,10,10); rectangle.moveCenter(QPoint(0,0)); // met le centre au centre origine=scene->addRect(rectangle); origine->setPos(map_im.width()/2,map_im.height()/2);// au centre de l'image //Mise en place de du robot QPixmap robot_im ; robot_im.load("petit_robot.png"); robot=scene->addPixmap(robot_im); robot->setZValue(2);// au dessus de l'image carte 2>-1 robot->setOffset(-robot_im.width()/2,-robot_im.height()/2); // origine du robot au centre robot->setPos(origine->x(),origine->y());//placer au centre du palteau //Mise en place de l'obstacle QPen pen(Qt::black, 1, Qt::SolidLine); QBrush brush(Qt::black); //scene.addRect(rectangle, pen, brush); obstacle = scene->addEllipse(0,0,15,15,pen,brush); obstacle->setZValue(1); obstacle->setPos(origine->x(),origine->y()); obstacle2 = scene->addEllipse(0,0,15,15,pen,brush); obstacle2->setZValue(1); obstacle2->setPos(origine->x(),origine->y()); //Ajout au layout principale puis à la fenetre layout0->addWidget(vue, 0,0); setLayout(layout0); //Configuration du Timer pas utiliser (debug) timer = new QTimer(this); // timer->start(1000); //Connection des Signaux/Solts connect( timer, SIGNAL(timeout()), this, SLOT(timerOut()) ); //Pacement par defaut //modifPosition(robot,-750,-1250,90); modifPosition(robot,-750,0,0); testPosObs(obstacle,100,90); }
bool MouseEventEater::eventFilter(QObject *obj, QEvent *event) { QString theObjName = obj->objectName(); if((theObjName != "" )&(event->type() != QEvent::None)&(event->type() != 39)&(event->type() != 69)&(event->type() != 74)&(event->type() != 75)&(event->type() != 170)) { // int test = event->type(); QMouseEvent *mouseEvent; int slot = 0; slot = (atoi(theObjName.right(2).toStdString().c_str()))-1; frmCurSlotNum = slot; bool todisplay = false; switch(event->type()) { case QEvent::MouseButtonPress: // case QEvent::MouseButtonDblClick: mouseEvent = static_cast<QMouseEvent *>(event); switch(mouseEvent->button()) { case Qt::LeftButton: switch(theObjName.toStdString()[2]) { case 'B': if(theObjName.mid(2,5) == "BoxSl") { theSlot = obj; apkm = &(frmCurBox->pokemon[slot]); ispartypkm_ = false; todisplay = true; } break; case 'P': theSlot = obj; apkm = &(frmParty->pokemon[slot]); ispartypkm_ = true; todisplay = true; break; default: QPixmap extmarkingspix; int selection = 0; if(theObjName.right(theObjName.length() - 2).toStdString() == "Circle"){ temppkm->markings.circle = !(temppkm->markings.circle); selection = (int)Markings::circle; extmarkingspix = getmarkingimage(Markings::circle, temppkm->markings.circle); } if(theObjName.right(theObjName.length() - 2).toStdString() == "Triangle"){ temppkm->markings.triangle = !(temppkm->markings.triangle); selection = (int)Markings::triangle; extmarkingspix = getmarkingimage(Markings::triangle, temppkm->markings.triangle); } if(theObjName.right(theObjName.length() - 2).toStdString() == "Square"){ temppkm->markings.square = !(temppkm->markings.square); selection = (int)Markings::square; extmarkingspix = getmarkingimage(Markings::square, temppkm->markings.square); } if(theObjName.right(theObjName.length() - 2).toStdString() == "Star"){ temppkm->markings.star = !(temppkm->markings.star); selection = (int)Markings::star; extmarkingspix = getmarkingimage(Markings::star, temppkm->markings.star); } if(theObjName.right(theObjName.length() - 2).toStdString() == "Diamond"){ temppkm->markings.diamond = !(temppkm->markings.diamond); selection = (int)Markings::diamond; extmarkingspix = getmarkingimage(Markings::diamond, temppkm->markings.diamond); } if(theObjName.right(theObjName.length() - 2).toStdString() == "Heart"){ temppkm->markings.heart = !(temppkm->markings.heart); selection = (int)Markings::heart; extmarkingspix = getmarkingimage(Markings::heart, temppkm->markings.heart); } QGraphicsScene * themarkingsscene = (QGraphicsScene*)extmarkingsscene; themarkingsscene = new QGraphicsScene(); themarkingsscene->addPixmap(extmarkingspix); QGraphicsView * themarkingsgraphics = (QGraphicsView*)obj; themarkingsgraphics->setScene(themarkingsscene); break; } if((apkm->species != 0) && todisplay) { // pview->setWindowTitle(QString::fromStdWString(getpkmnickname(apkm))); pview->setPKM(apkm,frmCurBoxNum, ispartypkm_); pview->displayPKM(); pview->show(); boxViewer->refreshboxgrids(); } break; default: break; } break; // case QEvent::MouseButtonDblClick: // test.setText("Test"); // test.show(); // break; case QEvent::ContextMenu: if(theObjName.mid(2,5) == "BoxSl") { apkm = &(frmCurBox->pokemon[slot]); // send_rightButtonClicked(mouseEvent->globalPos()); QMenu *menu = new QMenu(static_cast<QWidget*>(this->parent())); menu->addAction(new QAction("Delete",static_cast<QWidget*>(this->parent()))); // connect(mouseEventEater, SIGNAL(send_rightButtonClicked(const QPoint&)), // this, SLOT(rightButtonClicked(const QPoint&))); // connect(menu,SIGNAL(triggered()),static_cast<QWidget*>(this->parent()), // SLOT(MouseEventEater::test(apkm))); connect(static_cast<QWidget*>(this->parent()), SIGNAL ( customContextMenuRequested(QPoint) ), static_cast<QWidget*>(this->parent()), SLOT ( test(apkm) ) ); menu->exec(QCursor::pos()); } break; default: return QObject::eventFilter(obj, event); break; } } else { if(event->type() == QEvent::MouseButtonPress) { int slot = obj->property("Index").toInt(); boxViewer->changebox(slot); } return false; } return false; }
void fichierControl::openVideo(QString &fileName, QGraphicsView *videoGraphicsview, QProgressBar *progressBar) { bool stop = false; if (!cap.open(fileName.toStdString())){ cout << "Cannot read the frame from video file" << endl; } //get the number of frame long totalFrameNumber = cap.get(CV_CAP_PROP_FRAME_COUNT); cout<<"Number of frame"<<totalFrameNumber<<endl; //start the video at 300ms long frameToStart = 300; cap.set( CV_CAP_PROP_POS_FRAMES,frameToStart); cout<<"Frame to start"<<frameToStart<<endl; //stop the video at 400ms int frameToStop = 400; if(frameToStop < frameToStart) { cout<<"Frametostop smaller than frametostart!"<<endl; } else { cout<<"Frame to stop"<<frameToStop<<endl; } //get the frames per seconds of the video double rate = cap.get(CV_CAP_PROP_FPS); cout<<"the frames per seconds"<<rate<<endl; int delay = 1000/rate; currentFrame = frameToStart; //set the minimum and maximum value of progressBar progressBar->setMinimum(frameToStart); progressBar->setMaximum(frameToStop); //namedWindow("MyVideo",WINDOW_NORMAL); //create a window called "MyVideo" //resizeWindow("MyVideo", 400, 300); //Create Trackbar /*if(totalFrameNumber != 0){ createTrackbar("Position", "MyVideo", ¤tFrame, totalFrameNumber, tbCallback, &frame); }*/ while(!stop) { bool bSuccess = cap.read(frame); // read a new frame from video if (!bSuccess) //if not success, break loop { cout << "Cannot read the frame from video file" << endl; } /*******/ if(frame.data){ cvtColor(frame, frame, CV_BGR2RGB); //Qt support RGB, OpenCv support BGR }else{ cout << "Frame no data" << endl; } QImage image = QImage((uchar*)(frame.data), frame.cols, frame.rows, frame.step, QImage::Format_RGB888); QImage result = image.scaled(800,600).scaled(495,325, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); QGraphicsScene *scene = new QGraphicsScene; scene->addPixmap(QPixmap::fromImage(result)); videoGraphicsview->setScene(scene); videoGraphicsview->show(); cout<<"currentFrame"<<currentFrame<<endl; /*******/ //imshow("MyVideo", frame); //show the frame in "MyVideo" window if(waitKey(delay) == 27 || currentFrame >= frameToStop) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop { cout << "esc key is pressed by user" << endl; stop = true; } //suspendre if( waitKey(delay) >= 0) { waitKey(0); } currentFrame++; progressBar->setValue(currentFrame); //setTrackbarPos("Position", "MyVideo",currentFrame); } //Close video file cap.release(); waitKey(0); }
// refresh ui elements // void BSplineVisDialog::renderScene(QGraphicsScene& scene, bool isPrinter) { scene.clear(); if (ui.showCheckerboard->isChecked()) { RGBAImageType::Pointer image = ImageContainer::CreateBitmap(m_SrcImage, ui.imageOpacity->value()); QPixmap qPixmap = ImageContainer::CreatePixmap(image); scene.addPixmap(qPixmap)->setZValue(-10); } if (ui.showWarpedCheckerboard->isChecked()) { RGBAImageType::Pointer image = ImageContainer::CreateBitmap(m_DstImage, ui.imageOpacity->value()); QPixmap qPixmap = ImageContainer::CreatePixmap(image); scene.addPixmap(qPixmap)->setZValue(-10); } if (ui.showWarpedSlice->isChecked()) { RGBAImageType::Pointer image = ImageContainer::CreateBitmap(m_WarpedSlice, ui.imageOpacity->value()); QPixmap qPixmap = ImageContainer::CreatePixmap(image); scene.addPixmap(qPixmap)->setZValue(-10); } if (m_RefImage.IsNotNull()) { const int gridRes = ui.gridResolution->value(); QPen blackPen = QPen(QColor::fromRgbF(0,0,0,0.5)); blackPen.setWidthF(.1); QPen linePen(QColor::fromRgbF(.5,.5,.5,ui.imageOpacity->value() / 255.0)); if (ui.showCoordinateGrid->isChecked()) { QGraphicsGridItem* originalGrid = new QGraphicsGridItem(); if (isPrinter) { // can printer have alpha value? originalGrid->SetPen(blackPen); } else { originalGrid->SetPen(linePen); } originalGrid->SetResolution(gridRes); originalGrid->SetGrid(gX, gY); scene.addItem(originalGrid); ui.bspView->fitInView(originalGrid, Qt::KeepAspectRatio); } if (ui.showWarpedCoordinateGrid->isChecked()) { QGraphicsGridItem* warpedGrid = new QGraphicsGridItem(); if (isPrinter) { // can printer have alpha value? if (!ui.showNoImage->isChecked()) { blackPen.setColor(QColor::fromRgbF(1, 1, 0)); blackPen.setWidthF(0.2); } warpedGrid->SetPen(blackPen); } else { warpedGrid->SetPen(linePen); } warpedGrid->SetResolution(gridRes); warpedGrid->SetGrid(tX, tY); scene.addItem(warpedGrid); ui.bspView->fitInView(warpedGrid, Qt::KeepAspectRatio); } } if (ui.showDetJacobian->isChecked() && m_DetJacobian.IsNotNull()) { RGBAImageType::Pointer image = ImageContainer::CreateBitmap(m_DetJacobian); QPixmap qDetPixmap = ImageContainer::CreatePixmap(image); scene.addPixmap(qDetPixmap); } if (m_Field.IsNotNull() && ui.showDisplacementField->isChecked()) { FieldIteratorType iter(m_Field, m_Field->GetBufferedRegion()); for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter) { DisplacementFieldType::IndexType idx = iter.GetIndex(); DisplacementFieldType::PointType point; m_Field->TransformIndexToPhysicalPoint(idx, point); VectorType v = iter.Get(); if (v.GetNorm() < 1) { continue; } DisplacementFieldType::PointType point2; point2[0] = point[0] + v[0]; point2[1] = point[1] + v[1]; scene.addLine(point[0], point[1], point2[0], point2[1], QPen(Qt::yellow)); } } if (ui.showWarpedLandmarks->isChecked()) { double sz = ui.landmarkSize->value(); for (int i = 0; i < m_WarpedLandmarks.rows(); i++) { double x = m_WarpedLandmarks[i][0]; double y = m_WarpedLandmarks[i][1]; QGraphicsItem* p = scene.addRect(x - sz, y - sz, sz*2, sz*2, QPen(Qt::yellow), QBrush(Qt::yellow, Qt::SolidPattern)); } } // drawing order is important for correct pick up // only show when showLandmarks is checked // if (ui.showLandmarks->isChecked()) { double sz = ui.landmarkSize->value(); for (int i = 0; i < m_VectorList.size(); i++) { QRectF& xy = m_VectorList[i]; QPen linePen(Qt::yellow); QPen sourcePen(Qt::red); QBrush sourceBrush(Qt::red, Qt::SolidPattern); QPen targetPen(Qt::blue); QBrush targetBrush(Qt::blue, Qt::SolidPattern); linePen.setWidthF(sz * .5); if (isPrinter) { linePen.setWidthF(sz); linePen.setColor(QColor::fromRgbF(0.3, 0.6, 0.3)); } scene.addLine(xy.left(), xy.top(), xy.right(), xy.bottom(), linePen); QGraphicsItem* dx = scene.addEllipse(xy.left() - sz, xy.top() - sz, sz*2, sz*2, sourcePen, sourceBrush); QGraphicsItem* dy = scene.addEllipse(xy.right() - sz, xy.bottom() - sz, sz*2, sz*2, targetPen, targetBrush); dx->setData(1, i); dy->setData(2, i); } } }
void frmBoxes::on_actionLoad_SAV_triggered() { SaveFileName = QFileDialog::getOpenFileName(this,tr("Load a SAV file"),tr(""),tr("SAV Files (*.sav)")); if(SaveFileName != "") { boxViewer = this; SavDecrypted = false; read(SaveFileName.toStdString().c_str(),sav); cursavblock = &(sav->cur); baksavblock = &(sav->bak); this->setWindowTitle(wTitle + QString::fromStdString(" - ") + QString::fromStdWString(getwstring(cursavblock->trainername))); QGraphicsScene * partyscene = new QGraphicsScene(); for(int i = 0; i < 6; i++) { pix = QPixmap(); partyscene = new QGraphicsScene(); partyscene->addPixmap(pix); partygraphics[i]->setScene(partyscene); } for(uint32 pslot = 0; pslot < cursavblock->party.size; pslot++) { decryptpkm(&(cursavblock->party.pokemon[pslot])); pix = getpkmicon(cursavblock->party.pokemon[pslot].pkm_data); partyscene = new QGraphicsScene(); partyscene->addPixmap(pix); partygraphics[pslot]->setScene(partyscene); partygraphics[pslot]->installEventFilter(mouseEventEater); } for(uint32 pslot = 0; pslot < baksavblock->party.size; pslot++) { decryptpkm(&(baksavblock->party.pokemon[pslot])); } if(ui->cbBoxes->count() == 0) { for(int i = 0; i < 24; i++) { ui->cbBoxes->addItem(""); } } for(int boxnum = 0; boxnum < 24; boxnum++) { ui->cbBoxes->setItemText(boxnum,QString::fromStdWString(getwstring(cursavblock->boxnames[boxnum]))); for(int boxslot = 0; boxslot < 30; boxslot++) { decryptpkm(&(cursavblock->boxes[boxnum].pokemon[boxslot])); decryptpkm(&(baksavblock->boxes[boxnum].pokemon[boxslot])); } } SavDecrypted = true; ui->sbBoxIncrem->setEnabled(true); ui->sbBoxIncrem->setVisible(true); ui->saBoxes->setEnabled(true); ui->saBoxes->setVisible(true); ui->cbBoxes->setEnabled(true); ui->sbBoxIncrem->setValue(cursavblock->curbox); frmParty = &(cursavblock->party); for(int ic = 0; ic < 24; ic++) { boxpreviewgraphics[ic]->installEventFilter(mouseEventEater); boxpreviewgraphics[ic]->viewport()->setMouseTracking(true); boxpreviewgraphics[ic]->viewport()->setProperty("Index",ic); boxpreviewgraphics[ic]->viewport()->installEventFilter(mouseEventEater); } changebox(cursavblock->curbox); } }