我想使用QSharedMemory创建共享内存。 所以,我试图使用QDataStream读/写我的自定义类。 但我不知道如何覆盖双指针(float **)。
(我使用双指针的原因是因为opencv cv :: Mat,如果有比我想要的更好的方法,请推荐它)
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;
}
答案 0 :(得分:0)
示例:
$isac_start = microtime(true);
$ilog = function ($m) use ($isac_start) {
var_dump($m);
var_dump($isac_start);
};
$ilog('hello');