Reads an image from a buffer in memory.
- * - *The function reads an image from the specified buffer in the memory. - * If the buffer is too short or contains invalid data, the empty matrix/image - * is returned.
- * - *See "imread" for the list of supported formats and flags description.
- * - *Note: In the case of color images, the decoded images will have the channels
- * stored in B G R order.
Encodes an image into a memory buffer.
- * - *The function compresses the image and stores it in the memory buffer that is - * resized to fit the result. - * See "imwrite" for the list of supported formats and flags description.
- * - *Note: cvEncodeImage returns single-row matrix of type
- * CV_8UC1 that contains encoded image as array of bytes.
Encodes an image into a memory buffer.
- * - *The function compresses the image and stores it in the memory buffer that is - * resized to fit the result. - * See "imwrite" for the list of supported formats and flags description.
- * - *Note: cvEncodeImage returns single-row matrix of type
- * CV_8UC1 that contains encoded image as array of bytes.
Loads an image from a file.
- * - *The function imread loads an image from the specified file and
- * returns it. If the image cannot be read (because of missing file, improper
- * permissions, unsupported or invalid format), the function returns an empty
- * matrix (Mat.data==NULL). Currently, the following file formats
- * are supported:
*.bmp, *.dib (always supported)
- * *.jpeg, *.jpg, *.jpe (see the *Notes*
- * section)
- * *.jp2 (see the *Notes* section)
- * *.png (see the *Notes*
- * section)
- * *.pbm, *.pgm, *.ppm (always
- * supported)
- * *.sr, *.ras (always supported)
- * *.tiff, *.tif (see the *Notes* section)
- * Note:
- *OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
- * Note: In the case of color images, the decoded images will have the channels
- * stored in B G R order.
Note: In the current implementation the alpha channel, if any, is stripped - * from the output image. Use negative value if you need the alpha channel.
- *Loads an image from a file.
- * - *The function imread loads an image from the specified file and
- * returns it. If the image cannot be read (because of missing file, improper
- * permissions, unsupported or invalid format), the function returns an empty
- * matrix (Mat.data==NULL). Currently, the following file formats
- * are supported:
*.bmp, *.dib (always supported)
- * *.jpeg, *.jpg, *.jpe (see the *Notes*
- * section)
- * *.jp2 (see the *Notes* section)
- * *.png (see the *Notes*
- * section)
- * *.pbm, *.pgm, *.ppm (always
- * supported)
- * *.sr, *.ras (always supported)
- * *.tiff, *.tif (see the *Notes* section)
- * Note:
- *OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
- * Note: In the case of color images, the decoded images will have the channels
- * stored in B G R order.
Saves an image to a specified file.
- * - *The function imwrite saves the image to the specified file. The
- * image format is chosen based on the filename extension (see
- * "imread" for the list of extensions). Only 8-bit (or 16-bit unsigned
- * (CV_16U) in case of PNG, JPEG 2000, and TIFF) single-channel or
- * 3-channel (with 'BGR' channel order) images can be saved using this function.
- * If the format, depth or channel order is different, use "Mat.convertTo", and
- * "cvtColor" to convert it before saving. Or, use the universal "FileStorage"
- * I/O functions to save the image to XML or YAML format.
- * It is possible to store PNG images with an alpha channel using this function.
- * To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha
- * channel goes last. Fully transparent pixels should have alpha set to 0, fully
- * opaque pixels should have alpha set to 255/65535. The sample below shows how
- * to create such a BGRA image and store to PNG file. It also demonstrates how
- * to set custom compression parameters
// C++ code:
- * - *#include
#include
#include
using namespace cv;
- * - *using namespace std;
- * - *void createAlphaMat(Mat &mat)
- * - * - *CV_Assert(mat.channels() == 4);
- * - *for (int i = 0; i < mat.rows; ++i) {
- * - *for (int j = 0; j < mat.cols; ++j) {
- * - *Vec4b& bgra = mat.at
bgra[0] = UCHAR_MAX; // Blue
- * - *bgra[1] = saturate_cast
bgra[2] = saturate_cast
bgra[3] = saturate_cast
int main(int argv, char argc)
- * - * - *// Create mat with alpha channel
- * - *Mat mat(480, 640, CV_8UC4);
- * - *createAlphaMat(mat);
- * - *vector
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
- * - *compression_params.push_back(9);
- * - *try {
- * - *imwrite("alpha.png", mat, compression_params);
- * - * - *catch (runtime_error& ex) {
- * - *fprintf(stderr, "Exception converting image to PNG format: %sn", ex.what());
- * - *return 1;
- * - * - *fprintf(stdout, "Saved PNG file with alpha data.n");
- * - *return 0;
- * - * @param filename Name of the file. - * @param img a img - * @param params Format-specific save parameters encoded as pairs - *paramId_1, paramValue_1, paramId_2, paramValue_2,.... The
- * following parameters are currently supported:
- * CV_IMWRITE_JPEG_QUALITY)
- * from 0 to 100 (the higher is the better). Default value is 95.
- * CV_IMWRITE_PNG_COMPRESSION)
- * from 0 to 9. A higher value means a smaller size and longer compression time.
- * Default value is 3.
- * CV_IMWRITE_PXM_BINARY),
- * 0 or 1. Default value is 1.
- * Saves an image to a specified file.
- * - *The function imwrite saves the image to the specified file. The
- * image format is chosen based on the filename extension (see
- * "imread" for the list of extensions). Only 8-bit (or 16-bit unsigned
- * (CV_16U) in case of PNG, JPEG 2000, and TIFF) single-channel or
- * 3-channel (with 'BGR' channel order) images can be saved using this function.
- * If the format, depth or channel order is different, use "Mat.convertTo", and
- * "cvtColor" to convert it before saving. Or, use the universal "FileStorage"
- * I/O functions to save the image to XML or YAML format.
- * It is possible to store PNG images with an alpha channel using this function.
- * To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha
- * channel goes last. Fully transparent pixels should have alpha set to 0, fully
- * opaque pixels should have alpha set to 255/65535. The sample below shows how
- * to create such a BGRA image and store to PNG file. It also demonstrates how
- * to set custom compression parameters
// C++ code:
- * - *#include
#include
#include
using namespace cv;
- * - *using namespace std;
- * - *void createAlphaMat(Mat &mat)
- * - * - *CV_Assert(mat.channels() == 4);
- * - *for (int i = 0; i < mat.rows; ++i) {
- * - *for (int j = 0; j < mat.cols; ++j) {
- * - *Vec4b& bgra = mat.at
bgra[0] = UCHAR_MAX; // Blue
- * - *bgra[1] = saturate_cast
bgra[2] = saturate_cast
bgra[3] = saturate_cast
int main(int argv, char argc)
- * - * - *// Create mat with alpha channel
- * - *Mat mat(480, 640, CV_8UC4);
- * - *createAlphaMat(mat);
- * - *vector
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
- * - *compression_params.push_back(9);
- * - *try {
- * - *imwrite("alpha.png", mat, compression_params);
- * - * - *catch (runtime_error& ex) {
- * - *fprintf(stderr, "Exception converting image to PNG format: %sn", ex.what());
- * - *return 1;
- * - * - *fprintf(stdout, "Saved PNG file with alpha data.n");
- * - *return 0;
- * - * @param filename Name of the file. - * @param img a img - * @see org.opencv.highgui.Highgui.imwrite - */ - public static boolean imwrite(String filename, Mat img) { - - boolean retVal = imwrite_1(filename, img.nativeObj); - - return retVal; - } - - - // C++: Mat imdecode(Mat buf, int flags) - private static native long imdecode_0(long buf_nativeObj, int flags); - - // C++: bool imencode(string ext, Mat img, vector_uchar& buf, vector_int params = vector