Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "find_object/JsonWriter.h"
00029 #include "find_object/utilite/ULogger.h"
00030
00031 #include <QtCore/QFile>
00032 #include <QtCore/QTextStream>
00033
00034 #include "json/json.h"
00035
00036 namespace find_object {
00037
00038 void JsonWriter::write(const DetectionInfo & info, const QString & path)
00039 {
00040 if(!path.isEmpty())
00041 {
00042 Json::Value root;
00043
00044 if(info.objDetected_.size())
00045 {
00046 Json::Value detections;
00047
00048 QMultiMap<int, int>::const_iterator iterInliers = info.objDetectedInliersCount_.constBegin();
00049 QMultiMap<int, int>::const_iterator iterOutliers = info.objDetectedOutliersCount_.constBegin();
00050 QMultiMap<int, QSize>::const_iterator iterSizes = info.objDetectedSizes_.constBegin();
00051 QMultiMap<int, QString>::const_iterator iterFilenames = info.objDetectedFilenames_.constBegin();
00052 for(QMultiMap<int, QTransform>::const_iterator iter = info.objDetected_.constBegin(); iter!= info.objDetected_.end();)
00053 {
00054 char index = 'a';
00055 int id = iter.key();
00056 while(iter != info.objDetected_.constEnd() && id == iter.key())
00057 {
00058 QString name = QString("object_%1%2").arg(id).arg(info.objDetected_.count(id)>1?QString(index++):"");
00059 detections.append(name.toStdString());
00060
00061 Json::Value homography;
00062 homography.append(iter.value().m11());
00063 homography.append(iter.value().m12());
00064 homography.append(iter.value().m13());
00065 homography.append(iter.value().m21());
00066 homography.append(iter.value().m22());
00067 homography.append(iter.value().m23());
00068 homography.append(iter.value().m31());
00069 homography.append(iter.value().m32());
00070 homography.append(iter.value().m33());
00071 root[name.toStdString()]["width"] = iterSizes.value().width();
00072 root[name.toStdString()]["height"] = iterSizes.value().height();
00073 root[name.toStdString()]["homography"] = homography;
00074 root[name.toStdString()]["inliers"] = iterInliers.value();
00075 root[name.toStdString()]["outliers"] = iterOutliers.value();
00076 root[name.toStdString()]["filename"] = iterFilenames.value().toStdString();
00077
00078 ++iter;
00079 ++iterInliers;
00080 ++iterOutliers;
00081 ++iterSizes;
00082 ++iterFilenames;
00083 }
00084 }
00085 root["objects"] = detections;
00086 }
00087
00088 if(info.matches_.size())
00089 {
00090 Json::Value matchesValues;
00091 const QMap<int, QMultiMap<int, int> > & matches = info.matches_;
00092 for(QMap<int, QMultiMap<int, int> >::const_iterator iter = matches.constBegin();
00093 iter != matches.end();
00094 ++iter)
00095 {
00096 QString name = QString("matches_%1").arg(iter.key());
00097 root[name.toStdString()] = iter.value().size();
00098 matchesValues.append(name.toStdString());
00099 }
00100 root["matches"] = matchesValues;
00101 }
00102
00103
00104 Json::StyledWriter styledWriter;
00105
00106 QFile file(path);
00107 file.open(QIODevice::WriteOnly | QIODevice::Text);
00108 QTextStream out(&file);
00109 out << styledWriter.write(root).c_str();
00110 file.close();
00111 }
00112 }
00113
00114 }