OpenCV image conversion from RGB to Grayscale exception -
i'm getting strange exception (exception: cv::exception @ memory location 0x002eb6cc) when try convert rgb image grayscale. can me?
const cv::mat img1 = cv::imread(filename, 0) cv::mat gs_rgb(img1.size(), cv_8uc1); cv::cvtcolor(img1, gs_rgb, cv_rgb2gray);
you loading image gray scale , trying convert gray scale gray scale again.
the line
const cv::mat img1 = cv::imread(filename, 0)
will load image
where second argument
=0->cv_load_image_grayscale->load gray scale =1->cv_load_image_color->load color <0->cv_load_image_anydepth->return loaded image (with alpha channel).
so either load image gray scale , use like,
const cv::mat img1 = cv::imread(filename, 0)//load gray
or load color , convert gray scale like,
const cv::mat img1 = cv::imread(filename, 1);//load color mat gray;//no need of allocation, allocate automatically. cv::cvtcolor(img1,gray, cv_bgr2gray);//opencv default color order bgr
see more info here in imread documentation.
Comments
Post a Comment