0

我正在使用SparseMatofCV_32FC3并正在尝试执行以下操作:

int dims = 2;
    int size[] = {10,10};
    SparseMat m = SparseMat(dims, size, CV_32FC3);
    m.ref<Vec3f>(2,5)[0] = 0.5;
    m.ref<Vec3f>(2,5)[0] = 0.5;
    m.ref<Vec3f>(2,5)[0] = 0.5;

    if(m.find(2,6) == m.end()){
        cout << " could not find 2,6" << endl;
    }
    if(m.find(2,5) != m.end()){
        cout << "found 2, 5" << m.ref<Vec3f>(2,5)[0] << ", " << .ref<Vec3f>(2,5)[1] << ", " << .ref<Vec3f>(2,5)[2] << endl;
    }

但是,查找部分不正确,我如何使用它来检查该索引处的元素是否已添加到稀疏垫中?

谢谢

4

1 回答 1

1

根据SparseMat::ptr的定义:

C++: uchar* SparseMat::ptr(int i0, int i1, bool createMissing, size_t* hashval=0)

返回指向矩阵元素的指针。如果元素存在(非零),则返回指向它的指针。如果它不存在并且 createMissing=false,则返回 NULL 指针。如果它不存在并且 createMissing=true,则创建新元素并用 0 初始化。返回指向它的指针。如果可选的 hashval 指针不为 NULL,则不计算元素哈希值,而是采用 hashval。

所以在你的代码中

m.find(2,6) == m.end()
m.find(2,5) != m.end()

应该

m.ptr(2,6,false) == NULL
m.ptr(2,5,false) != NULL
于 2013-06-19T08:09:35.403 回答