我最近在 OSX 上开始了一些 OpenCV 编程(仅使用文本编辑器并在终端中编译)。我在互联网上找到了对我非常有用但似乎无法运行的程序。这是代码:
#include <stdio.h>
#include "cv.h"
#include <highgui.h>
#include <iostream>
#include <cstdio>
using namespace std;
int widthU;
int heightU;
int xU = 0;
int yU = 0;
int main(int argc, char *argv[])
{
IplImage *imgPicThres, *imgPicInput;
imgPicInput = cvLoadImage("bitmap.png", -1);
imgPicThres = cvCreateImage(cvSize(imgPicInput->width, imgPicInput->height), IPL_DEPTH_8U, 1);
cvNamedWindow("Input picture", 0);
cvNamedWindow("Thres picture", 0);
//Picture
//cvThreshold(imgPicInput,imgPicThres,100,255,CV_THRESH_BINARY);
cvAdaptiveThreshold(imgPicInput, imgPicThres,255,CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY,75,10);
cvShowImage("Input picture", imgPicInput);
cvShowImage("Thres picture", imgPicThres);
while (true)
{
int c = cvWaitKey(10);
if(c==27)
break;
}
cvDestroyWindow("Input picture");
cvDestroyWindow("Thres picture");
return 0;
}
这是我得到的错误:
OpenCV Error: Assertion failed (src.size == dst.size && src.type() == dst.type()) in cvAdaptiveThreshold, file /opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/opencv/work/opencv-2.4.5/modules/imgproc/src/thresh.cpp, line 873
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
我试图改变这条线
ImgPicThres = cvCreateImage(cvSize(imgPicInput->width, imgPicInput->height), IPL_DEPTH_8U, 1);
进入
ImgPicThres = cvCreateImage(cvGetSize(imgPicInput), IPL_DEPTH_8U, 1);
没有运气。OpenCV 通过 Macports 安装并运行最新版本。任何帮助,将不胜感激。谢谢!