MauiKit Image Tools

cvmatandqimage.h
1/****************************************************************************
2** Copyright (c) 2012-2015 Debao Zhang <hello@debao.me>
3** All right reserved.
4**
5** Permission is hereby granted, free of charge, to any person obtaining
6** a copy of this software and associated documentation files (the
7** "Software"), to deal in the Software without restriction, including
8** without limitation the rights to use, copy, modify, merge, publish,
9** distribute, sublicense, and/or sell copies of the Software, and to
10** permit persons to whom the Software is furnished to do so, subject to
11** the following conditions:
12**
13** The above copyright notice and this permission notice shall be
14** included in all copies or substantial portions of the Software.
15**
16** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23**
24****************************************************************************/
25
26#ifndef CVMATANDQIMAGE_H
27#define CVMATANDQIMAGE_H
28
29#include <QtGui/qimage.h>
30#include <opencv2/core/core.hpp>
31
32namespace QtOcv {
33
34enum MatColorOrder {
35 MCO_BGR,
36 MCO_RGB,
37 MCO_BGRA = MCO_BGR,
38 MCO_RGBA = MCO_RGB,
39 MCO_ARGB
40};
41
42
43/* Convert QImage to/from cv::Mat
44 *
45 * - cv::Mat
46 * - Supported channels
47 * - 1 channel
48 * - 3 channels (B G R), (R G B)
49 * - 4 channels (B G R A), (R G B A), (A R G B)
50 * - Supported depth
51 * - CV_8U [0, 255]
52 * - CV_16U [0, 65535]
53 * - CV_32F [0, 1.0]
54 *
55 * - QImage
56 * - All of the formats of QImage are supported.
57 */
58cv::Mat image2Mat(const QImage &img, int requiredMatType = CV_8UC(0), MatColorOrder requiredOrder=MCO_BGR);
59QImage mat2Image(const cv::Mat &mat, MatColorOrder order=MCO_BGR, QImage::Format formatHint = QImage::Format_Invalid);
60
61/* Convert QImage to/from cv::Mat without data copy
62 *
63 * - Supported QImage formats and cv::Mat types are:
64 * - QImage::Format_Indexed8 <==> CV_8UC1
65 * - QImage::Format_Alpha8 <==> CV_8UC1
66 * - QImage::Format_Grayscale8 <==> CV_8UC1
67 * - QImage::Format_RGB888 <==> CV_8UC3 (R G B)
68 * - QImage::Format_RGB32 <==> CV_8UC4 (A R G B or B G R A)
69 * - QImage::Format_ARGB32 <==> CV_8UC4 (A R G B or B G R A)
70 * - QImage::Format_ARGB32_Premultiplied <==> CV_8UC4 (A R G B or B G R A)
71 * - QImage::Format_RGBX8888 <==> CV_8UC4 (R G B A)
72 * - QImage::Format_RGBA8888 <==> CV_8UC4 (R G B A)
73 * - QImage::Format_RGBA8888_Premultiplied <==> CV_8UC4 (R G B A)
74 *
75 * - For QImage::Format_RGB32 ,QImage::Format_ARGB32
76 * and QImage::Format_ARGB32_Premultiplied, the
77 * color channel order of cv::Mat will be (B G R A) in little
78 * endian system or (A R G B) in big endian system.
79 *
80 * - User must make sure that the color channels order is the same as
81 * the color channels order requried by QImage.
82 */
83cv::Mat image2Mat_shared(const QImage &img, MatColorOrder *order=0);
84QImage mat2Image_shared(const cv::Mat &mat, QImage::Format formatHint = QImage::Format_Invalid);
85
86} //namespace QtOcv
87
88#endif // CVMATANDQIMAGE_H
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 11 2025 11:57:09 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.