Blame view
VignetteWidget.cpp
2.64 KB
3f2992b2c
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
#include <QPainter> #include <QDebug> #include <opencv2/imgproc/imgproc.hpp> #include "VignetteWidget.h" #include "Convert.h" using namespace cv; VignetteWidget::VignetteWidget(int nVignettes, int frameWidth, QWidget *parent) : QWidget(parent), m_width(frameWidth / nVignettes), m_height(0), m_shift(0), m_nVignettes(nVignettes), m_currentPosition(-2) { setFixedSize(frameWidth, m_height); } void VignetteWidget::setVideoCapture(const QString &fName) { m_cap.release(); m_cap.open(fName.toStdString()); int frameWidth = m_cap.get(CV_CAP_PROP_FRAME_WIDTH); int frameHeight = m_cap.get(CV_CAP_PROP_FRAME_HEIGHT); m_height = m_width * frameHeight / frameWidth; setFixedSize(width(), m_height); } /////////// // slots // /////////// void VignetteWidget::updateVignette(QList<qint64> positionList) { Mat frame(m_height, m_width, CV_8UC3, Scalar(0, 0, 0)); int step = m_width / 10; qint64 position = positionList[m_nVignettes / 2]; if (m_currentPosition == positionList[m_nVignettes / 2 - 1]) { if (positionList[m_nVignettes - 1] != -1) { m_cap.set(CV_CAP_PROP_POS_MSEC, positionList[m_nVignettes - 1]); m_cap >> frame; cv::resize(frame, frame, Size(m_width, m_height)); } m_vignettes.push_back(Convert::fromBGRMatToQImage(frame)); m_vignettes.pop_front(); m_shift = m_width; while (m_shift > 0) { m_shift -= step; repaint(); } } else if (m_currentPosition == positionList[m_nVignettes / 2 + 1]) { if (positionList[0] != -1) { m_cap.set(CV_CAP_PROP_POS_MSEC, positionList[0]); m_cap >> frame; cv::resize(frame, frame, Size(m_width, m_height)); } m_vignettes.push_front(Convert::fromBGRMatToQImage(frame)); m_vignettes.pop_back(); m_shift = -m_width; while (m_shift < 0) { m_shift += step; repaint(); } } else if (m_currentPosition != position) { m_vignettes.clear(); for (int i(0); i < positionList.size(); i++) { if (positionList[i] != -1) { m_cap.set(CV_CAP_PROP_POS_MSEC, positionList[i]); m_cap >> frame; cv::resize(frame, frame, Size(m_width, m_height)); } m_vignettes.push_back(Convert::fromBGRMatToQImage(frame)); } m_shift = 0; repaint(); } m_currentPosition = position; } void VignetteWidget::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); painter.setPen(Qt::white); for (int i(0); i < m_vignettes.size(); i++) painter.drawImage(QRect(m_width * i + m_shift, 0, m_width, m_height), m_vignettes[i]); for (int i(1); i < m_vignettes.size(); i++) painter.drawLine(m_width * i + m_shift, 0, m_width * i + m_shift, m_height); } |