Cannot save image
This is because you don't have the privileges to write in that location. Solutions:
- Start your program as administrator
- Change to a location where you have enough privileges
Integral image is saved blank
The integral image is of type CV_32UC1
, so values higher than 255 will be saturated to 255, and saved as white. You can't recover original values from the saved image.
Solutions:
Normalize the values to fit the range [0,255]
, and save the CV_8U
image. You can't recover original values from the saved image, but at least is scaled and shown correctly.
Use FileStorage
to save the original data. You keep the original values.
If you need more speed that FileStorage
, you can save raw binary data. See here for an example. You keep the original values.
This is a sample code to show solutions 1 and 2. For 3 please refer to the given link.
#include <opencv2\opencv.hpp>
using namespace cv;
int main()
{
// Load image
Mat1b object = imread("path_to_image", IMREAD_GRAYSCALE);
// Calculate integral image
Mat1i iObject;
integral(object, iObject);
imwrite("save_1i.png", iObject);
// the saved image has saturated values
// /////////////////////////////////////////
// Save using imwrite
Mat1b save_1b;
normalize(iObject, save_1b, 255, 0, NORM_MINMAX);
imwrite("save_1b.png", save_1b);
// the saved image has scaled values, but displayed correctly
// /////////////////////////////////////////
// Save using FileStorage
{
FileStorage fs("save_fs.yml", FileStorage::WRITE);
fs << "integral" << iObject;
// the saved file has original values
}
// Load using FileStorage
Mat1i loadedIObject;
{
FileStorage fs("save_fs.yml", FileStorage::READ);
fs["integral"] >> loadedIObject;
}
// loadedIObject has original values
return 0;
}