【问题标题】:OpenCV Error: Assertion failed in cvAdaptiveThresholdOpenCV 错误:cvAdaptiveThreshold 中的断言失败
【发布时间】:2013-05-23 10:45:00
【问题描述】:

我最近开始在 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 安装并运行最新版本。任何帮助,将不胜感激。谢谢!

【问题讨论】:

    标签: c++ opencv osx-mountain-lion libc++


    【解决方案1】:
    imgPicInput = cvLoadImage("bitmap.png",CV_LOAD_IMAGE_GRAYSCALE);
    

    以确保您阅读的图像实际上是灰度的。

    【讨论】:

    • 非常感谢 perfanoff,这个有帮助!
    【解决方案2】:

    除了 perfanoff 的建议,我宁愿克隆图像而不是创建它。

    imgPicThres = cvCloneImage(imgPicInput );
    

    【讨论】:

    • 谢谢两位,我会试试看会发生什么!
    【解决方案3】:

    我找到了答案,但忘了提及。正如错误所说,imgPicInput 和 imgPicThres 的大小和类型不同。我也应该在我没有观看的图像频道之后观看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 2018-05-20
      • 2017-10-26
      • 2016-11-27
      • 2019-12-04
      相关资源
      最近更新 更多