简体   繁体   中英

OpenCV Gives an error when using the imgproc functions (2)

Every time I use the image processing functions in opencv, I get a c++ runtime error.

This is my code, and I get "the application has requested to terminate it in an unusual way"

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

int main() {
    cv::Mat a = cv::imread("img.jpg");
    cv::Mat b(a);

    cv::Canny(a,b,250,300);
    cv::namedWindow("Hello");
    cv::imshow("Hello",b);
    cv::waitKey(2000);
    return 0;
}

The cv::Canny function requires always a grayscale image as input. You need to convert a to grayscale first. The following code snippet does the trick:

cv::cvtColor(a, a, CV_BGR2GRAY);

Have you checked what 'a' is after the imread?

What if it fails because the "img.jpg" is in a different directory or you don't have permission.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM