void ImageSegmentor::removeSmallMarkers(int th) { double min, max; cv::minMaxLoc(markersPic,&min,&max); std::vector<int> markerSize(max + 2, 0); // there are pixels with value -1 int nl = markersPic.rows; int nc = markersPic.cols; //only valid for single channel pic! for (int j=0; j<nl; j++) { int* data = markersPic.ptr<int>(j); for (int i=0; i<nc; i++) { markerSize[data[i]+1]++; } } for (int j=0; j<nl; j++) { int* data = markersPic.ptr<int>(j); for (int i=0; i<nc; i++) { int label = data[i]; if (label <= 1) { data[i] = 0; continue; } //set border and bg pixels to zero if (label > 1 && markerSize[label+1] < th) { data[i] = 0; } } } }
int QwtKnob::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QwtAbstractSlider::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< KnobStyle*>(_v) = knobStyle(); break; case 1: *reinterpret_cast< int*>(_v) = knobWidth(); break; case 2: *reinterpret_cast< Qt::Alignment*>(_v) = alignment(); break; case 3: *reinterpret_cast< double*>(_v) = totalAngle(); break; case 4: *reinterpret_cast< int*>(_v) = numTurns(); break; case 5: *reinterpret_cast< MarkerStyle*>(_v) = markerStyle(); break; case 6: *reinterpret_cast< int*>(_v) = markerSize(); break; case 7: *reinterpret_cast< int*>(_v) = borderWidth(); break; } _id -= 8; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setKnobStyle(*reinterpret_cast< KnobStyle*>(_v)); break; case 1: setKnobWidth(*reinterpret_cast< int*>(_v)); break; case 2: setAlignment(*reinterpret_cast< Qt::Alignment*>(_v)); break; case 3: setTotalAngle(*reinterpret_cast< double*>(_v)); break; case 4: setNumTurns(*reinterpret_cast< int*>(_v)); break; case 5: setMarkerStyle(*reinterpret_cast< MarkerStyle*>(_v)); break; case 6: setMarkerSize(*reinterpret_cast< int*>(_v)); break; case 7: setBorderWidth(*reinterpret_cast< int*>(_v)); break; } _id -= 8; } else if (_c == QMetaObject::ResetProperty) { _id -= 8; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 8; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 8; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 8; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 8; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 8; } #endif // QT_NO_PROPERTIES return _id; }
void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation &info ) { QVector<QPointF> data; // set validity flag and status from GPS data // based on GGA, GSA and RMC sentences - the logic does not require all bool validFlag = false; // true if GPS indicates position fix FixStatus fixStatus = NoData; // no fix if any of the three report bad; default values are invalid values and won't be changed if the corresponding NMEA msg is not received if ( info.status == 'V' || info.fixType == NMEA_FIX_BAD || info.quality == 0 ) // some sources say that 'V' indicates position fix, but is below acceptable quality { fixStatus = NoFix; } else if ( info.fixType == NMEA_FIX_2D ) // 2D indication (from GGA) { fixStatus = Fix2D; validFlag = true; } else if ( info.status == 'A' || info.fixType == NMEA_FIX_3D || info.quality > 0 ) // good { fixStatus = Fix3D; validFlag = true; } else // unknown status (not likely) { } // set visual status indicator -- do only on change of state if ( fixStatus != mLastFixStatus ) { setStatusIndicator( fixStatus ); } if ( mStackedWidget->currentIndex() == 1 && info.satInfoComplete ) //signal { mpPlot->setAxisScale( QwtPlot::xBottom, 0, info.satellitesInView.size() ); } //signal #ifdef WITH_QWTPOLAR if ( mStackedWidget->currentIndex() == 2 && info.satInfoComplete ) //satellites { while ( !mMarkerList.isEmpty() ) { delete mMarkerList.takeFirst(); } } //satellites #endif if ( mStackedWidget->currentIndex() == 4 ) //debug { mGPSPlainTextEdit->clear(); } //debug for ( int i = 0; i < info.satellitesInView.size(); ++i ) //satellite processing loop { QgsSatelliteInfo currentInfo = info.satellitesInView.at( i ); if ( mStackedWidget->currentIndex() == 1 && info.satInfoComplete ) //signal { data << QPointF( i, 0 ); data << QPointF( i, currentInfo.signal ); data << QPointF( i + 1, currentInfo.signal ); data << QPointF( i + 1, 0 ); } //signal if ( mStackedWidget->currentIndex() == 2 && info.satInfoComplete ) //satellites { QColor bg( Qt::white ); // moved several items outside of the following if block to minimize loop time bg.setAlpha( 200 ); QColor myColor; // Add a marker to the polar plot if ( currentInfo.id > 0 ) // don't show satellite if id=0 (no satellite indication) { #ifdef WITH_QWTPOLAR QwtPolarMarker *mypMarker = new QwtPolarMarker(); #if (QWT_POLAR_VERSION<0x010000) mypMarker->setPosition( QwtPolarPoint( currentInfo.azimuth, currentInfo.elevation ) ); #else mypMarker->setPosition( QwtPointPolar( currentInfo.azimuth, currentInfo.elevation ) ); #endif #endif if ( currentInfo.signal < 30 ) //weak signal { myColor = Qt::red; } else { myColor = Qt::black; //strong signal } #ifdef WITH_QWTPOLAR QBrush symbolBrush( Qt::black ); QSize markerSize( 9, 9 ); QBrush textBgBrush( bg ); #if (QWT_POLAR_VERSION<0x010000) mypMarker->setSymbol( QwtSymbol( QwtSymbol::Ellipse, symbolBrush, QPen( myColor ), markerSize ) ); #else mypMarker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, symbolBrush, QPen( myColor ), markerSize ) ); #endif mypMarker->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop ); QwtText text( QString::number( currentInfo.id ) ); text.setColor( myColor ); text.setBackgroundBrush( textBgBrush ); mypMarker->setLabel( text ); mypMarker->attach( mpSatellitesWidget ); mMarkerList << mypMarker; #endif } // currentInfo.id > 0 } //satellites } //satellite processing loop if ( mStackedWidget->currentIndex() == 1 && info.satInfoComplete ) //signal { mpCurve->setSamples( data ); mpPlot->replot(); } //signal #ifdef WITH_QWTPOLAR if ( mStackedWidget->currentIndex() == 2 && info.satInfoComplete ) //satellites { mpSatellitesWidget->replot(); } //satellites #endif if ( validFlag ) { validFlag = info.longitude >= -180.0 && info.longitude <= 180.0 && info.latitude >= -90.0 && info.latitude <= 90.0; } QgsPointXY myNewCenter; if ( validFlag ) { myNewCenter = QgsPointXY( info.longitude, info.latitude ); } else { myNewCenter = mLastGpsPosition; } if ( mStackedWidget->currentIndex() == 0 ) //position { mTxtLatitude->setText( QString::number( info.latitude, 'f', 8 ) ); mTxtLongitude->setText( QString::number( info.longitude, 'f', 8 ) ); mTxtAltitude->setText( tr( "%1 m" ).arg( info.elevation, 0, 'f', 1 ) ); // don't know of any GPS receivers that output better than 0.1 m precision if ( mDateTimeFormat.isEmpty() ) { mTxtDateTime->setText( info.utcDateTime.toString( Qt::TextDate ) ); // default format } else { mTxtDateTime->setText( info.utcDateTime.toString( mDateTimeFormat ) ); //user specified format string for testing the millisecond part of time } mTxtSpeed->setText( tr( "%1 km/h" ).arg( info.speed, 0, 'f', 1 ) ); mTxtDirection->setText( QString::number( info.direction, 'f', 1 ) + QStringLiteral( "°" ) ); mTxtHdop->setText( QString::number( info.hdop, 'f', 1 ) ); mTxtVdop->setText( QString::number( info.vdop, 'f', 1 ) ); mTxtPdop->setText( QString::number( info.pdop, 'f', 1 ) ); mTxtHacc->setText( QString::number( info.hacc, 'f', 1 ) + "m" ); mTxtVacc->setText( QString::number( info.vacc, 'f', 1 ) + "m" ); mTxtFixMode->setText( info.fixMode == 'A' ? tr( "Automatic" ) : info.fixMode == 'M' ? tr( "Manual" ) : QLatin1String( "" ) ); // A=automatic 2d/3d, M=manual; allowing for anything else mTxtFixType->setText( info.fixType == 3 ? tr( "3D" ) : info.fixType == 2 ? tr( "2D" ) : info.fixType == 1 ? tr( "No fix" ) : QString::number( info.fixType ) ); // 1=no fix, 2=2D, 3=3D; allowing for anything else mTxtQuality->setText( info.quality == 2 ? tr( "Differential" ) : info.quality == 1 ? tr( "Non-differential" ) : info.quality == 0 ? tr( "No position" ) : info.quality > 2 ? QString::number( info.quality ) : QLatin1String( "" ) ); // allowing for anything else mTxtSatellitesUsed->setText( QString::number( info.satellitesUsed ) ); mTxtStatus->setText( info.status == 'A' ? tr( "Valid" ) : info.status == 'V' ? tr( "Invalid" ) : QLatin1String( "" ) ); } //position // Avoid refreshing / panning if we haven't moved if ( mLastGpsPosition != myNewCenter ) { mLastGpsPosition = myNewCenter; // Pan based on user specified behavior if ( radRecenterMap->isChecked() || radRecenterWhenNeeded->isChecked() ) { QgsCoordinateReferenceSystem mypSRS = mpCanvas->mapSettings().destinationCrs(); QgsCoordinateTransform myTransform( mWgs84CRS, mypSRS ); // use existing WGS84 CRS QgsPointXY myPoint = myTransform.transform( myNewCenter ); //keep the extent the same just center the map canvas in the display so our feature is in the middle QgsRectangle myRect( myPoint, myPoint ); // empty rect can be used to set new extent that is centered on the point used to construct the rect // testing if position is outside some proportion of the map extent // this is a user setting - useful range: 5% to 100% (0.05 to 1.0) QgsRectangle myExtentLimit( mpCanvas->extent() ); myExtentLimit.scale( mSpinMapExtentMultiplier->value() * 0.01 ); // only change the extents if the point is beyond the current extents to minimize repaints if ( radRecenterMap->isChecked() || ( radRecenterWhenNeeded->isChecked() && !myExtentLimit.contains( myPoint ) ) ) { mpCanvas->setExtent( myRect ); mpCanvas->refresh(); } } //otherwise never recenter automatically if ( mCbxAutoAddVertices->isChecked() ) { addVertex(); } } // mLastGpsPosition != myNewCenter // new marker position after recentering if ( mGroupShowMarker->isChecked() ) // show marker { if ( validFlag ) // update cursor position if valid position { // initially, cursor isn't drawn until first valid fix; remains visible until GPS disconnect if ( ! mpMapMarker ) { mpMapMarker = new QgsGpsMarker( mpCanvas ); } mpMapMarker->setSize( mSliderMarkerSize->value() ); mpMapMarker->setCenter( myNewCenter ); } } else { if ( mpMapMarker ) { delete mpMapMarker; mpMapMarker = nullptr; } } // show marker }