OpenCV 2.4.2 Compile Issues in "operations.hpp" - c++

I am trying to install openCV 2.4.2 on Windows x64 and Netbeans. I have followed the following guide: http://projectsfromhellandmore.blogspot.co.nz/2012/06/opencv-241-netbeans-windows-7-plus.html
When I try to compile the sample code included in the guide I get the following errors for the following blocks of code in the file "include/opencv2/core/operations.hpp" and I have not found any fixes or figured out how to fix it myself:
template<typename _Tp, typename _Base> inline void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
Ptr<_Tp>& value, bool readOnly, Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&),
const string& help)
{
//TODO: static assert: _Tp inherits from _Base
addParam_(algo, parameter, ParamType<_Base>::type, &value, readOnly,
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
}
error: got 2 template parameters but 1 required
And the second block of code with an error is:
template<typename _Tp> inline void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
Ptr<_Tp>& value, bool readOnly, Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&),
const string& help)
{
//TODO: static assert: _Tp inherits from Algorithm
addParam_(algo, parameter, ParamType<Algorithm>::type, &value, readOnly,
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
}
error: redefinition of ...(the function in the first block of code)
Any help would be greatly appreciated thanks

I faced the same problem with MinGW with opencv2.4.x and later on found out that there was nothing wrong with the operations.hpp file. Instead, the MinGW compiler that i had installed was at fault. I reinstalled the compiler from sourcefourge and it worked. Check your netbeans compiler.

I faced the same problem. the solution to this problem is just comment out the entire template inline function. this function is declared twice just below one another thats why the issue. just comment out one of them.

Related

Eigen 3.3.4 compilation error on MIPS Compiler (C++98)

I compile Eigen 3.3.4 under Multi-2000 (Green Hill) MIPS C++ compiler.
After I solved some align macro issue in Macros.h, I met a problem again for some template expression.
Find the Error Details as below. I know it should be some issue for my old C++ compiler, but anyone whom can propose an work around it will be greatly appreciated.
"C:\Eigen/Eigen/src/Core/util/Meta.h", line 389
: error:
expression must have pointer-to-class type
template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()())>0)>::type * =
0);
^
"C:\Eigen/Eigen/src/Core/util/Meta.h", line 389
: error:
incomplete type is not allowed
template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()())>0)>::type * =
0);
^
So The Problem must be inside expression as below. But I really can not figure it out.
template <typename C> static meta_yes testFunctor(C const *,typename enable_if<(sizeof(return_ptr<C>()->operator()())>0)>::type * = 0);
Update 8/25-> whether "typename enable_if" cause this?

Opencv Logistic Regression load failed

I am using opencv's cv::ml::LogisticRegression class and have serialized it and saved it to file using the cv::Algorithm::save method, and am trying to load the file back into a Ptr<LogisticRegression> using cv::ml::LogisticRegression::load, as described in the documentation, my save code looks like this:
Ptr<cv::ml::LogisticRegression> logisReg = logisticRegression(features_train, labels_train);
logisReg->save("mFileName");
And load code (different place)
Ptr<cv::ml::LogisticRegression> logisReg = cv::ml::LogisticRegression::load("mFileName", "Logisitic Regression Classifier");
The save code works fine, and the serialized file content makes sense (plain text). However, when I tried to compile the load it, I got this error:
main.cpp:97:5: error: no matching function for call to 'load'
cv::ml::LogisticRegression::load("logisReg.auracle", "Logisitic Regression Classifier");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/opt/opencv3/include/opencv2/core.hpp:3074:44: note: candidate template ignored: couldn't infer template argument '_Tp'
template<typename _Tp> static Ptr<_Tp> load(const String& filename, const String& objname=String())
^
1 error generated.
make: *** [main.o] Error 1
The documentation you give is of version 3.2.0-dev, which has function:
static Ptr<LogisticRegression> load(const String &filepath, const String &nodeName=String())
but version before 3.1 only has an inherited template function:
template<typename _Tp >
static Ptr<_Tp> load (const String &filename, const String &objname=String())
I guess you are using opencv lib version before 3.1, try instantiate the template function explicitly:
load<LogisticRegression>()

Using CCNumber in Cocos2dx applications

