Hi,
I am having trouble converting a Mat to gray scale using the following (more details below) cv::cvtColor(result, gray, COLOR_BGR2GRAY);
result is a Mat. It is the output of image stitching (from the sample: https://github.com/Itseez/opencv/blob/master/samples/cpp/stitching_detailed.cpp):
Mat result, result_mask; blender->blend(result, result_mask);
result Mat properties:
- result.rows 2310
- result.cols 5545
- result.type 19
- result.channel 3
- result.depth 3
I am trying to convert this Mat result to grayscale as a first step in another cropping function: cv::Mat gray; cv::cvtColor(result, gray, COLOR_BGR2GRAY);
but fails at the assertion on line "cv::cvtColor(result, gray, COLOR_BGR2GRAY);": OpenCV Error: Assertion failed (depth == CV_8U || depth == CV_16U || depth == CV_32F) in cv::cvtColor, file C:\builds\master_PackSlave-win32-vc12-shared\opencv\modules\imgproc\src\color.cpp, line 7343
If I imwrite the result Mat above, and imread it back in like so:
imwrite(result_name, result);
Mat toCrop = imread(result_name, CV_LOAD_IMAGE_COLOR); cv::Mat gray; cv::cvtColor(toCrop, gray, COLOR_BGR2GRAY);
Then there are no errors
toCrop Mat properties after reading back in are:
- toCrop.rows 2310
- toCrop.cols 5545
- toCrop.type 16
- toCrop.channel 3
- toCrop.depth 0
Any ideas on how to get this working without writing and reading, using the original Mat result to convert to grayscale? I believe the depth is the issue. The result is I've been searching how to do a conversion of the depth but no progress..