[英]OpenCV Error: Assertion failed in cvAdaptiveThreshold
I recently started some OpenCV programming on OSX (just using text editor and compiling in terminal). 我最近在OSX上开始了一些OpenCV编程(仅使用文本编辑器并在终端中进行编译)。 I found program on the internet that is very useful to me but can't seem to run it.
我在互联网上发现了对我非常有用的程序,但似乎无法运行它。 This is the code:
这是代码:
#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;
}
And this is the error that I get: 这是我得到的错误:
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
I tried to change this line 我试图改变这条线
ImgPicThres = cvCreateImage(cvSize(imgPicInput->width, imgPicInput->height), IPL_DEPTH_8U, 1);
into 进入
ImgPicThres = cvCreateImage(cvGetSize(imgPicInput), IPL_DEPTH_8U, 1);
with no luck. 没有运气。 OpenCV is installed via Macports and is running the latest version.
OpenCV是通过Macports安装的,并且正在运行最新版本。 Any help would be appreciated.
任何帮助,将不胜感激。 Thanks!
谢谢!
imgPicInput = cvLoadImage("bitmap.png",CV_LOAD_IMAGE_GRAYSCALE);
以确保您阅读的图像实际上是灰度的。
除了perfanoff的建议外,我宁愿克隆映像而不是创建映像。
imgPicThres = cvCloneImage(imgPicInput );
I have found the answer but forgot to mention it. 我找到了答案,但忘了提。 As the error says imgPicInput and imgPicThres are not of the same size and type.
如错误所示,imgPicInput和imgPicThres的大小和类型不同。 Also I was supposed to watch after the image channels which I didn't.
我也应该注意那些我没有的图像通道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.