I have using the CCNumber repo found here in my Cocos2D-X application. The code
inline int compare(const CCNumber<_typeT>* rhs)
{
return memcmp((void*)&m_type, (void*)&rhs->m_type, sizeof(_typeT));
}
gives me an error
Invalid arguments '
Candidates are:
int memcmp(const void *, const void *, ?)
what am i doing wrong ?
Try following steps:
Clean
Refresh
Rebuild project indexes
Edit:
If this doesn't fix the problem. Try disabling Code Analysis as mentioned here

error: cannot convert ‘int (^)(int)’ to ‘R (^)(T)’ in initialization

I am trying to understand how to best make use of blocks in my templated class.
I have the following code snippet:
template<typename T, typename R>
class MyClass {
public:
typedef R (^Block)(T);
MyClass(Block blk) {}
};
void testMyClass() {
MyClass<int,int>::Block blk(^(int arg) {
return 1 + arg;
});
}
When I try to compile this, I get the following error message:
error: cannot convert ‘int (^)(int)’ to ‘R (^)(T)’ in initialization
Am I missing something obvious? Am I trying to do something that is not allowed? GCC accepts the program if I do the same thing without templates.
This is an issue in GCC. I tested your program under LLVM 3 and it compiled just fine.
There are a number of problems in GCC 4.2's implementation of blocks, sometimes they can be worked around by fully qualifying your block declarations ^int(int arg){return 1 + arg;} but in this case it was unable to work around this issue. I would highly recommend moving to use LLVM/Clang for any further work with Obj-C Blocks. Its C++ support is very good these days, especially for C++03 support.

OpenCV - Error C2244

I'm currently on vacation far away from my desktop, however I wanted to practice my c++ in particular with openCV, so I brought my laptop along. Given time and family constraints I didn't get everything set up in time with the libraries before flying.
I've set everything up with regards to VS 2010 as I recall doing on my desktop a while ago, but on compiling the test example on the openCV website (http://opencv.willowgarage.com/wiki/VisualC%2B%2B) I receive the following errors:
Error 3 error C2244: 'cv::Matx<_Tp,,>::diag' : unable to match function definition to an existing declaration C:\Program Files\OpenCV2.2\include\opencv2\core\operations.hpp 372
Error 4 error C2244: 'cv::Matx<_Tp,,>::diag' : unable to match function definition to an existing declaration C:\Program Files\OpenCV2.2\include\opencv2\core\operations.hpp 448
which in turn shows me:
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const Matx<_Tp,MIN(m,n),1>& d)
{
Matx<_Tp,m,n> M;
for(int i = 0; i < MIN(m,n); i++)
M(i,i) = d[i];
return M;
}
template<typename _Tp, int m, int n> inline
Matx<_Tp, MIN(m,n), 1> Matx<_Tp, m, n>::diag() const
{
diag_type d;
for( int i = 0; i < MIN(m, n); i++ )
d.val[i] = val[i*n + i];
return d;
}
I've looked into this error on the msdn and have looked on the openCV forums, but I couldn't find record of this specific error and I'm not sure how to resolve it.
Is it also problematic that I'm running the 64 bit version of Windows 7? I read that openCV2.2 is compatible however previously while the programs would compile, it kept on saying the .dll files were missing even though the PATH variable and directories were correct.
Thanks,
Jean-Pierre
I had the same issue running Opencv2.2 on 32bit Win7 VS2010 and QT 4.7.2.
I doesn't seem to be an error that affects the actual function of code. When I turned code analysis off as Himanshu jain described above it fixed the problem.
It seems indeed that the option advanced compiler option "/analyze" causes this problem (I'm using OpenCV 2.2 with VS 2008 on Win XP 32bit). I could fix the first error:
In line 365, you got to replace Matx<_Tp,MIN(m,n),1> with diag_type, i.e. this
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const Matx<_Tp,MIN(m,n),1>& d)
becomes
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const diag_type& d)
Unfortunately, the 2nd error still occurs -- I found no way to get rid of it but to deactivate \analyze :-(
1>D:\OpenCV2.2\include\opencv2/core/operations.hpp(447) : error C2244: 'cv::Matx<_Tp,,>::diag':
unable to match function definition to an existing declaration
If you find a way to fix this, please let me know -- I think I'll go ahead and post a bug-report-ticket on OpenCV Trac now...