cout < cv :: Mat:没有匹配的'operator&lt;&lt;' [英] cout &lt;&lt; cv::Mat : no match for ‘operator&lt;&lt;’

查看:287
本文介绍了cout < cv :: Mat:没有匹配的'operator&lt;&lt;'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在opencv中使用kmeans,我发现这个小例子:

i have to use kmeans in opencv and i've found this little example:

(正确的例子)

#include <iostream>
#include <stdio.h>

#include "cv.h"
#include "highgui.h"

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{

    cout << "." << endl;

    float pointsdata[] = { 1,1, 2,2, 6,6, 5,5, 10,10, 3,3, 2,8};
    Mat points(7, 1, CV_32F, pointsdata);
    Mat labels;
    Mat centers(3, 1, points.type());;

    cout << "points:\n" << points << endl;
    kmeans(points, 3, labels, TermCriteria(CV_TERMCRIT_EPS, 1000, 0), 
            1000, KMEANS_RANDOM_CENTERS, &centers);

    cout << "dudee" << endl;

    cout << "labels: " << labels << endl;
    cout << "centers " << centers << endl;

}

并且编译它:


g ++ -I / usr / include / opencv -lcv -lcxcore -lcvaux -lhighgui -lm m.cpp

g++ -I/usr/include/opencv -lcv -lcxcore -lcvaux -lhighgui -lm m.cpp

但我得到一个很长的错误。这是开始:

but i get a really long error. this is the beginning:

m.cpp: In function ‘int main(int, char**)’:
m.cpp:26: error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"labels: ")) << labels’
/usr/include/c++/4.4/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:117: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:127: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:165: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:169: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]



编辑:



对不起,我的程序有一个错误我知道std :: cout和std :: endl stuffs,它是一个类型错误!

sorry there was an error on copy my program i am aware of std::cout and std::endl stuffs, it was a type error!!

如果我打印CV_MAJOR_VERSION它说:2
如果我运行这个例子没有最后cout它去细分失败

if i print CV_MAJOR_VERSION it says: 2 if i run this example without final cout it goes in Segmentation fault

我已解决安装opencv。现在它工作。我也纠正问题os segfault

i resolved installing again opencv. now it works. And i also correct the problem os segfault

推荐答案

为什么你不 #include opencv2 / opencv。 hpp 而不是 cxcore.h ?或至少 core.hpp

Why don't you #include opencv2/opencv.hpp instead of cxcore.h? Or at least core.hpp

这篇关于cout < cv :: Mat:没有匹配的'operator&lt;&lt;'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