C++ OpenCV错误:cvAdaptiveThreshold中的断言失败
我最近在OSX上开始了一些OpenCV编程(仅使用文本编辑器并在终端中编译)。我在网上找到了一个对我很有用但似乎无法运行的程序。 代码如下:C++ OpenCV错误:cvAdaptiveThreshold中的断言失败,c++,opencv,osx-mountain-lion,libc++,C++,Opencv,Osx Mountain Lion,Libc++,我最近在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
#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;
}
我试着换这条线
ImgPicThres = cvCreateImage(cvSize(imgPicInput->width, imgPicInput->height), IPL_DEPTH_8U, 1);
进入
没有运气。
OpenCV通过Macports安装,并运行最新版本。任何帮助都将不胜感激。谢谢
imgPicInput = cvLoadImage("bitmap.png",CV_LOAD_IMAGE_GRAYSCALE);
为了确保您读取的图像实际上是灰度图像。此外,根据perfanoff的建议,我宁愿克隆图像,也不愿创建它
imgPicThres = cvCloneImage(imgPicInput );
我找到了答案,但忘了提。正如错误所说,imgPicInput和IMGPICThre的大小和类型不同。另外,我本应该在我没有观看的图像频道之后观看。谢谢你们,我会尝试看看会发生什么!非常感谢perfanoff,这个很有用!
imgPicInput = cvLoadImage("bitmap.png",CV_LOAD_IMAGE_GRAYSCALE);
imgPicThres = cvCloneImage(imgPicInput );