I would like to create an 8 channel openCV image using the C++ API:
cv::Mat lookupTable = cv::Mat(height, width, CV_32FC(8), cv::Scalar::all(-1.f));
I get:
external/opencv/modules/core/src/array.cpp:3229: error: (-215:Assertion failed) cn <= 4 in function 'scalarToRawData'
I was pretty sure that OpenCV supports multi channel >4 images. Am I wrong?
Update 1:
Apparently it is related to the initialization value cv::Scalar::all(-1.f). That is limited to be a cv::Vec<T,4>. However,
cv::Vec<float, 8> a = {-1.f, -1.f, -1.f, -1.f, 1.f, -1.f, -1.f, -1.f};
cv::Mat lookupTable = cv::Mat(height, width, CV_32FC(8), a);
is also not supported and fails with the same error.
Update 2:
cv::Mat lookupTable = cv::Mat(height, width, CV_32FC(8));
lookupTable.setTo(-1);
Compiles and runs, but I didn't yet validate if all values are really initialized to -1.
However, next problem is that cv::imwrite() can't save that image.
Oh man .. it is really a mess!
Update 3: Ok, I can confirm that lookupTable.setTo(-1) works and all values are initialized accordingly. Also, what works to save that image is going over cv::FileStorage.
cv::FileStorage fs("lookup.ext", cv::FileStorage::WRITE_BASE64);
fs.write("LUT",lookupTable);
However, this is saved in text format and there seems to be no way to have it stored in a binary format :-(
Update 4:
Ok, appending .gz to the extension compresses the file.
cv::FileStorage fs("lookup.ext.gz", cv::FileStorage::WRITE_BASE64);