1 | #include "DiskWriter.h"
|
---|
2 | #include <iostream>
|
---|
3 | #include <lib3dv-1.2.0/lib3dv/device.h>
|
---|
4 | #include <QDir>
|
---|
5 | #include <QFile>
|
---|
6 |
|
---|
7 | const int MAX_LENGTH_NAME = 512;
|
---|
8 |
|
---|
9 | DiskWriter::DiskWriter(const QString name, lib3dv::image::type::types imageType) : VislabImageProcessor(name, imageType)
|
---|
10 | {
|
---|
11 | QDir directory;
|
---|
12 | if (imageType == lib3dv::image::type::RIGHT_RECTIFIED)
|
---|
13 | {
|
---|
14 | QString nameBase = getName() + "_Video";
|
---|
15 | if (!directory.exists(nameBase.toLatin1()) && !directory.mkdir(nameBase.toLatin1()))
|
---|
16 | throw std::runtime_error("cannot create the webcam directory");
|
---|
17 | mFilenameTemplate = nameBase + QString("/image-%1.png");
|
---|
18 | mDbtfilename = nameBase + ".dbt";
|
---|
19 | mDBTFile.open(mDbtfilename.toStdString(), WriteMode, FILE_JPEG, MAX_LENGTH_NAME);
|
---|
20 | mImageCounter = mDBTFile.getRecordCount();
|
---|
21 |
|
---|
22 | }
|
---|
23 | if (imageType == lib3dv::image::type::DSI)
|
---|
24 | {
|
---|
25 | QString nameBase = getName() + "_Disparite";
|
---|
26 | if (!directory.exists(nameBase.toLatin1()) && !directory.mkdir(nameBase.toLatin1()))
|
---|
27 | throw std::runtime_error("cannot create the webcam directory");
|
---|
28 | mFilenameTemplate = nameBase + QString("/image-%1.png");
|
---|
29 | mDbtfilename = nameBase + ".dbt";
|
---|
30 | mDBTFile.open(mDbtfilename.toStdString(), WriteMode, FILE_JPEG, MAX_LENGTH_NAME);
|
---|
31 | mImageCounter = mDBTFile.getRecordCount();
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 |
|
---|
36 | void DiskWriter::process(cv::Mat const& frame)
|
---|
37 | {
|
---|
38 | try
|
---|
39 | {
|
---|
40 | QString filename = mFilenameTemplate.arg(mImageCounter);
|
---|
41 | //std::cout << mFilenameTemplate << std::endl;
|
---|
42 | ++mImageCounter;
|
---|
43 |
|
---|
44 | if (!cv::imwrite(filename.toStdString(), frame))
|
---|
45 | throw std::runtime_error("cannot save the following frame: " + filename.toStdString());
|
---|
46 |
|
---|
47 | mDBTFile.writeRecord(road_time(), 0, filename.toStdString().c_str(), MAX_LENGTH_NAME);
|
---|
48 | }
|
---|
49 | catch (DbiteException & e)
|
---|
50 | {
|
---|
51 | LOG_ERROR("error writing data: " << e.what());
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|