forked from situkangsayur/MouseHandTrackingLK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQCounturWidget.cpp
More file actions
executable file
·81 lines (74 loc) · 2.98 KB
/
Copy pathQCounturWidget.cpp
File metadata and controls
executable file
·81 lines (74 loc) · 2.98 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
74
75
76
77
78
79
80
/**
* MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
* Copyright (C) 2011 Hendri Karisma
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* contact author at situkangsayur[at]gmail[dot]com
*/
#include "QCounturWidget.h"
// Constructor
QCounturWidget::QCounturWidget(QWidget *parent) : QWidget(parent) {
layout = new QVBoxLayout;
imagelabel = new QLabel;
QImage dummy(100,100,QImage::Format_RGB32);
image = dummy;
layout->addWidget(imagelabel);
for (int x = 0; x < 100; x ++) {
for (int y =0; y < 100; y++) {
image.setPixel(x,y,qRgb(x, y, y));
}
}
imagelabel->setPixmap(QPixmap::fromImage(image));
setLayout(layout);
}
QCounturWidget::~QCounturWidget(void) {
}
void QCounturWidget::putImage(IplImage *cvimage) {
int cvIndex, cvLineStart;
// switch between bit depths
switch (cvimage->depth) {
case IPL_DEPTH_8U:
switch (cvimage->nChannels) {
case 3:
if ( (cvimage->width != image.width()) || (cvimage->height != image.height()) ) {
QImage temp(cvimage->width, cvimage->height, QImage::Format_RGB32);
image = temp;
}
cvIndex = 0; cvLineStart = 0;
for (int y = 0; y < cvimage->height; y++) {
unsigned char red,green,blue;
cvIndex = cvLineStart;
for (int x = 0; x < cvimage->width; x++) {
// DO it
red = cvimage->imageData[cvIndex+2];
green = cvimage->imageData[cvIndex+1];
blue = cvimage->imageData[cvIndex+0];
image.setPixel(x,y,qRgb(red, green, blue));
cvIndex += 3;
}
cvLineStart += cvimage->widthStep;
}
break;
default:
printf("This number of channels is not supported\n");
break;
}
break;
default:
printf("This type of IplImage is not implemented in QCounturWidget\n");
break;
}
imagelabel->setPixmap(QPixmap::fromImage(image));
}