source: pacpussensors/trunk/Vislab/DiskWriter.cpp@ 139

Last change on this file since 139 was 138, checked in by ldecherf, 8 years ago

Gestion des output

File size: 2.3 KB
Line 
1
2#include "DiskWriter.h"
3#include <iostream>
4#include <lib3dv-1.2.0/lib3dv/device.h>
5#include <QDir>
6#include <QFile>
7
8const int MAX_LENGTH_NAME = 512;
9
10 /*! A more elaborate description of the constructor*/
11 DiskWriter::DiskWriter(const QString name, lib3dv::image::type::types imageType) : VislabImageProcessor(name, imageType)
12 {
13 QDir directory;
14 /*! For the classic picture */
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 }
26 /*! For the disparity picture */
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
39 /*! process function from the DiskWriter class with a cv:Mat parameter */
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
51 /*! Write of the file on the disk */
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
Note: See TracBrowser for help on using the repository browser.