【发布时间】:2015-07-26 10:37:47
【问题描述】:
我正在尝试学习 C 和 OpenCV。我正在使用以下代码,其灵感来自 O'Reilly Learning OpenCV,但出现错误并且图像未按预期显示。这段代码有问题吗?
# include "cv.h"
# include "highgui.h"
IplImage * doCanny(IplImage *in, double lowThresh, double highThresh, int aperture) {
if(1 != in->nChannels){
return 0;
}
IplImage *out = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
cvCanny(in, out, lowThresh, highThresh, aperture);
return out;
}
/* This layout works with other functions like cvPyrdown, but for some reason it doesn't work with cvCanny */
int main() {
double lowThresh = 50;
double highThresh = 150;
int aperture = 3;
IplImage *img = cvLoadImage("/tmp/lena.jpg", CV_LOAD_IMAGE_UNCHANGED);
IplImage *out = doCanny(img, lowThresh, highThresh, aperture);
cvNamedWindow("Example2-6", CV_LOAD_IMAGE_UNCHANGED);
cvShowImage("Example2-6", out);
cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&out);
cvDestroyWindow("Example2-6");
return 0;
}
我在 Mac OS X Yosemite 上得到的输出是:
OpenCV 错误:cvGetMat 中的空指针(传递了空数组指针),文件 /opt/local/var/macports/build/.../opencv-2.4.11/.../array.cpp,第 2382 行
【问题讨论】:
-
请使用 opencv 的 c++ api,不要使用过时的,不再维护的 c-api