Joe Verbout
/
main
opencv on mbed
opencv2/imgcodecs.hpp@0:ea44dc9ed014, 2016-03-31 (annotated)
- Committer:
- joeverbout
- Date:
- Thu Mar 31 21:16:38 2016 +0000
- Revision:
- 0:ea44dc9ed014
OpenCV on mbed attempt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeverbout | 0:ea44dc9ed014 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2 | // |
joeverbout | 0:ea44dc9ed014 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
joeverbout | 0:ea44dc9ed014 | 4 | // |
joeverbout | 0:ea44dc9ed014 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
joeverbout | 0:ea44dc9ed014 | 6 | // If you do not agree to this license, do not download, install, |
joeverbout | 0:ea44dc9ed014 | 7 | // copy or use the software. |
joeverbout | 0:ea44dc9ed014 | 8 | // |
joeverbout | 0:ea44dc9ed014 | 9 | // |
joeverbout | 0:ea44dc9ed014 | 10 | // License Agreement |
joeverbout | 0:ea44dc9ed014 | 11 | // For Open Source Computer Vision Library |
joeverbout | 0:ea44dc9ed014 | 12 | // |
joeverbout | 0:ea44dc9ed014 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 15 | // Third party copyrights are property of their respective owners. |
joeverbout | 0:ea44dc9ed014 | 16 | // |
joeverbout | 0:ea44dc9ed014 | 17 | // Redistribution and use in source and binary forms, with or without modification, |
joeverbout | 0:ea44dc9ed014 | 18 | // are permitted provided that the following conditions are met: |
joeverbout | 0:ea44dc9ed014 | 19 | // |
joeverbout | 0:ea44dc9ed014 | 20 | // * Redistribution's of source code must retain the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 21 | // this list of conditions and the following disclaimer. |
joeverbout | 0:ea44dc9ed014 | 22 | // |
joeverbout | 0:ea44dc9ed014 | 23 | // * Redistribution's in binary form must reproduce the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 24 | // this list of conditions and the following disclaimer in the documentation |
joeverbout | 0:ea44dc9ed014 | 25 | // and/or other materials provided with the distribution. |
joeverbout | 0:ea44dc9ed014 | 26 | // |
joeverbout | 0:ea44dc9ed014 | 27 | // * The name of the copyright holders may not be used to endorse or promote products |
joeverbout | 0:ea44dc9ed014 | 28 | // derived from this software without specific prior written permission. |
joeverbout | 0:ea44dc9ed014 | 29 | // |
joeverbout | 0:ea44dc9ed014 | 30 | // This software is provided by the copyright holders and contributors "as is" and |
joeverbout | 0:ea44dc9ed014 | 31 | // any express or implied warranties, including, but not limited to, the implied |
joeverbout | 0:ea44dc9ed014 | 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
joeverbout | 0:ea44dc9ed014 | 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
joeverbout | 0:ea44dc9ed014 | 34 | // indirect, incidental, special, exemplary, or consequential damages |
joeverbout | 0:ea44dc9ed014 | 35 | // (including, but not limited to, procurement of substitute goods or services; |
joeverbout | 0:ea44dc9ed014 | 36 | // loss of use, data, or profits; or business interruption) however caused |
joeverbout | 0:ea44dc9ed014 | 37 | // and on any theory of liability, whether in contract, strict liability, |
joeverbout | 0:ea44dc9ed014 | 38 | // or tort (including negligence or otherwise) arising in any way out of |
joeverbout | 0:ea44dc9ed014 | 39 | // the use of this software, even if advised of the possibility of such damage. |
joeverbout | 0:ea44dc9ed014 | 40 | // |
joeverbout | 0:ea44dc9ed014 | 41 | //M*/ |
joeverbout | 0:ea44dc9ed014 | 42 | |
joeverbout | 0:ea44dc9ed014 | 43 | #ifndef __OPENCV_IMGCODECS_HPP__ |
joeverbout | 0:ea44dc9ed014 | 44 | #define __OPENCV_IMGCODECS_HPP__ |
joeverbout | 0:ea44dc9ed014 | 45 | |
joeverbout | 0:ea44dc9ed014 | 46 | #include "opencv2/core.hpp" |
joeverbout | 0:ea44dc9ed014 | 47 | |
joeverbout | 0:ea44dc9ed014 | 48 | /** |
joeverbout | 0:ea44dc9ed014 | 49 | @defgroup imgcodecs Image file reading and writing |
joeverbout | 0:ea44dc9ed014 | 50 | @{ |
joeverbout | 0:ea44dc9ed014 | 51 | @defgroup imgcodecs_c C API |
joeverbout | 0:ea44dc9ed014 | 52 | @defgroup imgcodecs_ios iOS glue |
joeverbout | 0:ea44dc9ed014 | 53 | @} |
joeverbout | 0:ea44dc9ed014 | 54 | */ |
joeverbout | 0:ea44dc9ed014 | 55 | |
joeverbout | 0:ea44dc9ed014 | 56 | //////////////////////////////// image codec //////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 57 | namespace cv |
joeverbout | 0:ea44dc9ed014 | 58 | { |
joeverbout | 0:ea44dc9ed014 | 59 | |
joeverbout | 0:ea44dc9ed014 | 60 | //! @addtogroup imgcodecs |
joeverbout | 0:ea44dc9ed014 | 61 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 62 | |
joeverbout | 0:ea44dc9ed014 | 63 | //! Imread flags |
joeverbout | 0:ea44dc9ed014 | 64 | enum ImreadModes { |
joeverbout | 0:ea44dc9ed014 | 65 | IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). |
joeverbout | 0:ea44dc9ed014 | 66 | IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image. |
joeverbout | 0:ea44dc9ed014 | 67 | IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image. |
joeverbout | 0:ea44dc9ed014 | 68 | IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. |
joeverbout | 0:ea44dc9ed014 | 69 | IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format. |
joeverbout | 0:ea44dc9ed014 | 70 | IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image. |
joeverbout | 0:ea44dc9ed014 | 71 | IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2. |
joeverbout | 0:ea44dc9ed014 | 72 | IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2. |
joeverbout | 0:ea44dc9ed014 | 73 | IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4. |
joeverbout | 0:ea44dc9ed014 | 74 | IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4. |
joeverbout | 0:ea44dc9ed014 | 75 | IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8. |
joeverbout | 0:ea44dc9ed014 | 76 | IMREAD_REDUCED_COLOR_8 = 65 //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. |
joeverbout | 0:ea44dc9ed014 | 77 | }; |
joeverbout | 0:ea44dc9ed014 | 78 | |
joeverbout | 0:ea44dc9ed014 | 79 | //! Imwrite flags |
joeverbout | 0:ea44dc9ed014 | 80 | enum ImwriteFlags { |
joeverbout | 0:ea44dc9ed014 | 81 | IMWRITE_JPEG_QUALITY = 1, //!< For JPEG, it can be a quality from 0 to 100 (the higher is the better). Default value is 95. |
joeverbout | 0:ea44dc9ed014 | 82 | IMWRITE_JPEG_PROGRESSIVE = 2, //!< Enable JPEG features, 0 or 1, default is False. |
joeverbout | 0:ea44dc9ed014 | 83 | IMWRITE_JPEG_OPTIMIZE = 3, //!< Enable JPEG features, 0 or 1, default is False. |
joeverbout | 0:ea44dc9ed014 | 84 | IMWRITE_JPEG_RST_INTERVAL = 4, //!< JPEG restart interval, 0 - 65535, default is 0 - no restart. |
joeverbout | 0:ea44dc9ed014 | 85 | IMWRITE_JPEG_LUMA_QUALITY = 5, //!< Separate luma quality level, 0 - 100, default is 0 - don't use. |
joeverbout | 0:ea44dc9ed014 | 86 | IMWRITE_JPEG_CHROMA_QUALITY = 6, //!< Separate chroma quality level, 0 - 100, default is 0 - don't use. |
joeverbout | 0:ea44dc9ed014 | 87 | IMWRITE_PNG_COMPRESSION = 16, //!< For PNG, it can be the compression level from 0 to 9. A higher value means a smaller size and longer compression time. Default value is 3. |
joeverbout | 0:ea44dc9ed014 | 88 | IMWRITE_PNG_STRATEGY = 17, //!< One of cv::ImwritePNGFlags, default is IMWRITE_PNG_STRATEGY_DEFAULT. |
joeverbout | 0:ea44dc9ed014 | 89 | IMWRITE_PNG_BILEVEL = 18, //!< Binary level PNG, 0 or 1, default is 0. |
joeverbout | 0:ea44dc9ed014 | 90 | IMWRITE_PXM_BINARY = 32, //!< For PPM, PGM, or PBM, it can be a binary format flag, 0 or 1. Default value is 1. |
joeverbout | 0:ea44dc9ed014 | 91 | IMWRITE_WEBP_QUALITY = 64 //!< For WEBP, it can be a quality from 1 to 100 (the higher is the better). By default (without any parameter) and for quality above 100 the lossless compression is used. |
joeverbout | 0:ea44dc9ed014 | 92 | }; |
joeverbout | 0:ea44dc9ed014 | 93 | |
joeverbout | 0:ea44dc9ed014 | 94 | //! Imwrite PNG specific flags used to tune the compression algorithm. |
joeverbout | 0:ea44dc9ed014 | 95 | /** These flags will be modify the way of PNG image compression and will be passed to the underlying zlib processing stage. |
joeverbout | 0:ea44dc9ed014 | 96 | |
joeverbout | 0:ea44dc9ed014 | 97 | - The effect of IMWRITE_PNG_STRATEGY_FILTERED is to force more Huffman coding and less string matching; it is somewhat intermediate between IMWRITE_PNG_STRATEGY_DEFAULT and IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY. |
joeverbout | 0:ea44dc9ed014 | 98 | - IMWRITE_PNG_STRATEGY_RLE is designed to be almost as fast as IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY, but give better compression for PNG image data. |
joeverbout | 0:ea44dc9ed014 | 99 | - The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately. |
joeverbout | 0:ea44dc9ed014 | 100 | - IMWRITE_PNG_STRATEGY_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications. |
joeverbout | 0:ea44dc9ed014 | 101 | */ |
joeverbout | 0:ea44dc9ed014 | 102 | enum ImwritePNGFlags { |
joeverbout | 0:ea44dc9ed014 | 103 | IMWRITE_PNG_STRATEGY_DEFAULT = 0, //!< Use this value for normal data. |
joeverbout | 0:ea44dc9ed014 | 104 | IMWRITE_PNG_STRATEGY_FILTERED = 1, //!< Use this value for data produced by a filter (or predictor).Filtered data consists mostly of small values with a somewhat random distribution. In this case, the compression algorithm is tuned to compress them better. |
joeverbout | 0:ea44dc9ed014 | 105 | IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = 2, //!< Use this value to force Huffman encoding only (no string match). |
joeverbout | 0:ea44dc9ed014 | 106 | IMWRITE_PNG_STRATEGY_RLE = 3, //!< Use this value to limit match distances to one (run-length encoding). |
joeverbout | 0:ea44dc9ed014 | 107 | IMWRITE_PNG_STRATEGY_FIXED = 4 //!< Using this value prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications. |
joeverbout | 0:ea44dc9ed014 | 108 | }; |
joeverbout | 0:ea44dc9ed014 | 109 | |
joeverbout | 0:ea44dc9ed014 | 110 | /** @brief Loads an image from a file. |
joeverbout | 0:ea44dc9ed014 | 111 | |
joeverbout | 0:ea44dc9ed014 | 112 | @anchor imread |
joeverbout | 0:ea44dc9ed014 | 113 | |
joeverbout | 0:ea44dc9ed014 | 114 | The function imread loads an image from the specified file and returns it. If the image cannot be |
joeverbout | 0:ea44dc9ed014 | 115 | read (because of missing file, improper permissions, unsupported or invalid format), the function |
joeverbout | 0:ea44dc9ed014 | 116 | returns an empty matrix ( Mat::data==NULL ). |
joeverbout | 0:ea44dc9ed014 | 117 | |
joeverbout | 0:ea44dc9ed014 | 118 | Currently, the following file formats are supported: |
joeverbout | 0:ea44dc9ed014 | 119 | |
joeverbout | 0:ea44dc9ed014 | 120 | - Windows bitmaps - \*.bmp, \*.dib (always supported) |
joeverbout | 0:ea44dc9ed014 | 121 | - JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Notes* section) |
joeverbout | 0:ea44dc9ed014 | 122 | - JPEG 2000 files - \*.jp2 (see the *Notes* section) |
joeverbout | 0:ea44dc9ed014 | 123 | - Portable Network Graphics - \*.png (see the *Notes* section) |
joeverbout | 0:ea44dc9ed014 | 124 | - WebP - \*.webp (see the *Notes* section) |
joeverbout | 0:ea44dc9ed014 | 125 | - Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported) |
joeverbout | 0:ea44dc9ed014 | 126 | - Sun rasters - \*.sr, \*.ras (always supported) |
joeverbout | 0:ea44dc9ed014 | 127 | - TIFF files - \*.tiff, \*.tif (see the *Notes* section) |
joeverbout | 0:ea44dc9ed014 | 128 | - OpenEXR Image files - \*.exr (see the *Notes* section) |
joeverbout | 0:ea44dc9ed014 | 129 | - Radiance HDR - \*.hdr, \*.pic (always supported) |
joeverbout | 0:ea44dc9ed014 | 130 | - Raster and Vector geospatial data supported by Gdal (see the *Notes* section) |
joeverbout | 0:ea44dc9ed014 | 131 | |
joeverbout | 0:ea44dc9ed014 | 132 | @note |
joeverbout | 0:ea44dc9ed014 | 133 | |
joeverbout | 0:ea44dc9ed014 | 134 | - The function determines the type of an image by the content, not by the file extension. |
joeverbout | 0:ea44dc9ed014 | 135 | - In the case of color images, the decoded images will have the channels stored in **B G R** order. |
joeverbout | 0:ea44dc9ed014 | 136 | - On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, |
joeverbout | 0:ea44dc9ed014 | 137 | libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, |
joeverbout | 0:ea44dc9ed014 | 138 | and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware |
joeverbout | 0:ea44dc9ed014 | 139 | that currently these native image loaders give images with different pixel values because of |
joeverbout | 0:ea44dc9ed014 | 140 | the color management embedded into MacOSX. |
joeverbout | 0:ea44dc9ed014 | 141 | - On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for |
joeverbout | 0:ea44dc9ed014 | 142 | codecs supplied with an OS image. Install the relevant packages (do not forget the development |
joeverbout | 0:ea44dc9ed014 | 143 | files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn |
joeverbout | 0:ea44dc9ed014 | 144 | on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. |
joeverbout | 0:ea44dc9ed014 | 145 | - In the case you set *WITH_GDAL* flag to true in CMake and @ref IMREAD_LOAD_GDAL to load the image, |
joeverbout | 0:ea44dc9ed014 | 146 | then [GDAL](http://www.gdal.org) driver will be used in order to decode the image by supporting |
joeverbout | 0:ea44dc9ed014 | 147 | the following formats: [Raster](http://www.gdal.org/formats_list.html), |
joeverbout | 0:ea44dc9ed014 | 148 | [Vector](http://www.gdal.org/ogr_formats.html). |
joeverbout | 0:ea44dc9ed014 | 149 | @param filename Name of file to be loaded. |
joeverbout | 0:ea44dc9ed014 | 150 | @param flags Flag that can take values of cv::ImreadModes |
joeverbout | 0:ea44dc9ed014 | 151 | */ |
joeverbout | 0:ea44dc9ed014 | 152 | CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR ); |
joeverbout | 0:ea44dc9ed014 | 153 | |
joeverbout | 0:ea44dc9ed014 | 154 | /** @brief Loads a multi-page image from a file. |
joeverbout | 0:ea44dc9ed014 | 155 | |
joeverbout | 0:ea44dc9ed014 | 156 | The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects. |
joeverbout | 0:ea44dc9ed014 | 157 | @param filename Name of file to be loaded. |
joeverbout | 0:ea44dc9ed014 | 158 | @param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. |
joeverbout | 0:ea44dc9ed014 | 159 | @param mats A vector of Mat objects holding each page, if more than one. |
joeverbout | 0:ea44dc9ed014 | 160 | @sa cv::imread |
joeverbout | 0:ea44dc9ed014 | 161 | */ |
joeverbout | 0:ea44dc9ed014 | 162 | CV_EXPORTS_W bool imreadmulti(const String& filename, std::vector<Mat>& mats, int flags = IMREAD_ANYCOLOR); |
joeverbout | 0:ea44dc9ed014 | 163 | |
joeverbout | 0:ea44dc9ed014 | 164 | /** @brief Saves an image to a specified file. |
joeverbout | 0:ea44dc9ed014 | 165 | |
joeverbout | 0:ea44dc9ed014 | 166 | The function imwrite saves the image to the specified file. The image format is chosen based on the |
joeverbout | 0:ea44dc9ed014 | 167 | filename extension (see cv::imread for the list of extensions). Only 8-bit (or 16-bit unsigned (CV_16U) |
joeverbout | 0:ea44dc9ed014 | 168 | in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with 'BGR' channel order) images |
joeverbout | 0:ea44dc9ed014 | 169 | can be saved using this function. If the format, depth or channel order is different, use |
joeverbout | 0:ea44dc9ed014 | 170 | Mat::convertTo , and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O |
joeverbout | 0:ea44dc9ed014 | 171 | functions to save the image to XML or YAML format. |
joeverbout | 0:ea44dc9ed014 | 172 | |
joeverbout | 0:ea44dc9ed014 | 173 | It is possible to store PNG images with an alpha channel using this function. To do this, create |
joeverbout | 0:ea44dc9ed014 | 174 | 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels |
joeverbout | 0:ea44dc9ed014 | 175 | should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535. |
joeverbout | 0:ea44dc9ed014 | 176 | |
joeverbout | 0:ea44dc9ed014 | 177 | The sample below shows how to create such a BGRA image and store to PNG file. It also demonstrates how to set custom |
joeverbout | 0:ea44dc9ed014 | 178 | compression parameters : |
joeverbout | 0:ea44dc9ed014 | 179 | @code |
joeverbout | 0:ea44dc9ed014 | 180 | #include <opencv2/opencv.hpp> |
joeverbout | 0:ea44dc9ed014 | 181 | |
joeverbout | 0:ea44dc9ed014 | 182 | using namespace cv; |
joeverbout | 0:ea44dc9ed014 | 183 | using namespace std; |
joeverbout | 0:ea44dc9ed014 | 184 | |
joeverbout | 0:ea44dc9ed014 | 185 | void createAlphaMat(Mat &mat) |
joeverbout | 0:ea44dc9ed014 | 186 | { |
joeverbout | 0:ea44dc9ed014 | 187 | CV_Assert(mat.channels() == 4); |
joeverbout | 0:ea44dc9ed014 | 188 | for (int i = 0; i < mat.rows; ++i) { |
joeverbout | 0:ea44dc9ed014 | 189 | for (int j = 0; j < mat.cols; ++j) { |
joeverbout | 0:ea44dc9ed014 | 190 | Vec4b& bgra = mat.at<Vec4b>(i, j); |
joeverbout | 0:ea44dc9ed014 | 191 | bgra[0] = UCHAR_MAX; // Blue |
joeverbout | 0:ea44dc9ed014 | 192 | bgra[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); // Green |
joeverbout | 0:ea44dc9ed014 | 193 | bgra[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); // Red |
joeverbout | 0:ea44dc9ed014 | 194 | bgra[3] = saturate_cast<uchar>(0.5 * (bgra[1] + bgra[2])); // Alpha |
joeverbout | 0:ea44dc9ed014 | 195 | } |
joeverbout | 0:ea44dc9ed014 | 196 | } |
joeverbout | 0:ea44dc9ed014 | 197 | } |
joeverbout | 0:ea44dc9ed014 | 198 | |
joeverbout | 0:ea44dc9ed014 | 199 | int main(int argv, char **argc) |
joeverbout | 0:ea44dc9ed014 | 200 | { |
joeverbout | 0:ea44dc9ed014 | 201 | // Create mat with alpha channel |
joeverbout | 0:ea44dc9ed014 | 202 | Mat mat(480, 640, CV_8UC4); |
joeverbout | 0:ea44dc9ed014 | 203 | createAlphaMat(mat); |
joeverbout | 0:ea44dc9ed014 | 204 | |
joeverbout | 0:ea44dc9ed014 | 205 | vector<int> compression_params; |
joeverbout | 0:ea44dc9ed014 | 206 | compression_params.push_back(IMWRITE_PNG_COMPRESSION); |
joeverbout | 0:ea44dc9ed014 | 207 | compression_params.push_back(9); |
joeverbout | 0:ea44dc9ed014 | 208 | |
joeverbout | 0:ea44dc9ed014 | 209 | try { |
joeverbout | 0:ea44dc9ed014 | 210 | imwrite("alpha.png", mat, compression_params); |
joeverbout | 0:ea44dc9ed014 | 211 | } |
joeverbout | 0:ea44dc9ed014 | 212 | catch (cv::Exception& ex) { |
joeverbout | 0:ea44dc9ed014 | 213 | fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what()); |
joeverbout | 0:ea44dc9ed014 | 214 | return 1; |
joeverbout | 0:ea44dc9ed014 | 215 | } |
joeverbout | 0:ea44dc9ed014 | 216 | |
joeverbout | 0:ea44dc9ed014 | 217 | fprintf(stdout, "Saved PNG file with alpha data.\n"); |
joeverbout | 0:ea44dc9ed014 | 218 | return 0; |
joeverbout | 0:ea44dc9ed014 | 219 | } |
joeverbout | 0:ea44dc9ed014 | 220 | @endcode |
joeverbout | 0:ea44dc9ed014 | 221 | @param filename Name of the file. |
joeverbout | 0:ea44dc9ed014 | 222 | @param img Image to be saved. |
joeverbout | 0:ea44dc9ed014 | 223 | @param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags |
joeverbout | 0:ea44dc9ed014 | 224 | */ |
joeverbout | 0:ea44dc9ed014 | 225 | CV_EXPORTS_W bool imwrite( const String& filename, InputArray img, |
joeverbout | 0:ea44dc9ed014 | 226 | const std::vector<int>& params = std::vector<int>()); |
joeverbout | 0:ea44dc9ed014 | 227 | |
joeverbout | 0:ea44dc9ed014 | 228 | /** @brief Reads an image from a buffer in memory. |
joeverbout | 0:ea44dc9ed014 | 229 | |
joeverbout | 0:ea44dc9ed014 | 230 | The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or |
joeverbout | 0:ea44dc9ed014 | 231 | contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). |
joeverbout | 0:ea44dc9ed014 | 232 | |
joeverbout | 0:ea44dc9ed014 | 233 | See cv::imread for the list of supported formats and flags description. |
joeverbout | 0:ea44dc9ed014 | 234 | |
joeverbout | 0:ea44dc9ed014 | 235 | @note In the case of color images, the decoded images will have the channels stored in **B G R** order. |
joeverbout | 0:ea44dc9ed014 | 236 | @param buf Input array or vector of bytes. |
joeverbout | 0:ea44dc9ed014 | 237 | @param flags The same flags as in cv::imread, see cv::ImreadModes. |
joeverbout | 0:ea44dc9ed014 | 238 | */ |
joeverbout | 0:ea44dc9ed014 | 239 | CV_EXPORTS_W Mat imdecode( InputArray buf, int flags ); |
joeverbout | 0:ea44dc9ed014 | 240 | |
joeverbout | 0:ea44dc9ed014 | 241 | /** @overload |
joeverbout | 0:ea44dc9ed014 | 242 | @param buf |
joeverbout | 0:ea44dc9ed014 | 243 | @param flags |
joeverbout | 0:ea44dc9ed014 | 244 | @param dst The optional output placeholder for the decoded matrix. It can save the image |
joeverbout | 0:ea44dc9ed014 | 245 | reallocations when the function is called repeatedly for images of the same size. |
joeverbout | 0:ea44dc9ed014 | 246 | */ |
joeverbout | 0:ea44dc9ed014 | 247 | CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst); |
joeverbout | 0:ea44dc9ed014 | 248 | |
joeverbout | 0:ea44dc9ed014 | 249 | /** @brief Encodes an image into a memory buffer. |
joeverbout | 0:ea44dc9ed014 | 250 | |
joeverbout | 0:ea44dc9ed014 | 251 | The function imencode compresses the image and stores it in the memory buffer that is resized to fit the |
joeverbout | 0:ea44dc9ed014 | 252 | result. See cv::imwrite for the list of supported formats and flags description. |
joeverbout | 0:ea44dc9ed014 | 253 | |
joeverbout | 0:ea44dc9ed014 | 254 | @param ext File extension that defines the output format. |
joeverbout | 0:ea44dc9ed014 | 255 | @param img Image to be written. |
joeverbout | 0:ea44dc9ed014 | 256 | @param buf Output buffer resized to fit the compressed image. |
joeverbout | 0:ea44dc9ed014 | 257 | @param params Format-specific parameters. See cv::imwrite and cv::ImwriteFlags. |
joeverbout | 0:ea44dc9ed014 | 258 | */ |
joeverbout | 0:ea44dc9ed014 | 259 | CV_EXPORTS_W bool imencode( const String& ext, InputArray img, |
joeverbout | 0:ea44dc9ed014 | 260 | CV_OUT std::vector<uchar>& buf, |
joeverbout | 0:ea44dc9ed014 | 261 | const std::vector<int>& params = std::vector<int>()); |
joeverbout | 0:ea44dc9ed014 | 262 | |
joeverbout | 0:ea44dc9ed014 | 263 | //! @} imgcodecs |
joeverbout | 0:ea44dc9ed014 | 264 | |
joeverbout | 0:ea44dc9ed014 | 265 | } // cv |
joeverbout | 0:ea44dc9ed014 | 266 | |
joeverbout | 0:ea44dc9ed014 | 267 | #endif //__OPENCV_IMGCODECS_HPP__ |
joeverbout | 0:ea44dc9ed014 | 268 |