UtiLite
0.3.1
A lite utilities library
|
00001 /* 00002 * utilite is a cross-platform library with 00003 * useful utilities for fast and small developing. 00004 * Copyright (C) 2010 Mathieu Labbe 00005 * 00006 * utilite is free library: you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * utilite is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #ifndef UCV2QT_H_ 00021 #define UCV2QT_H_ 00022 00023 #include <QtGui/QImage> 00024 #include <opencv2/core/core.hpp> 00025 00029 void uTest() 00030 { 00031 00032 } 00033 00040 inline QImage uCvMat2QImage(const cv::Mat & image, bool isBgr = true) 00041 { 00042 QImage qtemp; 00043 if(!image.empty() && image.depth() == CV_8U) 00044 { 00045 if(image.channels()==3) 00046 { 00047 const unsigned char * data = image.data; 00048 if(image.channels() == 3) 00049 { 00050 qtemp = QImage(image.cols, image.rows, QImage::Format_RGB32); 00051 for(int y = 0; y < image.rows; ++y, data += image.cols*image.elemSize()) 00052 { 00053 for(int x = 0; x < image.cols; ++x) 00054 { 00055 QRgb * p = ((QRgb*)qtemp.scanLine (y)) + x; 00056 if(isBgr) 00057 { 00058 *p = qRgb(data[x * image.channels()+2], data[x * image.channels()+1], data[x * image.channels()]); 00059 } 00060 else 00061 { 00062 *p = qRgb(data[x * image.channels()], data[x * image.channels()+1], data[x * image.channels()+2]); 00063 } 00064 } 00065 } 00066 } 00067 } 00068 else if(image.channels() == 1) 00069 { 00070 // mono grayscale 00071 qtemp = QImage(image.data, image.cols, image.rows, image.cols, QImage::Format_Indexed8).copy(); 00072 } 00073 else 00074 { 00075 printf("Wrong image format, must have 1 or 3 channels\n"); 00076 } 00077 } 00078 else if(!image.empty() && image.depth() != CV_8U) 00079 { 00080 printf("Wrong image format, must be 8_bits, 3 channels\n"); 00081 } 00082 return qtemp; 00083 } 00084 00085 00086 #endif /* UCV2QT_H_ */