我的程序在使用OpenCV进行图像处理时崩溃了

My program crashes when performing image processing with OpenCV

本文关键字:图像处理 崩溃 OpenCV 程序 我的      更新时间:2023-10-16

我使用OpenCV为我的学校项目。

当我使用OpenCV的"基础"时,我所有的程序都可以工作,但是当我必须做"大"图像处理时-例如使用findContours()或HoughLines或HoughLinesP,我的程序崩溃了…

你知道为什么吗?

编辑:代码:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main() {
    cout << "lol";
    IplImage* image = cvLoadImage("frame3.jpg", 0);
    cout << "bas";
    cvWaitKey(3000);
    Mat src(image);
    Mat color_dst;
    cout << "la3";
    imshow("source", src);
    cout << "la4";
    waitKey(3000);
    cout << "la5";
    vector<Vec4i> lines;
    HoughLinesP(src, lines, 1, CV_PI / 180, 80, 30, 10);
    cout << "la6";
    for (size_t i = 0; i < lines.size(); i++) {
        line(color_dst, Point(lines[i][0], lines[i][1]),
            Point(lines[i][2], lines[i][3]), Scalar(0, 0, 255), 3, 8);
    }
    imshow("io", color_dst);
    cvWaitKey(5000);
}

我认为它崩溃了,因为您建议line例程在未构建的图像上画一条线。

Mat color_dest不创建图像缓冲区。使用具有图像大小和类型的构造函数之一。