我也想知道在C语言中包装OpenCV的C ++接口然后将其包装在Lisp中的可能性,所以我可以将所有的C ++功能添加到我的cl-opencv包装器中,因为我想让它完整...还想知道我是否这样做,我可以在lisp中使用带有C包装器的C ++包装器....如果可以向我展示一个快速的示例程序,如打开的窗口并显示图片功能,仅在c和c ++一起....就像使用cv :: namedWindow而不是cvNamedWindow而所有其他部分都是c .....这里是我尝试下面的程序运行时我只使用cv :: namedWindow但是失败了
shape.cpp:37:32: error: invalid initialization of
reference of type ‘cv::InputArray {aka const cv::_InputArray&}’
from expression of type ‘IplImage* {aka _IplImage*}’In file included from
/usr/local/include/opencv/highgui.h:48:0,
from shape.cpp:4:
/usr/local/include/opencv2/highgui/highgui.hpp:78:19: error:
in passing argument 2 of ‘void cv::imshow(const string&, cv::InputArray)’
Compilation exited abnormally with code 1 at Thu Sep 26 21:18:00
当我添加cv :: imshow
时 #include <cv.h>
#include <highgui.h>
using namespace std;
int main(){
CvCapture* capture =0;
capture = cvCaptureFromCAM(0);
if(!capture){
printf("Capture failure\n");
return -1;
}
IplImage* frame=0;
cv::namedWindow("Video");
// cout << "colorModel = " << endl << " " << size << endl << endl;
while(true){
frame = cvQueryFrame(capture);
if(!frame) break;
frame=cvCloneImage(frame);
cv::imshow("Video", frame );
cvReleaseImage(&frame);
//Wait 50mS
int c = cvWaitKey(10);
//If 'ESC' is pressed, break the loop
if((char)c==27 ) break;
}
cvDestroyAllWindows() ;
cvReleaseCapture(&capture);
return 0;
}
我想知道它是否可行......就像我开始之前100%确定一样,我至少可以用c包装每个c ++函数并用lisp包装它。如果你认为id运行陷入某些地方的障碍甚至是不可能.....并且还会将它包裹两次使其变慢?并且比c ++更好/更差地识别c接口..或者我可以在c ++接口中完成所有内容我可以在c ++中
我问这个是因为在swig和cffi文档中它说c ++支持不完整。
哦是的,我也尝试使用所有这些标题运行上面的代码
#include <cv.h>
#include <highgui.h>
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
仍然出现以上错误
答案 0 :(得分:1)
来自the OpenCV documentation,InputArray
是
可以从Mat,Mat_,Matx,std :: vector,std :: vector&gt;构造的类或std :: vector。它也可以用矩阵表达式构建。
您正在尝试传递IplImage
,其中InputArray
是必需的,但这是不允许的。
你可以用
cvShowImage("Video", frame);
或者将您的IplImage
转换为Mat
并将其传递给imshow()
:
IplImage* frame;
// write to frame
...
// convert to cv::Mat and show the converted image
cv::Mat mat_frame(frame);
cv::imshow("Video", mat_frame)
更好的是根本不使用IplImage,它是遗留API的一部分。垫子是首选。
cv::VideoCapture capture;
capture.open(0);
cv::Mat frame;
cv::namedWindow("Video");
if (capture.isOpened()) {
while (true) {
capture >> frame;
if (!frame.empty()) {
cv::imshow("Video", frame);
int c = cv::waitKey(10);
if ((char) c == 27) {
break;
}
}
}
}
从理论上讲,你可以编写一些包装器来允许从Lisp CFFI调用,但它可能不值得花时间和痛苦。我将用C ++编写应用程序的OpenCV部分,然后使用C / CFFI从Lisp调用它。