我希望有人可以在这里提供一些帮助。这是我目前坚持的代码的相关部分:
///////////////////////////////////////////////////////////////////////////////////////////////////
void matchBlobs(std::vector<Blob> &existingBlobs, std::vector<Blob> ¤tFrameBlobs) {
for (auto &existingBlob : existingBlobs) {
existingBlob.blnCurrentMatchFoundOrNewBlob = false;
}
for (auto ¤tFrameBlob : currentFrameBlobs) {
int intIndexOfLeastDistance = 0;
double dblLeastDistance = 1000000.0;
for (unsigned int i = 0; i < existingBlobs.size() - 1; i++) {
if (existingBlobs[i].blnStillBeingTracked == true) {
double dblDistance = distanceBetweenBlobs(currentFrameBlob, existingBlobs[i]);
if (dblDistance < dblLeastDistance) {
dblLeastDistance = dblDistance;
intIndexOfLeastDistance = i;
}
}
}
if (dblLeastDistance < currentFrameBlob.dblDiagonalSize * 1.5) {
addBlobToExistingBlobs(currentFrameBlob, existingBlobs, intIndexOfLeastDistance); // !!!! compiler error for 2nd arg on this line !!!!!!!
} else {
addNewBlob(currentFrameBlob, existingBlobs);
}
}
for (auto &existingBlob : existingBlobs) {
if (existingBlob.blnCurrentMatchFoundOrNewBlob == false) {
existingBlob.blnStillBeingTracked = false;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void addBlobToExistingBlobs(Blob ¤tFrameBlob, std::vector<Blob> &existingBlobs, int &intIndex) {
existingBlobs[intIndex].contour = currentFrameBlob.contour;
existingBlobs[intIndex].boundingRect = currentFrameBlob.boundingRect;
existingBlobs[intIndex].ptCurrentCenter = currentFrameBlob.ptCurrentCenter;
existingBlobs[intIndex].dblDiagonalSize = currentFrameBlob.dblDiagonalSize;
existingBlobs[intIndex].dblAspectRatio = currentFrameBlob.dblAspectRatio;
existingBlobs[intIndex].vectorOfAllActualPoints.push_back(currentFrameBlob.ptCurrentCenter);
existingBlobs[intIndex].blnStillBeingTracked = true;
existingBlobs[intIndex].blnCurrentMatchFoundOrNewBlob = true;
}
正如代码中的注释所述,我在这一行上遇到编译器错误:
addBlobToExistingBlobs(currentFrameBlob, existingBlobs, intIndexOfLeastDistance); // !!!! compiler error for 2nd arg on this line !!!!!!!
错误是:
Error C2664 'void addBlobToExistingBlobs(Blob &,Blob &,int &)': cannot convert argument 2 from 'std::vector<Blob,std::allocator<_Ty>>' to 'Blob &' ObjectTrackingCPP c:\users\cdahms\documents\visual studio 2015\projects\objecttrackingcpp2\objecttrackingcpp.cpp 186
有人能说清楚我在这里做错了吗?我可以通过引用找到大量传递一个基本数据类型变量(int,double等)的C ++示例,但我无法找到任何涉及将对象向量传递到一个函数,然后传递到另一个函数的示例。
我正在使用Visual Studio 2015社区附带的编译器,如果这会产生影响,则选择默认选项。
我不确定这里的方向,非常感谢任何帮助。
答案 0 :(得分:1)
从错误消息中看,编译器知道你的函数是
void addBlobToExistingBlobs(Blob&, Blob&, int&);
然而,在你的
的实现中void matchBlobs(std::vector<Blob>&, std::vector<Blob>&);
使用名称为addBlobToExistingBlobs
的函数,但使用不同的原型,即
void addBlobToExistingBlobs(Blob& ,std::vector<Blob>&, int&);
您是否检查过代码中的某个地方,您还没有另一个addBlobToExistingBlobs
函数的原型让编译器感到困惑?