2010-10-13 175 views
0

我正在使用Microsoft Visual C++ 6.0和Microsoft Visual Studio 2008开发学术计算机视觉项目。cvblob在Visual C++ 6.0中编译错误

在这个项目中,我需要使用OpenCV 1.1(http://opencv.willowgarage.com/)和CvBlob(http://code.google.com/p/cvblob/)。

我试图用Microsoft Visual Studio 2008编译这个项目,它编译没有错误。

随着Visual C++ 6.0我得到了很多错误。

对于这种行为,OpenCV不负责,因为一个只有OpenCV(没有CvBlob)的平凡项目效果很好。

为了更好地理解错误,我做了一个只包含CvBlob的空项目。

我这里粘贴错误的简短摘要:

cvcontour.cpp(253) : error C2371: 'i' : redefinition; different basic types (and others similar to this. i solved with variable redefinition, every time) 

cvcontour.cpp(318) : error C2664: 'thiscall std::vector<struct CvPoint,class std::allocator<struct CvPoint> >::std::vector<struct CvPoint,class std::allocator<struct CvPoint> >(unsigned int,const struct CvPoint &,const class std::allocator<struct CvPoint> &)' : cannot convert parameter 1 from 'class std::deque<struct CvPoint,class std::allocator<struct CvPoint> >::iterator' to 'unsigned int' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 

cvtrack.cpp(278) : error C2440: 'initializing' : cannot convert from 'struct cvb::CvTrack *const ' to 'struct cvb::CvBlob *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 

你有我如何能解决这些问题的想法?

在此先感谢您的帮助!

-------- -------- UPDATE

我试图以elminate我的问题的三个错误编辑和纠正代码。

错误C2664似乎是更难cirmumvent ...

我已经更换了起诉线

return new CvContourPolygon(dq.begin(), dq.end()); 

其中CvContourPolygon是typedef std::vector<CvPoint> CvContourPolygon;

deque<int>::iterator dq_it;dq_it = dq.begin(); 
CvContourPolygon v_tmp; 
v_tmp.push_back(*dq_it); 
while (dq_it != dq.end()){ 
    v_tmp.push_back(*dq_it++); 
} 

首先,我写的是正确的?比,我该如何解决由此发生的错误?

预先感谢您!

错误(假设第一行是318:

cvcontour.cpp(319) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::deque<struct CvPoint,class std::allocator<struct CvPoint> >::iterator' (or 
there is no acceptable conversion) 
cvcontour.cpp(321) : error C2664: 'push_back' : cannot convert parameter 1 from 'int' to 'const struct CvPoint &' 
    Reason: cannot convert from 'int' to 'const struct CvPoint' 
    No constructor could take the source type, or constructor overload resolution was ambiguous 
cvcontour.cpp(322) : error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::deque<struct CvPoint,class std::allocator<struct CvPoint> >::iterator' (or there is no acceptable conversion) 
cvcontour.cpp(322) : fatal error C1903: unable to recover from previous error(s); stopping compilation 

执行cl.exe时出错

-------- -------- UPDATE2

此代码似乎正常工作

deque<CvPoint>::iterator dq_it; 
dq_it = dq.begin(); 
CvContourPolygon v_tmp; 
for (dq_it = dq.begin(); dq_it != dq.end(); ++dq_it){ 
    v_tmp.push_back(*dq_it); 
} 
//return new CvContourPolygon(dq.begin(), dq.end()); 
return &v_tmp; 
+2

有没有很好的理由你想使用VC 6.0?如果可以的话,避免它(你可以;你有MSVC 9.0)。 – rubenvb 2010-10-13 15:30:09

+0

是的,有一个很好的理由!在我的电脑我有MSVS2008和所有的代码运作良好!但在学术PC中,我无法选择IDE和编译器,并且有MSVC++ 6.0!所以,不幸的是 ,我必须在这个环境中编译我的代码... – Sbaush 2010-10-14 10:36:02

回答

3

C2371 - VC 6与局部变量的范围sl sl。应该能够通过使代码明确地使用变量名来解决这个问题。

C2664 - 看起来像使用deque迭代器初始化矢量失败 - vector :: vector()被调用的错误超载?可能必须通过手动将deque元素以某种方式复制到新的矢量来解决此问题。

C2440 - 检查对象是否兼容(VS2008似乎认为如此)并添加相应的强制转换。编辑: 不应该你的代码是这样吗?

deque<CVPoint>::iterator dq_it;dq_it = dq.begin(); 
CvContourPolygon v_tmp; 
for (dq_it = dq.begin(); dq_it != dq.end(); ++dq_it) 
{ 
    v_tmp.push_back(*dq_it); 
} 
+0

好吧,我会尽力做这些改变......我希望我永远不必更改库代码太多,因为我不是CvBlob的原作者! – Sbaush 2010-10-14 10:39:34

+0

@Sbaush - 如果可能的话,最好的方法就是让VC6下车。这是非常过时的。您可以免费获得VC10,如Visual C++ 2010 Express Edition。 – 2010-10-14 10:43:10

+0

我更新了原始文章,其中包含更正内容和新错误。你能帮我吗?先谢谢你! – Sbaush 2010-10-15 11:35:19