#ifndef PROJECTMODEL_H #define PROJECTMODEL_H #include #include #include #include #include #include #include "Series.h" #include "Segment.h" #include "Episode.h" #include "VideoFrame.h" #include "MovieAnalyzer.h" class ProjectModel: public QAbstractItemModel { Q_OBJECT public: ProjectModel(QObject *parent = 0); ~ProjectModel(); bool save(const QString &fName); bool load(const QString &fName); QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &child = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; Qt::ItemFlags flags(const QModelIndex &index) const; QModelIndex indexFromSegment(Segment *segment) const; int getDepth() const; QModelIndex getShotParentIndex() const; void setModel(const QString &name, const QString &seriesName, int seasNbr, int epNbr, const QString &epName, const QString &epFName); bool appendModel(int seasNbr, int epNbr, const QString &epName, const QString &epFName); bool insertSubtitles(const QString &subFName); bool speakerDiarization(const QString &subFName, VideoFrame::SpeakerSource source); bool localSpkDiar(bool baseline, UtteranceTree::DistType dist, bool norm, UtteranceTree::AgrCrit agr, UtteranceTree::PartMeth partMeth, bool weight, bool sigma); bool globalSpkDiar(); void extractShots(QString fName, int histoType, int nVBins, int nHBins, int nSBins, int metrics, qreal threshold1, qreal threshold2, int nVBlock, int nHBlock, bool iterate); void labelSimilarShots(QString fName, int histoType, int nVBins, int nHBins, int nSBins, int metrics, qreal maxDist, int windowSize, int nVBlock, int nHBlock, bool iterate); qreal evaluateShotDetection(bool displayResults, qreal thresh1, qreal thresh2) const; qreal evaluateSimShotDetection(bool displayResults, qreal thresh1, qreal thresh2) const; int retrieveShotPrevPositions(qint64 position, QList &shotPositions); void reset(); QString getName() const; QString getBaseName() const; QString getSeriesName() const; void setSpkDiar(const QString &epFName); public slots: void setResolution(const QSize &resolution); void setFps(qreal fps); void appendVideoFrame(int id, qint64 position); void initShotLevel(Segment *segment); void insertShot(qint64 position, Segment::Source); void insertShot(Segment *segment, Segment::Source); void removeShot(Segment *segment, Segment::Source source); void processSegmentation(bool checked, bool annot); void retrieveSpeakers(bool checked); void labelSimShot(qint64 position, int nCamera, Segment::Source source); void setSpeaker(qint64 start, qint64 end, const QString &speaker, VideoFrame::SpeakerSource source); void resetSpeaker(qint64 prevStart, qint64 prevEnd, qint64 start, qint64 end, bool resetSub, VideoFrame::SpeakerSource source); void exportSubtitles(const QString &fName); void improveSpkDiar(); void retrieveShotSub(qint64 position); void playSubtitle(QList utter); void playSeg(QList> segments); void currentSub(qint64 position); void extractIVectors(bool ubm, const QString &epFName); void extractSpkIVectors(const QString &epFName, bool refSpk); signals: void modelChanged(); void positionChanged(qint64 position); void truePositive(qint64 position); void falsePositive(qint64 position); void getShot(Segment *shot) const; void segmentationRetrieved(); void getSpokenFrame(qint64 position, const QString &sub, const QString &speaker) const; void viewSegmentation(bool checked, bool annot); void speakersRetrieved(QList speakers); void getCurrentPattern(const QList> &subFeatures); void getPatternFirstShot(const QList> &subFeatures); void getPatternSecondShot(const QList> &subFeatures); void playSegments(QList> utterances); void currentSubtitle(int subIdx); void setDiarData(const arma::mat &E, const arma::mat &Sigma, const arma::mat &W); void setDiarData(const arma::mat &E, const arma::mat &Sigma, const arma::mat &W, QMap>> speakers); private: void eraseSubtitles(Segment *segment); void clearSpeaker(Segment *segment, VideoFrame::SpeakerSource source); bool shotLevelCreated(Segment *segment); Segment * getFirstVideoFrame(Segment *segment); qreal computePrecision(int tp, int fp) const; qreal computeRecall(int tp, int fn) const; qreal computeFScore(qreal precision, qreal recall) const; qreal computeAccuracy(int tp, int fp, int fn, int tn) const; void resetShotsToManual(Segment *segment, QList &toRemove); void resetAutoCameraLabels(Segment *segment); void depthFirstToShots(Segment *segment) const; void depthFirstToSpokenFrames(Segment *segment, VideoFrame::SpeakerSource source) const; void retrieveShotPositions(Segment *segment, QList &shotPositions) const; void retrieveSimCamLabels(Segment *segment, QList &autCamLabels, QList &manCamLabels) const; void nFramesByCamLabel(Segment *segment, QMap> &speakerList, Segment::Source vSource, VideoFrame::SpeakerSource sSource) const; void retrieveSpokenVFrames(Segment *segment, QList &spkVFrames, VideoFrame::SpeakerSource source) const; void retrieveVFrames(Segment *segment, QList &vFrames) const; void retrieveSpeakersList(Segment *segment, QList &speakers, VideoFrame::SpeakerSource source) const; void retrieveShotUtterances(); void retrieveShotPatterns(); void retrieveShotLabels(Segment *segment, QList &shotLabels) const; void retrieveSubPositionsLabels(QList &subStarts, QList &subEnds, QList &subRefLbl) const; bool testShotPattern(const QList &lblWindow, int pattSize); QPair adjustSubBoundaries(qint64 subStart, qint64 subEnd, QList> shotPattBound); QString normalizedPattern(const QString &firstLabel, const QString &secondLabel); QString mergePatterns(QString firstLabel, QString secondLabel, QList> list1, QList> list2, QList> &mergedList); QString completePatternLabel(const QString &label, QMap>> shotPatterns); bool interPatterns(QString firstLabel, QString secondLabel); QStringList appendStringList(const QStringList &list1, const QStringList &list2); void mergePatternBoundaries(QMap>> &shotPattBound); void exportGlobSpkRef(const QString &fName); void exportLocSpkRef(const QString &fName); arma::mat genWMat(QMap> spkIdx, const arma::mat &X); QString m_name; QString m_baseName; Series *m_series; Episode *m_episode; MovieAnalyzer *m_movieAnalyzer; QList> m_subBound; QMap>> m_shotUtterances; QMap>> m_shotPatterns; QMap>> m_shotPattBound; QMap>> m_strictShotPattBound; QList m_subRefLbl; cv::VideoCapture m_cap; arma::mat m_W; }; #endif