0
我想使用QSharedMemory製作共享內存。 所以,我想使用QDataStream讀/寫我的自定義類。 但我不知道如何重寫雙指針(float **)。Qt QSharedMemory和QDataStream
(我用的雙指針的原因是OpenCV的簡歷::墊,如果有比我想要什麼更好的辦法,請推薦一下)
class ObservationData
{
private:
int m_nCameras;
cv::Mat** m_matDBRGB;
cv::Mat* m_matQueryRGB;
unsigned char** dbRGB;
unsigned char* queryRGB;
int row, col;
int m_recogIdx;
public:
ObservationData();
~ObservationData();
void setNumCameras(const int nCameras);
int getNumCameras() const;
void setDB_RGB(const unsigned char** rgb);
unsigned char** getDB_RGB() const;
void setQuery_RGB(const unsigned char* rgb);
unsigned char* getQuery_RGB() const;
void setRow(const int row);
void setCol(const int col);
int getRow() const;
int getCol() const;
}
和CPP文件:
void ObservationData::setNumCameras(const int nCameras)
{
this->m_nCameras = nCameras;
}
int ObservationData::getNumCameras() const
{
return this->m_nCameras;
}
void ObservationData::setDB_RGB(const unsigned char** rgb)
{
std::memcpy(this->dbRGB, rgb,
sizeof(unsigned char)
* this->row * this->col * 3 * this->m_nCameras
);
}
unsigned char** ObservationData::getDB_RGB() const
{
return this->dbRGB;
}
void ObservationData::setQuery_RGB(const unsigned char* rgb)
{
std::memcpy(this->queryRGB, rgb,
sizeof(unsigned char)
* this->row * this->col * 3
);
}
unsigned char* ObservationData::getQuery_RGB() const
{
return this->queryRGB;
}
void ObservationData::setRow(const int row)
{
this->row = row;
}
void ObservationData::setCol(const int col)
{
this->col = col;
}
int ObservationData::getRow() const
{
return this->row;
}
int ObservationData::getCol() const
{
return this->col;
}
QDataStream &operator<<(QDataStream &out, const ObservationData &ob)
{
out << ob.getDB_RGB() << ob.getQuery_RGB();
return out;
}
QDataStream &operator>>(QDataStream &in, ObservationData &ob)
{
unsigned char** dbRGB;
unsigned char* queryRGB;
//in >> dbRGB >> queryRGB; ///// ERROR
ob.setDB_RGB(dbRGB);
ob.setQuery_RGB(queryRGB);
return in;
}