简体   繁体   English

Opencv.exe 中 0x00007FFFB9423B29 处的未处理异常:Microsoft C++ 异常:cv::Exception at ZCD69B4957F06CD818D7BF3D61980E2

[英]Unhandled exception at 0x00007FFFB9423B29 in Opencv.exe: Microsoft C++ exception: cv::Exception at memory location

#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;



Mat imgOriginal, imgDilate, imgCanny, imgGray, imgBlur, imgWrap, imgCrop,imgScan;
vector<Point> initialPoints, docPoints;

float w = 590, h = 360;

Mat preProcessing(Mat img)
{
    cvtColor(img, imgGray, COLOR_BGR2GRAY);
    GaussianBlur(imgGray, imgBlur, Size(3, 3), 3, 0);
    Canny(imgBlur, imgCanny, 25, 75);
    Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3));
    dilate(imgCanny, imgDilate, kernel);
    return imgDilate;
}

vector<Point> getContours(Mat image)
{
    vector< vector<Point >> contours;
    vector<Vec4i> hierarchy;

    findContours(image, contours, hierarchy ,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);

    vector<vector<Point >> conPoly(contours.size());
    vector<Rect> boundRect(contours.size());

    vector<Point> biggest;
    int maxArea = 0;

    for (int i = 0; i < contours.size(); i++)
    {
        int area = contourArea(contours[i]);
        cout << area << endl;

    
        if (area > 1000)
        {
            float peri = arcLength(contours[i], true);
            approxPolyDP(contours[i], conPoly[i], 0.02 * peri, true);

            if (area > maxArea && conPoly[i].size() == 4)
            {
                //drawContours(imgOriginal, conPoly, i, Scalar(255, 0, 255), 5);
                biggest = { conPoly[i][0], conPoly[i][1] , conPoly[i][2] , conPoly[i][3] };
                maxArea = area;
            }   
            
        }
    }
    return biggest;
}
void drawPoints(vector<Point> points, Scalar color)
{
    for (int i = 0; i < points.size(); i++)
    {
        circle(imgOriginal, points[i], 10, color, FILLED);
        putText(imgOriginal, to_string(i), points[i], FONT_HERSHEY_PLAIN, 2, color, 2);
    }
}

vector<Point> reorder(vector<Point> points)
{
    vector<Point> newPoints;
    vector<int> sumPoints, subPoints;

    for (int i = 0; i < 4; i++)
    {
        sumPoints.push_back(points[i].x + points[i].y);
        subPoints.push_back(points[i].x - points[i].y);
    }
    newPoints.push_back(points[min_element(sumPoints.begin(), sumPoints.end()) - sumPoints.begin()]); // 0
    newPoints.push_back(points[max_element(subPoints.begin(), subPoints.end()) - subPoints.begin()]); // 1
    newPoints.push_back(points[min_element(subPoints.begin(), subPoints.end()) - subPoints.begin()]); // 2
    newPoints.push_back(points[max_element(sumPoints.begin(), sumPoints.end()) - sumPoints.begin()]); // 3

    return newPoints;
    
}

Mat getWarp(Mat img, vector<Point> points, float w, float h)
{
    Point2f src[4] = { points[0], points[1], points[2], points[3] };
    Point2f des[4] = { {0.0f,0.0f },{w,0.0f },{0.0f,h },{w,h} };

    Mat matrix = getPerspectiveTransform(src, des);
    warpPerspective(img, imgWrap, matrix, Point(w, h));

    return imgWrap;

}

At This point error occurs In adaptiveThreshold Error: Unhandled exception at 0x00007FFFB9423B29 in Opencv.exe: Microsoft C++ exception: cv::Exception at memory location此时错误发生在adaptiveThreshold错误:Opencv.exe 中 0x00007FFFB9423B29 处的未处理异常:Microsoft C++ 异常:cv::Exception at ZCD69B17BDFDD818

Mat Scanner(Mat img)
{
    adaptiveThreshold(img, imgScan, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 3, 11); //Error 
    return imgScan;
} 

