cvblob compile error in Visual C++ 6.0

2019-06-11 23:28发布

I'm using Microsoft Visual C++ 6.0 and Microsoft Visual Studio 2008 to develop an academic computer vision project.

In this project i need to use OpenCV 1.1 (http://opencv.willowgarage.com/) and CvBlob (http://code.google.com/p/cvblob/).

I tried to compile this project with Microsoft Visual Studio 2008 and it compiles without errors.

With Visual C++ 6.0 i got a lot of errors.

OpenCV are not responsible of this behavior, because a trivial project with only OpenCV (without CvBlob) works well.

To understand the errors better I made an empty project with only the CvBlob inclusion.

I paste here a brief summary of the errors:

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

Have you ideas on how can i solve these problems?

Thanks in advance for the help!

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

I tried to edit and correct the code in order to elminate the three errors in my question.

The error C2664 seems to be the more difficult to cirmumvent...

I have replaced the indicted line

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

where CvContourPolygon is a typedef std::vector<CvPoint> CvContourPolygon;

with

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++);
}

First, what that i wrote is correct? Than, how can i solve the errors that occured from this?

Thank you in advance!

Errors (suppose that the first line is 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

Error executing cl.exe.

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

This code seems to work correctly!

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;

1条回答
手持菜刀,她持情操
2楼-- · 2019-06-12 00:00

C2371 - VC6 was sloppy with scope of local variables. Should be able to fix this by making the code use variable names unambiguously.

C2664 - looks like failure to initialize a vector using deque iterators - wrong overload on vector::vector() being called? Probably have to work around this by manually copying the deque elements to the new vector somehow.

C2440 - check the objects are compatible (VS2008 seems to think so) and add the appropriate cast.

EDIT: Shouldn't your code look like this?

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);
}
查看更多
登录 后发表回答