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