-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagemodel.cpp
More file actions
73 lines (72 loc) · 2.49 KB
/
imagemodel.cpp
File metadata and controls
73 lines (72 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "imagemodel.h"
ImageModel::ImageModel(const QList<QList<QVariant> > &data, QObject *parent) :
BasicModel(parent)
{
setRootNode(new ImageItem(data, true));
}
void ImageModel::AddBlankItem()
{
this->AddItem(new ImageItem(QString("Blank Image")));
}
void ImageModel::AddMultichannelImage(const cv::Mat image,const QString fileName)
{
QFileInfo fileInfo(fileName);
QString name = fileInfo.fileName();
ImageItem* multichannelImage = new ImageItem(image, name, fileName);
int channelsCount = image.channels();
if(channelsCount>1)
{
QHash<int, QString> ChannelsStrings;
ChannelsStrings[0] = QString("Blue");
ChannelsStrings[1] = QString("Green");
ChannelsStrings[2] = QString("Red");
ChannelsStrings[3] = QString("Alpha");
vector<cv::Mat> imageChannels;
cv::split(image, imageChannels);
for(int i = 0; i<channelsCount; i++)
{
ImageItem* child = new ImageItem(imageChannels[i], name+QString(" ")+ChannelsStrings[i], fileName, i);
multichannelImage->appendChild(child);
}
}
this->AddItem(multichannelImage);
}
void ImageModel::AddImage(const cv::Mat image, const QString fileName)
{
QFileInfo fileInfo(fileName);
QString name = fileInfo.fileName();
// find image if already in list and remove before append new one;
ImageItem* child = this->findImage(fileName);
if(child)
{
child->remove();
}
int channelsCount = image.channels();
if(channelsCount>1)
{
ImageItem* multichannelImage = new ImageItem(name, fileName);
vector<cv::Mat> imageChannels;
cv::split(image, imageChannels);
QHash<int, QString> ChannelsStrings;
ChannelsStrings[0] = QString("Red");
ChannelsStrings[1] = QString("Green");
ChannelsStrings[2] = QString("Blue");
ChannelsStrings[3] = QString("Alpha");
for(int i = 0; i<channelsCount; i++)
{
ImageItem* child = new ImageItem(imageChannels[i], name+QString(" ")+ChannelsStrings[i], fileName, i);
multichannelImage->appendChild(child);
}
this->AddItem(multichannelImage);
}
else
{
ImageItem* item = new ImageItem(image, name, fileName, 0);
this->AddItem(item);
}
}
ImageItem* ImageModel::findImage(QString fileName)
{
ImageItem* root = static_cast<ImageItem*>(_root);
return root->findImage(fileName);
}