-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathShowCornersVideoFilter.cpp
59 lines (45 loc) · 2.02 KB
/
ShowCornersVideoFilter.cpp
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
#include "ShowCornersVideoFilter.h"
#include <QPainter>
#include <QDebug>
#include <QDateTime>
#include <QGuiApplication>
#include <QScreen>
#include "VideoFrame.h"
#include "QVideoFrameToQImage.h"
#include "QImagePainter.h"
ShowCornersVideoFilter::ShowCornersVideoFilter( QObject* parent )
: QAbstractVideoFilter( parent )
{
}
QVideoFilterRunnable* ShowCornersVideoFilter::createFilterRunnable()
{
return new ShowCornersVideoFilterRunnable( this );
}
ShowCornersVideoFilterRunnable::ShowCornersVideoFilterRunnable( ShowCornersVideoFilter* filter ) :
m_Filter( filter )
{
}
QVideoFrame ShowCornersVideoFilterRunnable::run( QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags )
{
Q_UNUSED( flags )
if ( !input )
{
return QVideoFrame();
}
int videoOutputOrientation = m_Filter->m_VideoOutputOrientation;
QImage image = QVideoFrameToQImage( *input );
int w = ( videoOutputOrientation == 0 || videoOutputOrientation == 180 ) ? image.width() : image.height();
int h = ( videoOutputOrientation == 0 || videoOutputOrientation == 180 ) ? image.height() : image.width();
QImagePainter painter( &image, input, surfaceFormat, videoOutputOrientation );
painter.setFont( QFont("Arial", 10 ) );
painter.setPen( Qt::white );
painter.fillRect( QRect( 0, 0, 24, 24 ), QColor( Qt::GlobalColor::red ) );
painter.drawText( QRect( 0, 0, 24, 24 ), Qt::AlignCenter, QStringLiteral( "1" ) );
painter.fillRect( QRect( w-1 - 24, 0, 24, 24 ), QColor( Qt::GlobalColor::darkGreen ) );
painter.drawText( QRect( w-1 - 24, 0, 24, 24 ), Qt::AlignCenter, QStringLiteral( "2" ) );
painter.fillRect( QRect( w-1 - 24, h-1 - 24, 24, 24 ), QColor( Qt::GlobalColor::darkGreen ) );
painter.drawText( QRect( w-1 - 24, h-1 - 24, 24, 24 ), Qt::AlignCenter, QStringLiteral( "3" ) );
painter.fillRect( QRect( 0, h-1 - 24, 24, 24 ), QColor( Qt::GlobalColor::blue ) );
painter.drawText( QRect( 0, h-1 - 24, 24, 24 ), Qt::AlignCenter, QStringLiteral( "4" ) );
return image;
}