How to solve the "integer division by zero" problem during the application of opencv?

Viewed 51

When I use OpenCV in the visual studio with C++ to process an image, it occurs this Exception unhandled problem as follows: Unhandled exception at 0x00007FF81406F880 (opencv_world455d.dll) in ImageFilterTest.exe: 0xC0000094: Integer division by zero.

my source code is as follows:

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    // read image
    Mat image = imread("../Images/im092002.jpg");
    
    //print error message if image is null
    if (image.empty())
    {
        cout << "Could not read image" << endl;
    }
    //apply identiy filter using kernel
    Mat kernel1 = (Mat_<double>(5, 5) << 0, 0, 0, 0, 1, 0, 0, 0, 0);
    Mat identity;
    filter2D(image, identity, -1, kernel1, Point(-1, -1), 0, 4);
    imshow("Orginal", image);
    imshow("Identity", identity);
    destroyAllWindows();

    //blurred using kernel
    //initalize matrix with all ones
    Mat kernel2 = Mat::ones(5, 5,CV_64F);
    kernel2 = kernel2 / 25;
    Mat img;
    filter2D(image, img, -1, kernel2, Point(-1, -1), 0, 4);
    imshow("Original", image);
    imshow("kernel blur", img);
    imwrite("blur_kernel.jpg", img);
    waitKey();
    destroyAllWindows();

}

I have no basis at all to this kind of problem, can any one tell me how to solve this problem?

0 Answers
Related