tomelse
tomelse

Reputation: 90

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;
}

Upvotes: 0

Views: 263

Answers (2)

Banus80
Banus80

Reputation: 101

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);

Upvotes: 2

Martin Beckett
Martin Beckett

Reputation: 96109

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.

Upvotes: 0

Related Questions