-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cpp
65 lines (58 loc) · 1.46 KB
/
common.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
60
61
62
63
64
65
#include "common.h"
#include <QUuid>
#include <QProcess>
QString createUuid()
{
return QUuid::createUuid().toString() ;
}
QString createSimpleUuid()
{
QString ret = createUuid() ;
ret.chop(1) ;
ret = ret.right(ret.length()-1) ;
return ret ;
}
int getMSec(QTime t)
{
int ret = t.hour()*3600 ;
ret += t.minute()*60 ;
ret += t.second() ;
ret = ret*1000+t.msec() ;
return ret ;
}
QTime getTime(int msec)
{
int s = msec/1000 ;
msec %= 1000 ;
int h = s/3600 ;
s %= 3600 ;
int m = s/60 ;
s%=60 ;
return QTime(h,m,s,msec) ;
}
QImage Mat2QImage(cv::Mat const& src)
{
cv::Mat temp; // make the same cv::Mat
cvtColor(src, temp,CV_BGR2RGB); // cvtColor Makes a copt, that what i need
QImage dest((const uchar *) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
dest.bits(); // enforce deep copy, see documentation
// of QImage::QImage ( const uchar * data, int width, int height, Format format )
return dest;
}
cv::Mat QImage2Mat(QImage const& qimage)
{
cv::Mat mat = cv::Mat(qimage.height(), qimage.width(), CV_8UC4, (uchar*)qimage.bits(), qimage.bytesPerLine());
cv::Mat mat2 = cv::Mat(mat.rows, mat.cols, CV_8UC3 );
int from_to[] = { 0,0, 1,1, 2,2 };
cv::mixChannels( &mat, 1, &mat2, 1, from_to, 3 );
return mat2;
}
void runProcess( QObject* parent, QString path, QStringList arg )
{
QProcess *myProcess = new QProcess(parent);
myProcess->start(path,arg);
if (myProcess->waitForStarted(-1)) {
while(myProcess->waitForReadyRead(-1)) {
}
}
}