-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.cpp
64 lines (59 loc) · 1.66 KB
/
images.cpp
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
#include "images.h"
#include "QImage"
#include "QGraphicsRectItem"
#include "QDebug"
images::images(cv::Mat &mat)
{
matrix=mat;
switch ( mat.type() )
{
case CV_8UC4:
{
image=QImage( mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB32 );
break;
}
case CV_8UC3:
{
image=QImage( mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB888 );
break;
}
case CV_8UC1:
{
static QVector<QRgb> sColorTable;
if ( sColorTable.isEmpty() )
{
for ( int i = 0; i < 256; ++i )
sColorTable.push_back( qRgb( i, i, i ) );
}
image=QImage( mat.data, mat.cols, mat.rows, mat.step, QImage::Format_Indexed8 );
image.setColorTable( sColorTable );
break;
}
default:
qDebug() << "ASM::cvMatToQImage() - cv::Mat image type not handled in switch:" << mat.type();
break;
}
pixmap=QPixmap::fromImage(image);
}
QPixmap images::getPixmap()
{
return pixmap;
}
cv::Mat images::getCvMat(void)
{
return matrix;
}
cv::Mat images::ellipseCrop(QGraphicsRectItem * rect)
{
cv::Rect myRoi(rect->rect().x(),rect->rect().y(),rect->rect().width(),rect->rect().height());
cv::Mat croppedImage;
cv::Point center(rect->rect().x()+rect->rect().width()/2,rect->rect().y()+rect->rect().height()/2);
cv::Size size(rect->rect().width()/2,rect->rect().height()/2);
cv::Mat im1(matrix.rows, matrix.cols, CV_8UC1, cv::Scalar(255,255,255));
cv::Mat im2(matrix.rows, matrix.cols, CV_8UC1, cv::Scalar(0,0,0));
cv::ellipse( im2, center, size, 0, 0, 360, cv::Scalar( 255, 255, 255), -1, 8 );
cv::ellipse( im1, center, size, 0, 0, 360, cv::Scalar( 0, 0, 0), -1, 8 );
cv::bitwise_and(matrix,im2,croppedImage);
cv::bitwise_xor(croppedImage,im1,croppedImage);
return croppedImage(myRoi);
}