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 | /*! A more elaborate description of the constructor*/
|
---|
10 | DiskWriter::DiskWriter(const QString name, lib3dv::image::type::types imageType) : VislabImageProcessor(name, imageType)
|
---|
11 | {
|
---|
12 | QDir directory;
|
---|
13 | /*! For the classic picture */
|
---|
14 | if (imageType == lib3dv::image::type::RIGHT_RECTIFIED)
|
---|
15 | {
|
---|
16 | QString nameBase = getName() + "_Video";
|
---|
17 | if (!directory.exists(nameBase.toLatin1()) && !directory.mkdir(nameBase.toLatin1()))
|
---|
18 | throw std::runtime_error("cannot create the webcam directory");
|
---|
19 | mFilenameTemplate = nameBase + QString("/image-%1.png");
|
---|
20 | mDbtfilename = nameBase + ".dbt";
|
---|
21 | mDBTFile.open(mDbtfilename.toStdString(), WriteMode, FILE_JPEG, MAX_LENGTH_NAME);
|
---|
22 | mImageCounter = mDBTFile.getRecordCount();
|
---|
23 |
|
---|
24 | }
|
---|
25 | /*! For the disparity picture */
|
---|
26 | if (imageType == lib3dv::image::type::DSI)
|
---|
27 | {
|
---|
28 | QString nameBase = getName() + "_Disparite";
|
---|
29 | if (!directory.exists(nameBase.toLatin1()) && !directory.mkdir(nameBase.toLatin1()))
|
---|
30 | throw std::runtime_error("cannot create the webcam directory");
|
---|
31 | mFilenameTemplate = nameBase + QString("/image-%1.png");
|
---|
32 | mDbtfilename = nameBase + ".dbt";
|
---|
33 | mDBTFile.open(mDbtfilename.toStdString(), WriteMode, FILE_JPEG, MAX_LENGTH_NAME);
|
---|
34 | mImageCounter = mDBTFile.getRecordCount();
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | /*! process function from the DiskWriter class with a cv:Mat parameter */
|
---|
39 | void DiskWriter::process(cv::Mat const& frame)
|
---|
40 | {
|
---|
41 | try
|
---|
42 | {
|
---|
43 | QString filename = mFilenameTemplate.arg(mImageCounter);
|
---|
44 | //std::cout << mFilenameTemplate << std::endl;
|
---|
45 | ++mImageCounter;
|
---|
46 |
|
---|
47 | if (!cv::imwrite(filename.toStdString(), frame))
|
---|
48 | throw std::runtime_error("cannot save the following frame: " + filename.toStdString());
|
---|
49 |
|
---|
50 | /*! Write of the file on the disk */
|
---|
51 | mDBTFile.writeRecord(road_time(), 0, filename.toStdString().c_str(), MAX_LENGTH_NAME);
|
---|
52 | }
|
---|
53 | catch (DbiteException & e)
|
---|
54 | {
|
---|
55 | LOG_ERROR("error writing data: " << e.what());
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|