Subversion Repositories seema-scanner

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
256 - 1
#include <QCoreApplication>
2
#include <QDir>
3
 
4
#include "SMExportWorker.h"
5
#include "cvtools.h"
6
 
7
#define PNG_COMPRESSION_LEVEL 1
8
// Level from 0 - 9 (lowest to highest)
9
// 1 is default, 9 is *very slow*
10
 
11
void SMExportWorker::abort() {
12
    was_aborted = true;
13
}
14
void SMExportWorker::exportFrameSequence(QString path, SMFrameSequence seq) {
15
    paths.push_back(path);
16
    seqs.push_back(seq);
17
}
18
 
19
void SMExportWorker::work() {
20
    if (working)
21
        return;
22
 
23
    working = true;
24
 
25
    std::vector<int> compression_params;
26
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
27
    compression_params.push_back(PNG_COMPRESSION_LEVEL);
28
 
29
    while(seqs.size() > 0) {
30
        QString path = paths.front(); paths.pop_front();
31
        SMFrameSequence seq = seqs.front(); seqs.pop_front();
32
 
33
        if (seq.frames0.size() == 0 || path == QString()) {
34
            emit aborted();
35
            continue;
36
        }
37
 
38
        path = QString("%1/sequence_%2").arg(path).arg(seq.id);
39
 
40
        if(!QDir().mkdir(path))
41
            std::cerr << "Could not create directory " << path.toStdString() << std::endl;
42
 
43
        bool HDR = (seq.frames0[0].depth() == CV_32F);
44
        QString format;
45
        if (HDR) format = "hdr";
46
        else format = "png";
47
 
48
        cv::Mat frameBGR;
49
        for(unsigned int i=0; i < seq.frames0.size(); ++i){
50
 
51
            emit progressUpdate(100.0 * i / seq.frames0.size());
52
 
53
            QString fileName0 = QString("%1/frames0_%2.%3").arg(path).arg(i).arg(format);
54
            QString fileName1 = QString("%1/frames1_%2.%3").arg(path).arg(i).arg(format);
55
 
56
            // Convert rgb (png needs BGR order)
57
            if (HDR) {
58
                cv::cvtColor(seq.frames0[i], frameBGR, CV_RGB2BGR);
59
                cv::imwrite(fileName0.toStdString(), frameBGR, compression_params);
60
 
61
                cv::cvtColor(seq.frames1[i], frameBGR, CV_RGB2BGR);
62
                cv::imwrite(fileName1.toStdString(), frameBGR, compression_params);
63
            }
64
            else {
65
                cv::cvtColor(seq.frames0[i], frameBGR, CV_BayerBG2BGR);
66
                cv::imwrite(fileName0.toStdString(), frameBGR, compression_params);
67
 
68
                cv::cvtColor(seq.frames1[i], frameBGR, CV_BayerBG2BGR);
69
                cv::imwrite(fileName1.toStdString(), frameBGR, compression_params);
70
            }
71
 
72
            // Necessary to enable aborting!
73
            QCoreApplication::processEvents();
74
            if (was_aborted) {
75
                emit aborted();
76
                was_aborted = false;
77
                working = false;
78
                return;
79
            }
80
        }
81
 
82
        emit finished(seq.id);
83
        QCoreApplication::processEvents();
84
    }
85
    working = false;
86
}
87