gpt4 book ai didi

c++ - OpenCv c++ 为基本打印垫功能创建 C 包装器?

转载 作者:太空宇宙 更新时间:2023-11-04 08:49:57 25 4
gpt4 key购买 nike

我可以像这样创建和打印矩阵:

  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*’

最佳答案

您的返回数据类型是 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);
}

关于c++ - OpenCv c++ 为基本打印垫功能创建 C 包装器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20037449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com