0

我想使用 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;
}
4

1 回答 1

0

使用取消引用运算符

例子:

unsigned char** dbRGB;
unsigned char* queryRGB;
in >> *dbRGB; // note the asterisk before 'dbRGB'
于 2016-11-30T17:01:12.207 回答