OpenCv c++ 为基本打印垫功能创建一个 C 包装器?
Posted
技术标签:
【中文标题】OpenCv c++ 为基本打印垫功能创建一个 C 包装器?【英文标题】:OpenCv c++ Create a C wrapper for basic print mat function? 【发布时间】:2013-11-17 23:11:23 【问题描述】:我可以像这样创建和打印矩阵:
Mat M(2,2, CV_8UC3, Scalar(0,0,255));
cout << "M = " << endl << " " << M << endl << endl;
我的 C++ 函数的 C 包装是这样的:
Mat* cv_printmat(Mat* mat)
return cout << "Matrix = " << endl << " " << *mat << endl << endl;
不确定从这里去哪里...我需要按原样声明“Mat* mat”...一个不透明的指针 出于我的目的...但收到此错误
In file included from /usr/include/c++/4.8/ios:44:0,
from /usr/include/c++/4.8/istream:38,
from /usr/include/c++/4.8/sstream:38,
from /usr/include/c++/4.8/complex:45,
from /usr/local/include/opencv2/core/cvstd.inl.hpp:48,
from /usr/local/include/opencv2/core.hpp:1256,
from /usr/local/include/opencv2/opencv.hpp:46,
from opencv_generated.hpp:1,
from cl-opencv-glue.cpp:1:
/usr/include/c++/4.8/bits/basic_ios.h:115:7: note:
candidate is: std::basic_ios<_CharT, _Traits>::operator
void*() const [with _CharT = char; _Traits = std::
char_traits<char>] <near match>
operator void*() const
^
/usr/include/c++/4.8/bits/basic_ios.h:115:7: note:
no known conversion for implicit ‘this’ parameter from ‘void*’ to ‘cv::Mat*’
用这个编译:
g++ -Wall -shared -fPIC -o libcl-opencv-glue.so cl-opencv-glue.cpp
任何帮助都非常感谢=)。
编辑...新错误
opencv-glue.cpp :150:58 error:invalid user-defined conversion from
‘std::basic_ostream<char>::__ostream_type aka std
::basic_ostream<char>’ to ‘cv::Mat*’ [-fpermissive]
return cout << "M = " << endl << " " << *mat << endl << endl;
^
In file included from /usr/include/c++/4.8/ios:44:0,
from /usr/include/c++/4.8/istream:38,
from /usr/include/c++/4.8/sstream:38,
from /usr/include/c++/4.8/complex:45,
from /usr/local/include/opencv2/core/cvstd.inl.hpp:48,
from /usr/local/include/opencv2/core.hpp:1256,
from /usr/local/include/opencv2/opencv.hpp:46,
from opencv_generated.hpp:1,
from opencv-glue.cpp:1:
/usr/include/c++/4.8/bits/basic_ios.h:115:7: note: candidate is:
std::basic_ios<_CharT, _Traits>::operator void*() const [with _
CharT = char; _Traits = std::char_traits<char>] <near match>
operator void*() const
^
/usr/include/c++/4.8/bits/basic_ios.h:115:7: note:
no known conversion for implicit ‘this’ parameter from
‘void*’ to ‘cv::Mat*’
【问题讨论】:
只是备注:只要您使用 Mat,这不是 C 包装器。 【参考方案1】:您的返回数据类型是 cv::Mat*,而 std::cout 的返回数据类型是 void*。不确定您的目标是什么,但如果您只是想打印,这应该可以编译。
void cv_printmat(Mat* mat)
cout << "Matrix = " << endl << " " << *mat << endl << endl;
int main(int argc, char* argv[])
cv::Mat M(2,2, CV_8UC3, cv::Scalar(0,0,255));
cv_printmat(&M);
【讨论】:
感谢您的回复....但返回无效时仍然出现错误...关于此错误的任何建议是偶然的以上是关于OpenCv c++ 为基本打印垫功能创建一个 C 包装器?的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 C++ Mat Class ptr 对象的基本 C 包装器打印 Mat 元素