Error in only this ^^^^^ part of code仅此 ^^^^^ 部分代码出错

rest of the code working only error occurs in adaptiveThreshold rest 的代码工作仅错误发生在adaptiveThreshold

int main()
{
    string path = "resource/document5.jpg";
    imgOriginal = imread(path);
    resize(imgOriginal, imgOriginal,Size(1080,720));

    //image processing 
    imgDilate = preProcessing(imgOriginal);

    //Get contours
    initialPoints = getContours(imgDilate);

    //draw points
    docPoints = reorder(initialPoints);
    //drawPoints(docPoints, Scalar(0, 255, 0));
    //drawPoints(initialPoints, Scalar(0, 0, 255));
    imgWrap = getWarp(imgOriginal, docPoints, w, h);
    

    //Crop
    Rect roi(5, 5, w - (2 * 5), h - (2 * 5));
    imgCrop = imgWrap(roi);

    //scan
    Scanner(imgCrop);

    imshow("imgOrignal contours", imgOriginal);
    imshow("imgDilate", imgDilate);
    imshow("imgWrap", imgWrap);
    imshow("imgCrop", imgCrop);
    imshow("imgScan", imgScan);

    waitKey(0);
    return 0;
}

In scanner part i use adaptiveThreshold but it shows error Unhandled exception at 0x00007FFFB9423B29 in Opencv.exe: Microsoft C++ exception: cv::Exception at memory location在扫描仪部分,我使用了adaptiveThreshold,但它在Opencv.exe 中的0x00007FFFB9423B29 处显示错误未处理异常:Microsoft C++ 异常:cv::Exception at ZCD6917B4957F08CDE21 位置6

You have to convert input image to gray to use adaptive threshold Use cvtcolor to do it您必须将输入图像转换为灰色才能使用自适应阈值使用 cvtcolor 来完成

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理的异常 Microsoft C++ 异常:cv::Exception at memory location - Unhandled exception Microsoft C++ exception: cv::Exception at memory location Opencv PCA Microsoft C ++异常:内存位置的cv :: Exception - Opencv PCA Microsoft C++ exception: cv::Exception at memory location Project1.exe中0x00007FFCA550A839的未处理异常:Microsoft C ++异常:内存位置0x0000002F82CFEF60的std :: bad_alloc。 发生了 - Unhandled exception at 0x00007FFCA550A839 in Project1.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0000002F82CFEF60. occurred OpenCv-内存位置C ++中的cv :: Exception - OpenCv - cv::Exception at memory location C++ 7 行代码行不通...Conv.exe 中 0x76F643D2 处未处理的异常:Microsoft C++ 异常:cv::Exception 位于 memory 位置 0x008EDDD8 - 7 lines of code won't work... Unhandled exception at 0x76F643D2 in Conv.exe: Microsoft C++ exception: cv::Exception at memory location 0x008EDDD8 错误 test.exe 中 0x76C9FD62 处的未处理异常:Microsoft C++ 异常:memory 位置 0x006FF870 处的 std::out_of_range。 发生了 - Error Unhandled exception at 0x76C9FD62 in test.exe: Microsoft C++ exception: std::out_of_range at memory location 0x006FF870. occurred Mini-Project.exe中0x77031D4D的未处理异常:Microsoft C ++异常:内存位置0x00CFF620的std :: out_of_range - Unhandled exception at 0x77031D4D in Mini-Project.exe: Microsoft C++ exception: std::out_of_range at memory location 0x00CFF620 Milestone2.exe中0x7700C42D的未处理异常:Microsoft C ++异常:内存位置0x003EF5DC的std :: bad_alloc - Unhandled exception at 0x7700C42D in Milestone2.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003EF5DC 位置未处理的异常:Microsoft C ++异常:内存位置处的std :: length_error - Unhandled exception at location :Microsoft C++ exception: std::length_error at memory location [内存分配问题]未处理的异常:Microsoft C ++异常:内存位置处的std :: bad_alloc - [Memory allocation problem]Unhandled exception: Microsoft C++ exception: std::bad_alloc at memory location
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM