-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Description
This is a feature request for opencv core.
Using opencv C++, is there a way to automatically detect what colorspace a cvMat is in? In my experience with opencv, I believe the answer is no. The responsibility of knowing what colorspace a cvMat is in has always been application-specific and relied on a dev to know how data was read in via imread.
This becomes problematic when interfacing with other libraries that use opencv and pass cvMat's around where it's not always clear how the cvMat was constructed. Either the colorspace must be documented or requires digging into the source code.
An easy fix to this would be to add an enum (maybe call it COLORSPACE) that tracks what colorspace the data is in. Functions like imread and cvtColor would set/update the enum where appropriate. Here is a short example of how I imagine someone would use the enum solution.
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char **argv) {
string image_file("some-image.jpg");
Mat img = imread(image_file); // or possibly retrieve a cvMat from an external library
if (img.empty()) {
cout << "Can't read image from file: " << image_file << endl;
return -1;
}
// what colorspace are we in? Does the Mat need converting with cv::cvtColor?
if (img.COLORSPACE == cv::RGB) {
cout << "this image is in RGB space" << endl
}
if (img.COLORSPACE == cv::BGR) {
cout << "this image is in BGR space" << endl;
}
}Thoughts or suggestions?