Commit 80660cb6 authored by Jussi Lindgren's avatar Jussi Lindgren

Plugins: Fixed Feature Vector encoding not always confirming to stream spec

- Added feature vector decoder test for dimension count
parent 2d3da17a
......@@ -166,14 +166,13 @@ namespace OpenViBEPlugins
l_ui64TotalBufferSize+=l_pInputMatrix->getBufferElementCount();
if(input==l_pStaticBoxContext->getInputCount()-1)
{
l_pOutputMatrix->setDimensionCount(2);
l_pOutputMatrix->setDimensionSize(0, 1);
l_pOutputMatrix->setDimensionSize(1, (uint32)l_ui64TotalBufferSize);
l_pOutputMatrix->setDimensionCount(1);
l_pOutputMatrix->setDimensionSize(0, (uint32)l_ui64TotalBufferSize);
for(uint32 i=0;i<(uint32)l_ui64TotalBufferSize;i++) {
char l_sBuffer[64];
sprintf(l_sBuffer, "Feature %d", (i+1));
l_pOutputMatrix->setDimensionLabel(1, i, l_sBuffer);
l_pOutputMatrix->setDimensionLabel(0, i, l_sBuffer);
}
m_pFeatureVectorEncoder->encodeHeader();
......
......@@ -550,13 +550,12 @@ OpenViBE::boolean CBoxAlgorithmCSVFileReader::process_featureVector(void)
// in this case we need to transpose it
IMatrix* ip_pMatrix=((OpenViBEToolkit::TStreamedMatrixEncoder < CBoxAlgorithmCSVFileReader >*)m_pAlgorithmEncoder)->getInputMatrix();
ip_pMatrix->setDimensionCount(2);
ip_pMatrix->setDimensionSize(0,1);
ip_pMatrix->setDimensionSize(1,m_ui32NbColumn-1);
ip_pMatrix->setDimensionCount(1);
ip_pMatrix->setDimensionSize(0,m_ui32NbColumn-1);
for(uint32 i=1;i<m_ui32NbColumn;i++)
{
ip_pMatrix->setDimensionLabel(1,i-1,m_vHeaderFile[i].c_str());
ip_pMatrix->setDimensionLabel(0,i-1,m_vHeaderFile[i].c_str());
}
m_pAlgorithmEncoder->encodeHeader();
......
......@@ -149,7 +149,7 @@ boolean CBoxAlgorithmCSVFileWriter::process_streamedMatrix(void)
return false;
}
if( l_pMatrix->getDimensionCount() == 1)
if( l_pMatrix->getDimensionCount() == 1 || m_oTypeIdentifier==OV_TypeId_FeatureVector)
{
// The matrix is a vector, make a matrix to represent it
m_oMatrix.setDimensionCount(2);
......@@ -162,22 +162,6 @@ boolean CBoxAlgorithmCSVFileWriter::process_streamedMatrix(void)
m_oMatrix.setDimensionLabel(0,i,l_pMatrix->getDimensionLabel(0,i));
}
}
else if(m_oTypeIdentifier==OV_TypeId_FeatureVector)
{
// OpenViBE matrixes are usually [channels x time], but they get written to the CSV as transposed, i.e. [time X channels].
// The feature stream matrix is [1 X features], but here we transpose it to [features X 1] to compensate and to get
// one-vector-per-row in the output file
m_oMatrix.setDimensionCount(2);
// This [n X 1] will get written as a single row due to transpose later
m_oMatrix.setDimensionSize(0,l_pMatrix->getDimensionSize(1));
m_oMatrix.setDimensionSize(1,1);
for(uint32 i=0;i<l_pMatrix->getDimensionSize(1);i++)
{
// this->getLogManager() << LogLevel_Info << " N: " << i << " is " << l_pMatrix->getDimensionLabel(1,i) << "\n";
m_oMatrix.setDimensionLabel(0,i,l_pMatrix->getDimensionLabel(1,i));
}
}
else
{
// As-is
......
Time(s);
;1
;-1.376622
;0.70467
;-0.466579
;0.152404
;0.227561
;-0.432799
;0.191391
Time (s);Channel 1
0.0000000000e+000;1.0000000000e+000
0.0000000000e+000;-1.3499924204e+000
0.0000000000e+000;7.1548116977e-001
0.0000000000e+000;-4.8823484546e-001
0.0000000000e+000;1.3773934216e-001
0.0000000000e+000;2.4122886822e-001
0.0000000000e+000;-4.1646742087e-001
0.0000000000e+000;1.6024997233e-001
......@@ -7,3 +7,25 @@ using namespace OpenViBE::Plugins;
using namespace OpenViBEPlugins;
using namespace OpenViBEPlugins::StreamCodecs;
void CFeatureVectorDecoder::openChild(const EBML::CIdentifier& rIdentifier)
{
m_oTop = rIdentifier;
CStreamedMatrixDecoder::openChild(rIdentifier);
}
void CFeatureVectorDecoder::processChildData(const void* pBuffer, const EBML::uint64 ui64BufferSize)
{
// Check for conforming dimension count, then pass to matrix decoder
if(m_oTop==OVTK_NodeId_Header_StreamedMatrix_DimensionCount)
{
const uint32 l_ui32DimensionCount = (uint32)m_pEBMLReaderHelper->getUIntegerFromChildData(pBuffer, ui64BufferSize);
if(l_ui32DimensionCount!=1)
{
this->getLogManager() << LogLevel_Warning << "Trying to decode a feature vector with more than 1 dimension (" << l_ui32DimensionCount << "). The stream does not seem to conform to specification.\n";
}
}
CStreamedMatrixDecoder::processChildData(pBuffer, ui64BufferSize);
}
\ No newline at end of file
......@@ -13,7 +13,14 @@ namespace OpenViBEPlugins
virtual void release(void) { delete this; }
virtual void openChild(const EBML::CIdentifier& rIdentifier);
virtual void processChildData(const void* pBuffer, const EBML::uint64 ui64BufferSize);
_IsDerivedFromClass_Final_(OpenViBEPlugins::StreamCodecs::CStreamedMatrixDecoder, OVP_ClassId_Algorithm_FeatureVectorStreamDecoder);
private:
EBML::CIdentifier m_oTop;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment