├── images
├── GNU.jpg
├── GNU.png
├── exit.png
├── play.png
├── stop.png
├── contour.jpg
├── running.png
├── buttonStop.png
├── histogram.jpg
├── tombolStart.png
├── button Keluar.png
├── buttonContour.png
├── buttonHistogram.png
└── 7023332-human-hand-concept-made-of-100-icons-set-in-black-color.jpg
├── projectresource.qrc
├── CounturWindow.h
├── README.md
├── inhersistemview.cpp
├── inhersistemview.h
├── LICENSE
├── sistemview.cpp
├── main.cpp
├── dialoghelp.cpp
├── IColorSkinDetector.h
├── dialoghelp.h
├── sistemview.h
├── sistemcontroll.h
├── dialogcontour.h
├── dialogcontour.cpp
├── QCounturWidget.h
├── listener.h
├── dialoghistogram.cpp
├── QOpenCVWidget.h
├── QHistogramWidget.h
├── dialoghistogram.h
├── sistemcontroll.cpp
├── .gitignore
├── dialogcontour.ui
├── buttonwidget.h
├── CounturWindow.cpp
├── Image.h
├── HistogramWindow.h
├── HistogramWindow.cpp
├── dialoghistogram.ui
├── conhistogram.h
├── MyCameraWindow.h
├── YCrCbSkinDetector.h
├── handtracking.h
├── sistemmodel.h
├── inheritsistemview.h
├── conhistogram.cpp
├── QOpenCVWidget.cpp
├── QCounturWidget.cpp
├── MouseHandTrackingLK.pro
├── QHistogramWidget.cpp
├── handtracking.cpp
├── ConContour.h
├── sistemmodel.cpp
├── MyCameraWindow.cpp
├── inheritsistemview.cpp
├── dialoghelp.ui
├── sistemview.ui
└── ConContour.cpp
/images/GNU.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/GNU.jpg
--------------------------------------------------------------------------------
/images/GNU.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/GNU.png
--------------------------------------------------------------------------------
/images/exit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/exit.png
--------------------------------------------------------------------------------
/images/play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/play.png
--------------------------------------------------------------------------------
/images/stop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/stop.png
--------------------------------------------------------------------------------
/images/contour.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/contour.jpg
--------------------------------------------------------------------------------
/images/running.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/running.png
--------------------------------------------------------------------------------
/images/buttonStop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/buttonStop.png
--------------------------------------------------------------------------------
/images/histogram.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/histogram.jpg
--------------------------------------------------------------------------------
/images/tombolStart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/tombolStart.png
--------------------------------------------------------------------------------
/images/button Keluar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/button Keluar.png
--------------------------------------------------------------------------------
/images/buttonContour.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/buttonContour.png
--------------------------------------------------------------------------------
/images/buttonHistogram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/buttonHistogram.png
--------------------------------------------------------------------------------
/images/7023332-human-hand-concept-made-of-100-icons-set-in-black-color.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/situkangsayur/MouseHandTrackingLK/HEAD/images/7023332-human-hand-concept-made-of-100-icons-set-in-black-color.jpg
--------------------------------------------------------------------------------
/projectresource.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/7023332-human-hand-concept-made-of-100-icons-set-in-black-color.jpg
4 | images/contour.jpg
5 | images/exit.png
6 | images/GNU.jpg
7 | images/GNU.png
8 | images/histogram.jpg
9 | images/play.png
10 | images/stop.png
11 | images/buttonContour.png
12 | images/buttonHistogram.png
13 | images/button Keluar.png
14 | images/buttonStop.png
15 | images/tombolStart.png
16 | images/running.png
17 |
18 |
19 |
--------------------------------------------------------------------------------
/CounturWindow.h:
--------------------------------------------------------------------------------
1 | #ifndef COUNTURWINDOW_H_
2 | #define COUNTURWINDOW_H_
3 |
4 | #include
5 | #include
6 | #include "QCounturWidget.h"
7 | #include "qpushbutton.h"
8 | #include
9 | #include
10 |
11 |
12 |
13 | class CounturWindow : public QWidget
14 | {
15 | Q_OBJECT
16 | private:
17 | QCounturWidget *widgetCountur;
18 | CvCapture *camera;
19 |
20 | IplImage *image;
21 | int set;
22 |
23 | public:
24 |
25 | CounturWindow(QWidget *parent=0);
26 | ~CounturWindow();
27 |
28 | void setImage(IplImage *image);
29 |
30 | void setSet(int s);
31 |
32 | protected:
33 | void timerEvent(QTimerEvent*);
34 | };
35 |
36 |
37 | #endif /*ContourWindow_H_*/
38 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MouseHandTrackingLK
2 | Controlling Mouse Pointer using Hand Gesture via web-cam using opencv, pyramidal lucas-kanade algorithm, and skin filter
3 |
4 | contact author at situkangsayur[at]gmail[dot]com.
5 |
6 |
7 | The project using QT Framework for GUI and OpenCV for Computer Vision library.
8 | The methods that used in this project: skin color filter, convex hull, convexity defect and pyramidal lucas kanade for optical flow.
9 | Video demo : https://www.youtube.com/watch?v=jup99fg9ioQ
10 |
11 | news :
12 | http://news.okezone.com/read/2011/11/07/373/525723/operasikan-komputer-dengan-gerakkan-jari
13 | http://nasional.kompas.com/read/2011/10/06/19401852/Inilah.Pemenang.Indonesia.ICT.Award.2011
14 | http://berita.unikom.ac.id/berita/view/unikom-raih-emas-merit.w.html
15 | http://www.inaicta.web.id/inaicta/pemenang-inaicta-2011/
16 |
--------------------------------------------------------------------------------
/inhersistemview.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "inhersistemview.h"
21 |
22 | InherSistemView::InherSistemView()
23 | {
24 | }
25 |
--------------------------------------------------------------------------------
/inhersistemview.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 |
21 | #ifndef INHERSISTEMVIEW_H
22 | #define INHERSISTEMVIEW_H
23 |
24 | class InherSistemView
25 | {
26 | public:
27 | InherSistemView();
28 | };
29 |
30 | #endif // INHERSISTEMVIEW_H
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2011 Hendri Karisma
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/sistemview.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "sistemview.h"
21 |
22 |
23 | SIstemView::SIstemView(QWidget *parent) :
24 | QWidget(parent)
25 | {
26 | ui = new InheritSistemView(this);
27 | }
28 |
29 | SIstemView::~SIstemView()
30 | {
31 | ui->~InheritSistemView();
32 | }
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 |
21 | #include
22 |
23 | #include "sistemview.h"
24 |
25 |
26 | int main(int argc, char *argv[])
27 | {
28 | QApplication a(argc, argv);
29 | SIstemView w;
30 | w.setWindowTitle("OpenCV --> QtImage");
31 |
32 | w.show();
33 |
34 | return a.exec();
35 | }
36 |
--------------------------------------------------------------------------------
/dialoghelp.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "dialoghelp.h"
21 | #include "ui_dialoghelp.h"
22 |
23 | DialogHelp::DialogHelp(QWidget *parent) :
24 | QDialog(parent),
25 | ui(new Ui::DialogHelp)
26 | {
27 | ui->setupUi(this);
28 | }
29 |
30 | DialogHelp::~DialogHelp()
31 | {
32 | delete ui;
33 | }
34 |
35 | void DialogHelp::on_pushButton_clicked()
36 | {
37 | this->hide();
38 | }
39 |
--------------------------------------------------------------------------------
/IColorSkinDetector.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef ICOLORSKINDETECTOR_H
21 | #define ICOLORSKINDETECTOR_H
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include "Image.h"
28 |
29 | using namespace std;
30 | using namespace cv;
31 |
32 | class IColorSkinDetector{
33 |
34 | public:
35 | virtual IplImage *detectSkin(IplImage *img, CvScalar min, CvScalar max)=0;
36 | };
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/dialoghelp.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef DIALOGHELP_H
21 | #define DIALOGHELP_H
22 |
23 | #include
24 |
25 | namespace Ui {
26 | class DialogHelp;
27 | }
28 |
29 | class DialogHelp : public QDialog
30 | {
31 | Q_OBJECT
32 |
33 | public:
34 | explicit DialogHelp(QWidget *parent = 0);
35 | ~DialogHelp();
36 |
37 | private slots:
38 | void on_pushButton_clicked();
39 |
40 | private:
41 | Ui::DialogHelp *ui;
42 | };
43 |
44 | #endif // DIALOGHELP_H
45 |
--------------------------------------------------------------------------------
/sistemview.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef SISTEMVIEW_H
21 | #define SISTEMVIEW_H
22 |
23 | #include
24 | #include "inheritsistemview.h"
25 |
26 | namespace Ui {
27 | class SIstemView;
28 | }
29 |
30 | class SIstemView : public QWidget
31 | {
32 | Q_OBJECT
33 |
34 | public:
35 | explicit SIstemView(QWidget *parent = 0);
36 | ~SIstemView();
37 |
38 | private slots:
39 |
40 |
41 |
42 |
43 | private:
44 | InheritSistemView *ui;
45 | };
46 |
47 | #endif // SISTEMVIEW_H
48 |
--------------------------------------------------------------------------------
/sistemcontroll.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef SISTEMCONTROLL_H
21 | #define SISTEMCONTROLL_H
22 |
23 | #include "sistemmodel.h"
24 |
25 | class SistemControll
26 | {
27 | private :
28 | SistemModel *model;
29 |
30 | public:
31 | SistemControll();
32 |
33 | void setModel(SistemModel *model);
34 |
35 | void startTracking();
36 |
37 | void stopTracking();
38 |
39 | void startHistogram();
40 |
41 | void startContour();
42 |
43 | void showPetunjuk();
44 | };
45 |
46 | #endif // SISTEMCONTROLL_H
47 |
--------------------------------------------------------------------------------
/dialogcontour.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef DIALOGCONTOUR_H
21 | #define DIALOGCONTOUR_H
22 |
23 | #include
24 | #include "cv.h"
25 |
26 | namespace Ui {
27 | class DialogContour;
28 | }
29 |
30 | class DialogContour : public QDialog
31 | {
32 | Q_OBJECT
33 |
34 | public:
35 | explicit DialogContour(QWidget *parent = 0);
36 | ~DialogContour();
37 |
38 | void setCountur(IplImage *image, int i);
39 |
40 | private slots:
41 | void on_buttonTutup_clicked();
42 |
43 | private:
44 | Ui::DialogContour *ui;
45 | };
46 |
47 | #endif // DIALOGCONTOUR_H
48 |
--------------------------------------------------------------------------------
/dialogcontour.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "dialogcontour.h"
21 | #include "ui_dialogcontour.h"
22 |
23 | DialogContour::DialogContour(QWidget *parent) :
24 | QDialog(parent),
25 | ui(new Ui::DialogContour)
26 | {
27 | ui->setupUi(this);
28 | }
29 |
30 | DialogContour::~DialogContour()
31 | {
32 | delete ui;
33 | }
34 |
35 | void DialogContour::setCountur(IplImage *image,int i){
36 | this->ui->widgetCountur->setImage(image);
37 | this->ui->widgetCountur->setSet(i);
38 | }
39 |
40 | void DialogContour::on_buttonTutup_clicked()
41 | {
42 | this->hide();
43 | }
44 |
--------------------------------------------------------------------------------
/QCounturWidget.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef QCOUNTURWIDGET_H
21 | #define QCOUNTURWIDGET_H
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 | class QCounturWidget : public QWidget {
31 | private:
32 | QLabel *imagelabel;
33 | QVBoxLayout *layout;
34 |
35 | QImage image;
36 |
37 | public:
38 | QCounturWidget(QWidget *parent = 0);
39 | ~QCounturWidget(void);
40 | void putImage(IplImage *);
41 | };
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/listener.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 |
21 | #ifndef LISTENER_H
22 | #define LISTENER_H
23 |
24 | #include "cv.h"
25 |
26 | class listener
27 | {
28 | public:
29 | virtual void onStart()=0;
30 | virtual void onStop()=0;
31 | virtual void onHistogram()=0;
32 | virtual void onContour()=0;
33 | virtual void loadCountur(IplImage *image)=0;
34 | virtual void sinkronisasi(IplImage *image)=0;
35 | virtual void onTracking(CvPoint point, int state)=0;
36 | virtual void onPetunjuk()=0;
37 | };
38 |
39 | #endif // LISTENER_H
40 |
--------------------------------------------------------------------------------
/dialoghistogram.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "dialoghistogram.h"
21 | #include "ui_dialoghistogram.h"
22 |
23 | DialogHistogram::DialogHistogram(QWidget *parent) :
24 | QDialog(parent),
25 | ui(new Ui::DialogHistogram)
26 | {
27 | ui->setupUi(this);
28 | }
29 |
30 | DialogHistogram::~DialogHistogram()
31 | {
32 | delete ui;
33 | }
34 |
35 | void DialogHistogram::setQwidgetVal(IplImage *img,int val){
36 | ui->widgetHistogram->setSet(1);
37 | ui->widgetHistogram->setImage(img);
38 | }
39 |
40 | void DialogHistogram::on_buttonTutup_clicked()
41 | {
42 | this->hide();
43 | }
44 |
--------------------------------------------------------------------------------
/QOpenCVWidget.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef QOPENCVWIDGET_H
21 | #define QOPENCVWIDGET_H
22 |
23 | //#include "qmetatype.h"
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | class QOpenCVWidget : public QWidget {
32 | private:
33 | QLabel *imagelabel;
34 | QVBoxLayout *layout;
35 |
36 | QImage image;
37 |
38 | public:
39 | QOpenCVWidget(QWidget *parent = 0);
40 | ~QOpenCVWidget(void);
41 | void putImage(IplImage *);
42 | };
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/QHistogramWidget.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef QHISTOGRAMWIDGET_H
21 | #define QHISTOGRAMWIDGET_H
22 |
23 | //#include "qmetatype.h"
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | class QHistogramWidget : public QWidget {
32 | private:
33 | QLabel *imagelabel;
34 | QVBoxLayout *layout;
35 |
36 | QImage image;
37 |
38 | public:
39 | QHistogramWidget(QWidget *parent = 0);
40 | ~QHistogramWidget(void);
41 | void putImage(IplImage *);
42 | };
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/dialoghistogram.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef DIALOGHISTOGRAM_H
21 | #define DIALOGHISTOGRAM_H
22 |
23 | #include
24 | #include "cv.h"
25 | //#include "inherithistogramdialog.h"
26 |
27 | namespace Ui {
28 | class DialogHistogram;
29 | }
30 |
31 | class DialogHistogram : public QDialog
32 | {
33 | Q_OBJECT
34 |
35 | public:
36 | explicit DialogHistogram(QWidget *parent = 0);
37 | ~DialogHistogram();
38 |
39 | void setQwidgetVal(IplImage *img,int val);
40 |
41 | private slots:
42 | void on_buttonTutup_clicked();
43 |
44 | private:
45 | Ui::DialogHistogram *ui;
46 | };
47 |
48 | #endif // DIALOGHISTOGRAM_H
49 |
--------------------------------------------------------------------------------
/sistemcontroll.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "sistemcontroll.h"
21 |
22 | SistemControll::SistemControll()
23 | {
24 | }
25 |
26 | void SistemControll::startTracking(){
27 | model->doHandTracking();
28 | }
29 |
30 | void SistemControll::stopTracking(){
31 | model->doStopHandTracking();
32 | }
33 |
34 | void SistemControll::startHistogram(){
35 | model->getHistogram();
36 | }
37 |
38 | void SistemControll::startContour(){
39 | model->getContour();
40 | }
41 |
42 | void SistemControll::setModel(SistemModel *model){
43 | this->model = model;
44 |
45 | }
46 |
47 | void SistemControll::showPetunjuk(){
48 | model->tampilPetunjuk();
49 | }
50 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3 | .idea
4 |
5 | # User-specific stuff:
6 | .idea/workspace.xml
7 | .idea/tasks.xml
8 | .idea/dictionaries
9 | .idea/vcs.xml
10 | .idea/jsLibraryMappings.xml
11 |
12 | # Sensitive or high-churn files:
13 | .idea/dataSources.ids
14 | .idea/dataSources.xml
15 | .idea/dataSources.local.xml
16 | .idea/sqlDataSources.xml
17 | .idea/dynamic.xml
18 | .idea/uiDesigner.xml
19 |
20 | # Gradle:
21 | .idea/gradle.xml
22 | .idea/libraries
23 |
24 | # Mongo Explorer plugin:
25 | .idea/mongoSettings.xml
26 |
27 | ## File-based project format:
28 | *.iws
29 |
30 | ## Plugin-specific files:
31 |
32 | # IntelliJ
33 | /out/
34 |
35 | # mpeltonen/sbt-idea plugin
36 | .idea_modules/
37 |
38 | # JIRA plugin
39 | atlassian-ide-plugin.xml
40 |
41 | # Crashlytics plugin (for Android Studio and IntelliJ)
42 | com_crashlytics_export_strings.xml
43 | crashlytics.properties
44 | crashlytics-build.properties
45 | fabric.properties
46 |
47 | # C++ objects and libs
48 |
49 | *.slo
50 | *.lo
51 | *.o
52 | *.a
53 | *.la
54 | *.lai
55 | *.so
56 | *.dll
57 | *.dylib
58 |
59 | # Qt-es
60 |
61 | /.qmake.cache
62 | /.qmake.stash
63 | *.pro.user
64 | *.pro.user.*
65 | *.qbs.user
66 | *.qbs.user.*
67 | *.moc
68 | moc_*.cpp
69 | qrc_*.cpp
70 | ui_*.h
71 | Makefile*
72 | *build-*
73 |
74 | # QtCreator
75 |
76 | *.autosave
77 |
78 | # QtCtreator Qml
79 | *.qmlproject.user
80 | *.qmlproject.user.*
81 |
82 | # QtCtreator CMake
83 | CMakeLists.txt.user*
84 |
85 |
--------------------------------------------------------------------------------
/dialogcontour.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | DialogContour
4 |
5 |
6 |
7 | 0
8 | 0
9 | 642
10 | 485
11 |
12 |
13 |
14 |
15 | 642
16 | 485
17 |
18 |
19 |
20 |
21 | 642
22 | 485
23 |
24 |
25 |
26 | Dialog
27 |
28 |
29 |
30 |
31 | 0
32 | 0
33 | 641
34 | 481
35 |
36 |
37 |
38 | -
39 |
40 |
41 | -
42 |
43 |
44 | &Tutup
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | CounturWindow
54 | QWidget
55 |
56 | 1
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/buttonwidget.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef BUTTONWIDGET_H
21 | #define BUTTONWIDGET_H
22 |
23 | #include
24 |
25 | class ButtonWidget : public QWidget
26 | {
27 | Q_OBJECT
28 | public :
29 | int state;
30 | int histogram;
31 | int contour;
32 |
33 | public:
34 | explicit ButtonWidget(QWidget *parent = 0);
35 | void setState(int state);
36 | void setHistogram(int histogram);
37 | void setContour(int conrour);
38 | int getState();
39 | int getHistogram();
40 | int getContour();
41 |
42 |
43 | signals:
44 |
45 | public slots:
46 | void startTrackingTangan();
47 | void stopTrackingTangan();
48 | void startHistogram();
49 | void startContour();
50 | void exitApp();
51 |
52 | };
53 |
54 | #endif // BUTTONWIDGET_H
55 |
--------------------------------------------------------------------------------
/CounturWindow.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "CounturWindow.h"
21 |
22 | CounturWindow::CounturWindow(QWidget *parent) : QWidget(parent) {
23 |
24 | QVBoxLayout *layout = new QVBoxLayout;
25 | widgetCountur= new QCounturWidget(this);
26 |
27 | layout->addWidget(widgetCountur);
28 | setLayout(layout);
29 | resize(640, 480);
30 | image=0;
31 |
32 | startTimer(100); // 0.1-second timer
33 | }
34 |
35 | CounturWindow::~CounturWindow(){
36 | delete widgetCountur;
37 | delete image;
38 | }
39 |
40 |
41 | void CounturWindow::setImage(IplImage *image){
42 | this->image = image;
43 | }
44 |
45 | void CounturWindow::setSet(int s){
46 | this->set = s;
47 | }
48 |
49 | void CounturWindow::timerEvent(QTimerEvent*) {
50 |
51 | if(image != 0){
52 | if(set==1){
53 | widgetCountur->putImage(image);
54 | }else{
55 | widgetCountur->putImage(image);
56 | }
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/Image.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef IMAGE_H
21 | #define IMAGE_H
22 |
23 | #include "cv.h"
24 | #include
25 | #include
26 |
27 |
28 | template class Image {
29 |
30 | private:
31 | IplImage *imgp;
32 |
33 | public:
34 | Image(IplImage *img = 0) {
35 | imgp = img;
36 | }
37 | ~Image() {
38 | imgp = 0;
39 | }
40 | void operator=(IplImage *img) {
41 | imgp = img;
42 | }
43 | inline T* operator[](const int rowIndex) {
44 | return ((T*) (imgp->imageData + rowIndex * imgp->widthStep));
45 | }
46 | };
47 |
48 | typedef struct {
49 | unsigned char b, g, r;
50 | } RgbPixel;
51 | typedef struct {
52 | float b, g, r;
53 | } RgbPixelFloat;
54 |
55 | typedef struct {
56 | float Cr, Y, Cb;
57 | } YCrCbPixel;
58 |
59 | typedef struct {
60 | float H;
61 | } GrayPixel;
62 |
63 | typedef Image RgbImage;
64 | typedef Image YcrCbImage;
65 | typedef Image GrayImage;
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/HistogramWindow.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef MYCAMERAWINDOW_H_
21 | #define MYCAMERAWINDOW_H_
22 |
23 | #include
24 | #include
25 | #include "QOpenCVWidget.h"
26 | #include "qpushbutton.h"
27 | #include "iostream"
28 | #include
29 | #include
30 | #include "QHistogramWidget.h"
31 | #include "conhistogram.h"
32 | //#include "handtracking.h"
33 | //#include "ConContour.h"
34 |
35 |
36 | class HistogramWindow : public QWidget
37 | {
38 | Q_OBJECT
39 | private:
40 | QHistogramWidget *widgetHistogram;
41 |
42 | ConHistogram *histogram;
43 |
44 | IplImage *img;
45 |
46 | int set;
47 |
48 | public:
49 |
50 | HistogramWindow(QWidget *parent=0);
51 |
52 | void setSet(int s);
53 | void setImage(IplImage *image);
54 |
55 | protected:
56 | void timerEvent(QTimerEvent*);
57 | };
58 |
59 |
60 | #endif /*MYCAMERAWINDOW_H_*/
61 |
--------------------------------------------------------------------------------
/HistogramWindow.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "HistogramWindow.h"
21 |
22 | HistogramWindow::HistogramWindow(QWidget *parent) : QWidget(parent) {
23 | QVBoxLayout *layout = new QVBoxLayout;
24 | widgetHistogram= new QHistogramWidget(this);
25 |
26 | layout->addWidget(widgetHistogram);
27 | setLayout(layout);
28 | resize(320, 200);
29 | histogram = new ConHistogram();
30 |
31 | startTimer(100); // 0.1-second timer
32 | }
33 |
34 |
35 | void HistogramWindow::setSet(int s){
36 | this->set = s;
37 | }
38 |
39 | void HistogramWindow::setImage(IplImage *image){
40 | this->img= image;
41 | }
42 |
43 | void HistogramWindow::timerEvent(QTimerEvent*) {
44 | if(img != 0){
45 | if(set==1){
46 | histogram->setFrame(img);
47 | histogram->progressImage();
48 | widgetHistogram->putImage(histogram->getHistimg());
49 | std::cout<<"in == 1"<
2 |
3 | DialogHistogram
4 |
5 |
6 |
7 | 0
8 | 0
9 | 321
10 | 250
11 |
12 |
13 |
14 |
15 | 0
16 | 0
17 |
18 |
19 |
20 |
21 | 321
22 | 250
23 |
24 |
25 |
26 |
27 | 321
28 | 250
29 |
30 |
31 |
32 | Dialog
33 |
34 |
35 |
36 |
37 | 0
38 | 0
39 | 321
40 | 251
41 |
42 |
43 |
44 | -
45 |
46 |
47 | -
48 |
49 |
50 | &Tutup
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | HistogramWindow
60 | QWidget
61 |
62 | 1
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/conhistogram.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef CONHISTOGRAM_H
21 | #define CONHISTOGRAM_H
22 |
23 | #include "iostream"
24 | #include "cv.h"
25 | #include "highgui.h"
26 | #include "cvaux.h"
27 |
28 | using namespace std;
29 |
30 | class ConHistogram {
31 | public:
32 | IplImage *frame;
33 | IplImage *singleFrame;
34 | IplImage *histimg;
35 |
36 | CvHistogram *hist;
37 |
38 | int hdims;
39 | float hranges_arr[2];
40 | float* hranges;
41 | int bin_w;
42 | float max_val;
43 | int i;
44 | double val;
45 | CvScalar color;
46 |
47 | public:
48 | ConHistogram();
49 | ~ConHistogram();
50 |
51 | //accessor
52 | IplImage *getFrame();
53 |
54 | CvHistogram *getHist();
55 |
56 | IplImage *getHistimg();
57 |
58 | IplImage *getSingleFrame();
59 |
60 | void setFrame(IplImage *frame);
61 |
62 | void setHist(CvHistogram *hist);
63 |
64 | void setHistimg(IplImage *histimg);
65 |
66 | void setSingleFrame(IplImage *singleFrame);
67 |
68 | public:
69 | //main methode
70 | void progressImage();
71 |
72 | void drawHistogram();
73 |
74 | };
75 |
76 | #endif
77 |
78 |
--------------------------------------------------------------------------------
/MyCameraWindow.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef MYCAMERAWINDOW_H_
21 | #define MYCAMERAWINDOW_H_
22 |
23 | #include
24 | #include
25 | #include
26 | #include "iostream"
27 | #include "cv.h"
28 | #include "highgui.h"
29 | #include "ConContour.h"
30 | #include "sistemmodel.h"
31 | #include
32 |
33 |
34 |
35 | class MyCameraWindow : public QWidget
36 | {
37 | Q_OBJECT
38 | private:
39 | QOpenCVWidget *cvwidget;
40 | CvCapture *camera;
41 |
42 | IplImage *image;
43 | IplImage *black;
44 | IplImage *gray;
45 |
46 | ConContour *cont;
47 |
48 | SistemModel *model;
49 |
50 | int state;
51 | int histogram;
52 | int countur;
53 |
54 | public:
55 | MyCameraWindow( QWidget *parent=0);
56 |
57 | void setModel(SistemModel *model);
58 | void setState(int state);
59 | void setHistogram(int histogram);
60 | void setContour(int conrtour);
61 | int getState();
62 | int getHistogram();
63 | int getContour();
64 |
65 | protected:
66 | void timerEvent(QTimerEvent*);
67 |
68 |
69 |
70 | };
71 |
72 |
73 | #endif /*MYCAMERAWINDOW_H_*/
74 |
--------------------------------------------------------------------------------
/YCrCbSkinDetector.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef YCRCBSKINDETECTOR_H
21 | #define YCRCBSKINDETECTOR_H
22 |
23 | #include "cv.h"
24 | #include "cvaux.h"
25 | #include "highgui.h"
26 | //#include "image.h"
27 | #include "IColorSkinDetector.h"
28 |
29 | using namespace std;
30 | //using namespace cv;
31 |
32 | class YCrCbSkindetector: public IColorSkinDetector {
33 | public:
34 | IplImage *currentYCrCbFrame;
35 | IplImage *skin;
36 |
37 | IplConvKernel *rect_12;
38 | IplConvKernel *rect_6;
39 |
40 | public:
41 |
42 | YCrCbSkindetector() {
43 | currentYCrCbFrame = 0;
44 | skin = 0;
45 |
46 | rect_12 = 0;
47 |
48 | rect_6 = 0;
49 | }
50 |
51 | IplImage *detectSkin(IplImage *img, CvScalar min, CvScalar max) {
52 |
53 | if (currentYCrCbFrame == 0) {
54 | currentYCrCbFrame = cvCreateImage(cvGetSize(img), img->depth, 3);
55 | }
56 | if (skin == 0) {
57 | skin = cvCreateImage(cvGetSize(img), img->depth, 1);
58 | }
59 |
60 | cvCvtColor(img, currentYCrCbFrame, CV_BGR2YCrCb);
61 |
62 | cvInRangeS(currentYCrCbFrame, min, max, skin);
63 |
64 |
65 | if (rect_12 == 0) {
66 | rect_12 = cvCreateStructuringElementEx(12, 12, 6, 6, CV_SHAPE_RECT);
67 | }
68 | cvErode(skin, skin, rect_12, 1);
69 |
70 | if (rect_6 == 0) {
71 | rect_6 = cvCreateStructuringElementEx(6, 6, 3, 3, CV_SHAPE_RECT);
72 | }
73 |
74 | cvDilate(skin, skin, rect_6, 2);
75 |
76 | return skin;
77 | }
78 | };
79 | #endif
80 |
--------------------------------------------------------------------------------
/handtracking.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef HANDTRACKING_H
21 | #define HANDTRACKING_H
22 |
23 | #include "iostream"
24 | #include "math.h"
25 | #include "cv.h"
26 | #include "cvaux.h"
27 | #include "highgui.h"
28 | #include "X11/Xlib.h"
29 | #include "X11/extensions/XTest.h"
30 |
31 | #include "Image.h"
32 | using namespace std;
33 |
34 | using namespace cv;
35 |
36 | class HandTracking {
37 |
38 | private:
39 |
40 | Display *dpy;
41 |
42 |
43 |
44 | // Where to start the search from
45 | int searchx;
46 | int searchy;
47 |
48 |
49 | CvPoint p0;
50 | CvPoint p1;
51 |
52 | // What state is the mouse in now
53 |
54 |
55 | //IplImage *currentFrame;
56 |
57 | int stateX;
58 | int stateY;
59 | int konX;
60 | int konY;
61 |
62 | int countx;
63 | int county;
64 |
65 | int state;
66 |
67 | int redx;
68 | int redy;
69 | int starth;
70 |
71 | public:
72 |
73 | HandTracking();
74 | ~HandTracking();
75 |
76 | void setDefault();
77 |
78 | void setState(int state);
79 |
80 | void setP0(CvPoint point);
81 |
82 | void setP1(CvPoint point);
83 |
84 | // in case I want to add mouse handling to the window later
85 | void on_mouse(int event, int x, int y, int flags, void* param);
86 |
87 | // Fill in the red region and identify its center of gravity
88 | void trackPoint(Display *dpy);
89 |
90 | void play();
91 |
92 | void getResult();
93 |
94 |
95 |
96 | };
97 |
98 | #endif // HANDTRACKING_H
99 |
--------------------------------------------------------------------------------
/sistemmodel.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef SISTEMMODEL_H
21 | #define SISTEMMODEL_H
22 |
23 | #include "iostream"
24 | #include "listener.h"
25 | #include "cv.h"
26 | //#include "handtracking.h"
27 |
28 | class SistemModel
29 | {
30 | private :
31 |
32 | int ptX;
33 | int ptY;
34 | CvPoint point;
35 | listener *listen;
36 | IplImage *image;
37 | IplImage *countur;
38 |
39 | int state;
40 |
41 |
42 | public:
43 | SistemModel();
44 |
45 | void setPtX(int ptX);
46 | void setPtY(int ptY);
47 |
48 | int getPtX();
49 | int getPtY();
50 | void setImage(IplImage *image);
51 | void setCountur(IplImage *countur);
52 |
53 | void setPoint(CvPoint points);
54 | CvPoint getPoint();
55 |
56 | void setState(int state);
57 | int getState();
58 |
59 | void setListener(listener *list);
60 |
61 | void doHandTracking();
62 | void doStopHandTracking();
63 |
64 | void getHistogram();
65 |
66 | void getContour();
67 |
68 | void setSingkronisasiMouse();
69 |
70 | void singkronisasiHis();
71 |
72 | void loadCountur();
73 |
74 | void tampilPetunjuk();
75 |
76 | //void doTracking();
77 |
78 | protected :
79 | void fireOnStart();
80 | void fireOnStop();
81 | void fireOnHistogram();
82 | void fireOnContour();
83 | void fireOnSingkronisasi();
84 | void fireOnTracking();
85 | void fireOnLoadCountur();
86 | void fireOnPetunjuk();
87 | };
88 |
89 | #endif // SISTEMMODEL_H
90 |
--------------------------------------------------------------------------------
/inheritsistemview.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef INHERITSISTEMVIEW_H
21 | #define INHERITSISTEMVIEW_H
22 |
23 | #include
24 | #include
25 | #include "iostream"
26 | #include "ui_sistemview.h"
27 | #include "stdlib.h"
28 | #include "listener.h"
29 |
30 | #include "sistemmodel.h"
31 | #include "sistemcontroll.h"
32 | #include "cv.h"
33 | #include "handtracking.h"
34 | #include "dialoghistogram.h"
35 | #include "dialogcontour.h"
36 | #include "dialoghelp.h"
37 |
38 |
39 | using namespace std;
40 |
41 |
42 | class InheritSistemView : public QWidget, public Ui::SIstemView,public listener
43 | {
44 | Q_OBJECT
45 |
46 | public :
47 | SistemModel *model;
48 | SistemControll *controll;
49 | HandTracking *tracking;
50 |
51 | DialogHistogram *histogram;
52 | DialogContour *countur;
53 | IplImage *hist;
54 | IplImage *cou;
55 | DialogHelp *help;
56 |
57 |
58 | public:
59 | explicit
60 | InheritSistemView(QWidget *parent = 0);
61 | ~InheritSistemView();
62 |
63 | signals:
64 |
65 | public :
66 | void onStart();
67 | void onStop();
68 | void onHistogram();
69 | void onContour();
70 | void onTracking(CvPoint point, int state);
71 | void sinkronisasi(IplImage *image);
72 | void loadCountur(IplImage *image);
73 | void onPetunjuk();
74 |
75 |
76 |
77 | public slots:
78 | void on_buttonStart_clicked();
79 | void on_buttonStop_clicked();
80 | void on_buttonHistogram_clicked();
81 | void on_buttonContour_clicked();
82 | void on_buttonExit_clicked();
83 | void on_buttonPetunjuk_clicked();
84 |
85 | };
86 |
87 | #endif // INHERITSISTEMVIEW_H
88 |
--------------------------------------------------------------------------------
/conhistogram.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "conhistogram.h"
21 |
22 | ConHistogram::ConHistogram() {
23 |
24 | frame = 0;
25 | singleFrame = 0;
26 | histimg = cvCreateImage(cvSize(320, 200), 8, 3);
27 | singleFrame = 0;
28 |
29 | hist = 0;
30 |
31 | hdims = 50;
32 | hranges_arr[0] = 0;
33 | hranges_arr[1] = 255;
34 | hranges = hranges_arr;
35 | bin_w = 0;
36 | i = 0;
37 |
38 | hist = cvCreateHist(1, &hdims, CV_HIST_ARRAY, &hranges, 1);
39 |
40 | color = CV_RGB(101,255,0);
41 | }
42 |
43 | ConHistogram::~ConHistogram() {
44 |
45 | }
46 |
47 | IplImage *ConHistogram::getFrame() {
48 | return frame;
49 | }
50 |
51 | CvHistogram *ConHistogram::getHist() {
52 | return hist;
53 | }
54 |
55 | IplImage *ConHistogram::getHistimg() {
56 | return histimg;
57 | }
58 |
59 | IplImage *ConHistogram::getSingleFrame() {
60 | return singleFrame;
61 | }
62 |
63 | void ConHistogram::setFrame(IplImage *frame) {
64 | this->frame = frame;
65 | }
66 |
67 | void ConHistogram::setHist(CvHistogram *hist) {
68 | this->hist = hist;
69 | }
70 |
71 | void ConHistogram::setHistimg(IplImage *histimg) {
72 | this->histimg = histimg;
73 | }
74 |
75 | void ConHistogram::setSingleFrame(IplImage *singleFrame) {
76 | this->singleFrame = singleFrame;
77 | }
78 |
79 | void ConHistogram::progressImage() {
80 |
81 | if(singleFrame == 0){
82 | singleFrame=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1);
83 | }
84 | cvCvtColor(frame, frame, CV_RGB2HSV);
85 | cvSplit(frame, singleFrame, NULL, NULL, NULL);
86 | drawHistogram();
87 |
88 | }
89 |
90 | void ConHistogram::drawHistogram() {
91 |
92 | cvZero(histimg);
93 | cvCalcHist(&singleFrame, hist, 0, 0);
94 | cvGetMinMaxHistValue(hist, 0, &max_val, 0, 0);
95 |
96 | cvConvertScale(hist->bins, hist->bins, max_val ? 255. / max_val : 0., 0);
97 |
98 | bin_w = histimg->width / hdims;
99 |
100 |
101 | for (i = 0; i < hdims; i++) {
102 | val = (cvGetReal1D(hist->bins, i) * (histimg->height - 5) / 255);
103 |
104 | cvRectangle(histimg, cvPoint(i * bin_w, histimg->height),
105 | cvPoint((i + 1) * bin_w, (int) (histimg->height - val)), color,
106 | 1, 8, 0);
107 | }
108 | cout << hdims << endl;
109 | }
110 |
111 |
--------------------------------------------------------------------------------
/QOpenCVWidget.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "QOpenCVWidget.h"
21 |
22 | // Constructor
23 | QOpenCVWidget::QOpenCVWidget(QWidget *parent) : QWidget(parent) {
24 | layout = new QVBoxLayout;
25 | imagelabel = new QLabel;
26 | QImage dummy(100,100,QImage::Format_RGB32);
27 | image = dummy;
28 | layout->addWidget(imagelabel);
29 | for (int x = 0; x < 100; x ++) {
30 | for (int y =0; y < 100; y++) {
31 | image.setPixel(x,y,qRgb(x, y, y));
32 | }
33 | }
34 | imagelabel->setPixmap(QPixmap::fromImage(image));
35 |
36 | setLayout(layout);
37 | }
38 |
39 | QOpenCVWidget::~QOpenCVWidget(void) {
40 |
41 | }
42 |
43 | void QOpenCVWidget::putImage(IplImage *cvimage) {
44 | int cvIndex, cvLineStart;
45 | // switch between bit depths
46 | switch (cvimage->depth) {
47 | case IPL_DEPTH_8U:
48 | switch (cvimage->nChannels) {
49 | case 3:
50 | if ( (cvimage->width != image.width()) || (cvimage->height != image.height()) ) {
51 | QImage temp(cvimage->width, cvimage->height, QImage::Format_RGB32);
52 | image = temp;
53 | }
54 | cvIndex = 0; cvLineStart = 0;
55 | for (int y = 0; y < cvimage->height; y++) {
56 | unsigned char red,green,blue;
57 | cvIndex = cvLineStart;
58 | for (int x = 0; x < cvimage->width; x++) {
59 | // DO it
60 | red = cvimage->imageData[cvIndex+2];
61 | green = cvimage->imageData[cvIndex+1];
62 | blue = cvimage->imageData[cvIndex+0];
63 |
64 | image.setPixel(x,y,qRgb(red, green, blue));
65 | cvIndex += 3;
66 | }
67 | cvLineStart += cvimage->widthStep;
68 | }
69 | break;
70 | default:
71 | printf("This number of channels is not supported\n");
72 | break;
73 | }
74 | break;
75 | default:
76 | printf("This type of IplImage is not implemented in QOpenCVWidget\n");
77 | break;
78 | }
79 | imagelabel->setPixmap(QPixmap::fromImage(image));
80 | }
81 |
82 |
--------------------------------------------------------------------------------
/QCounturWidget.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "QCounturWidget.h"
21 |
22 | // Constructor
23 | QCounturWidget::QCounturWidget(QWidget *parent) : QWidget(parent) {
24 | layout = new QVBoxLayout;
25 | imagelabel = new QLabel;
26 | QImage dummy(100,100,QImage::Format_RGB32);
27 | image = dummy;
28 | layout->addWidget(imagelabel);
29 | for (int x = 0; x < 100; x ++) {
30 | for (int y =0; y < 100; y++) {
31 | image.setPixel(x,y,qRgb(x, y, y));
32 | }
33 | }
34 | imagelabel->setPixmap(QPixmap::fromImage(image));
35 |
36 | setLayout(layout);
37 | }
38 |
39 | QCounturWidget::~QCounturWidget(void) {
40 |
41 | }
42 |
43 | void QCounturWidget::putImage(IplImage *cvimage) {
44 | int cvIndex, cvLineStart;
45 | // switch between bit depths
46 | switch (cvimage->depth) {
47 | case IPL_DEPTH_8U:
48 | switch (cvimage->nChannels) {
49 | case 3:
50 | if ( (cvimage->width != image.width()) || (cvimage->height != image.height()) ) {
51 | QImage temp(cvimage->width, cvimage->height, QImage::Format_RGB32);
52 | image = temp;
53 | }
54 | cvIndex = 0; cvLineStart = 0;
55 | for (int y = 0; y < cvimage->height; y++) {
56 | unsigned char red,green,blue;
57 | cvIndex = cvLineStart;
58 | for (int x = 0; x < cvimage->width; x++) {
59 | // DO it
60 | red = cvimage->imageData[cvIndex+2];
61 | green = cvimage->imageData[cvIndex+1];
62 | blue = cvimage->imageData[cvIndex+0];
63 |
64 | image.setPixel(x,y,qRgb(red, green, blue));
65 | cvIndex += 3;
66 | }
67 | cvLineStart += cvimage->widthStep;
68 | }
69 | break;
70 | default:
71 | printf("This number of channels is not supported\n");
72 | break;
73 | }
74 | break;
75 | default:
76 | printf("This type of IplImage is not implemented in QCounturWidget\n");
77 | break;
78 | }
79 | imagelabel->setPixmap(QPixmap::fromImage(image));
80 | }
81 |
82 |
--------------------------------------------------------------------------------
/MouseHandTrackingLK.pro:
--------------------------------------------------------------------------------
1 | #
2 | # MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | # Copyright (C) 2011 Hendri Karisma
4 | #
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 | #
18 | # contact author at situkangsayur[at]gmail[dot]com
19 | #
20 | #-------------------------------------------------
21 | #
22 | # Project created by QtCreator 2011-06-16T19:26:35
23 | #
24 | #-------------------------------------------------
25 |
26 | QT += core gui
27 | TARGET = MouseHandTrackingLK
28 | DEPENDPATH += .
29 | TEMPLATE = app
30 |
31 |
32 | INCLUDEPATH += /usr/local/include \
33 | /usr/include/opencv \
34 | /usr/lib
35 | LIBS += -lX11 \
36 | -lXtst \
37 | -lopencv_core \
38 | -lopencv_imgproc \
39 | -lopencv_calib3d \
40 | -lopencv_video \
41 | -lopencv_features2d \
42 | -lopencv_ml \
43 | -lopencv_highgui \
44 | -lopencv_objdetect \
45 | -lopencv_contrib \
46 | -lopencv_legacy
47 |
48 |
49 |
50 | SOURCES += main.cpp\
51 | sistemview.cpp \
52 | QOpenCVWidget.cpp \
53 | MyCameraWindow.cpp \
54 | sistemcontroll.cpp \
55 | sistemmodel.cpp \
56 | ConContour.cpp \
57 | inheritsistemview.cpp \
58 | handtracking.cpp \
59 | conhistogram.cpp \
60 | HistogramWindow.cpp \
61 | dialoghistogram.cpp \
62 | QHistogramWidget.cpp \
63 | dialogcontour.cpp \
64 | QCounturWidget.cpp \
65 | CounturWindow.cpp \
66 | dialoghelp.cpp
67 |
68 | HEADERS += sistemview.h \
69 | QOpenCVWidget.h \
70 | MyCameraWindow.h \
71 | sistemcontroll.h \
72 | listener.h \
73 | sistemmodel.h \
74 | YCrCbSkinDetector.h \
75 | Image.h \
76 | IColorSkinDetector.h \
77 | ConContour.h \
78 | inheritsistemview.h \
79 | handtracking.h \
80 | conhistogram.h \
81 | HistogramWindow.h \
82 | dialoghistogram.h \
83 | QHistogramWidget.h \
84 | dialogcontour.h \
85 | QCounturWidget.h \
86 | CounturWindow.h \
87 | dialoghelp.h
88 |
89 | FORMS += sistemview.ui \
90 | dialoghistogram.ui \
91 | dialogcontour.ui \
92 | dialoghelp.ui
93 |
94 | OTHER_FILES += \
95 | images/stop.png \
96 | images/play.png \
97 | images/histogram.jpg \
98 | images/GNU.png \
99 | images/exit.png \
100 | images/contour.jpg \
101 | images/7023332-human-hand-concept-made-of-100-icons-set-in-black-color.jpg \
102 | images/tombolStart.png \
103 | images/buttonStop.png \
104 | images/button Keluar.png \
105 | images/buttonHistogram.png \
106 | images/buttonContour.png
107 |
108 | RESOURCES += \
109 | projectresource.qrc
110 |
--------------------------------------------------------------------------------
/QHistogramWidget.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "QHistogramWidget.h"
21 |
22 | // Constructor
23 | QHistogramWidget::QHistogramWidget(QWidget *parent) : QWidget(parent) {
24 | layout = new QVBoxLayout;
25 | imagelabel = new QLabel;
26 | QImage dummy(100,100,QImage::Format_RGB32);
27 | image = dummy;
28 | layout->addWidget(imagelabel);
29 | for (int x = 0; x < 100; x ++) {
30 | for (int y =0; y < 100; y++) {
31 | image.setPixel(x,y,qRgb(x, y, y));
32 | }
33 | }
34 | imagelabel->setPixmap(QPixmap::fromImage(image));
35 |
36 | setLayout(layout);
37 | }
38 |
39 | QHistogramWidget::~QHistogramWidget(void) {
40 |
41 | }
42 |
43 | void QHistogramWidget::putImage(IplImage *cvimage) {
44 | int cvIndex, cvLineStart;
45 | // switch between bit depths
46 | switch (cvimage->depth) {
47 | case IPL_DEPTH_8U:
48 | switch (cvimage->nChannels) {
49 | case 3:
50 | if ( (cvimage->width != image.width()) || (cvimage->height != image.height()) ) {
51 | QImage temp(cvimage->width, cvimage->height, QImage::Format_RGB32);
52 | image = temp;
53 | }
54 | cvIndex = 0; cvLineStart = 0;
55 | for (int y = 0; y < cvimage->height; y++) {
56 | unsigned char red,green,blue;
57 | cvIndex = cvLineStart;
58 | for (int x = 0; x < cvimage->width; x++) {
59 | // DO it
60 | red = cvimage->imageData[cvIndex+2];
61 | green = cvimage->imageData[cvIndex+1];
62 | blue = cvimage->imageData[cvIndex+0];
63 |
64 | image.setPixel(x,y,qRgb(red, green, blue));
65 | cvIndex += 3;
66 | }
67 | cvLineStart += cvimage->widthStep;
68 | }
69 | break;
70 | default:
71 | printf("This number of channels is not supported\n");
72 | break;
73 | }
74 | break;
75 | default:
76 | printf("This type of IplImage is not implemented in QHistogramWidget\n");
77 | break;
78 | }
79 | imagelabel->setPixmap(QPixmap::fromImage(image));
80 | }
81 |
82 |
--------------------------------------------------------------------------------
/handtracking.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "handtracking.h"
21 |
22 | using namespace std;
23 |
24 | void HandTracking::setP0(CvPoint point) {
25 | p0 = point;
26 |
27 | }
28 | void HandTracking::setP1(CvPoint point) {
29 | p1 = point;
30 | }
31 |
32 | HandTracking::HandTracking() {
33 | dpy = XOpenDisplay(0);
34 |
35 | searchx = -1;
36 | searchy = -1;
37 |
38 | // How big to make the starting region
39 |
40 |
41 | // How big the last starting region was
42 |
43 | state = 5;
44 | countx = 1;
45 | county = 1;
46 | stateX = 0;
47 | stateY = 0;
48 | konX = 0;
49 | konY = 0;
50 | }
51 |
52 | HandTracking::~HandTracking() {
53 | XTestFakeButtonEvent(dpy, 1, 0, 0);
54 | XTestFakeButtonEvent(dpy, 2, 0, 0);
55 | XTestFakeButtonEvent(dpy, 3, 0, 0);
56 | XFlush(dpy);
57 | }
58 |
59 | void HandTracking::setDefault(){
60 | XTestFakeButtonEvent(dpy, 1, 0, 0);
61 | XTestFakeButtonEvent(dpy, 2, 0, 0);
62 | XTestFakeButtonEvent(dpy, 3, 0, 0);
63 | XFlush(dpy);
64 | }
65 |
66 | void HandTracking::trackPoint(Display *dpy) {
67 |
68 |
69 | redx = ((p1.x / (640 / 100)) * (1550 / 100));
70 | redy = ((p1.y / (480 / 100)) * (890 / 100));
71 |
72 | if (redx < searchx) {
73 | redx -= countx;
74 | stateX = 0;
75 | } else {
76 | stateX = 1;
77 | }
78 |
79 | if (redy < searchy) {
80 |
81 | redy -= county;
82 | stateY = 0;
83 |
84 | } else {
85 |
86 | stateY = 1;
87 | }
88 |
89 | if (countx <= 10) {
90 | countx++;
91 | }
92 | if (county <= 10) {
93 | county++;
94 | }
95 |
96 | cout << redx << "&" << redy << countx << endl;
97 |
98 | // move the mouse to the red region's center of gravity
99 | XTestFakeMotionEvent(dpy, DefaultScreen (dpy), redx, redy, 0);
100 |
101 | if ((redx <= 0) || (konX != stateX)) {
102 | countx = 1;
103 | }
104 | if ((redy <= 0) || (konY != stateY)) {
105 | county = 1;
106 | }
107 |
108 | konX = stateX;
109 | konY = stateY;
110 |
111 | searchx = redx;
112 | searchy = redy;
113 |
114 | if (state == 0 || state == 1) {
115 | XTestFakeButtonEvent(dpy, 1, 1, 0);
116 | }
117 |
118 | if (state == 3) {
119 | XTestFakeButtonEvent(dpy, 2, 1, 0);
120 | }
121 |
122 | if (state >= 4) {
123 | XTestFakeButtonEvent(dpy, 1, 0, 0);
124 | XTestFakeButtonEvent(dpy, 2, 0, 0);
125 | XTestFakeButtonEvent(dpy, 3, 0, 0);
126 | }
127 |
128 | if (state == 2) {
129 | XTestFakeButtonEvent(dpy, 3, 1, 0);
130 | //XTestFakeButtonEvent(dpy, 3, 0, 0);
131 | }
132 |
133 |
134 | XFlush(dpy);
135 |
136 | }
137 |
138 |
139 | void HandTracking::getResult() {
140 |
141 | trackPoint(dpy);
142 |
143 |
144 | }
145 | void HandTracking::setState(int state) {
146 | this->state = state;
147 | }
148 |
--------------------------------------------------------------------------------
/ConContour.h:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #ifndef CONCONTOUR_H
21 | #define CONCONTOUR_H
22 |
23 | #include
24 | #include
25 | #include "Image.h"
26 | #include
27 | //#include "math.h"
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 |
36 | #include "IColorSkinDetector.h"
37 | #include "YCrCbSkinDetector.h"
38 | #include "Image.h"
39 |
40 | using namespace std;
41 |
42 | const int MAX_CORNERS = 500;
43 |
44 | class ConContour {
45 |
46 | private:
47 | IColorSkinDetector *skinDetection;
48 | IplImage *img;
49 | IplImage *currentFrame;
50 | IplImage *tempImage;
51 | //IplImage *currentFrameCopy;
52 | IplImage *skinTemp;
53 |
54 | IplImage *skin;
55 | //lucas kanade
56 | IplImage *pyrdA;
57 | IplImage *pyrdB;
58 | IplImage *eig_image;
59 | IplImage *tmp_image;
60 | CvPoint2D32f *cornersA;
61 |
62 | CvSize img_sz;
63 |
64 | CvSize pyr_sz;
65 | IplImage *tempPyrA;
66 | IplImage *tempPyrB;
67 | CvPoint2D32f *cornersB;
68 |
69 | int win_size;
70 |
71 | char features_found[MAX_CORNERS];
72 | float feature_errors[MAX_CORNERS];
73 | //end object for lucas kanade
74 |
75 | //VideoCapture frame;
76 | //CvCapture *grabber;
77 |
78 | // CvAdaptiveSkinDetector *adaptiveSkinDetector;
79 |
80 | int frameWidth;
81 | int frameHeight;
82 |
83 | CvScalar hsvMin;
84 | CvScalar hsvMax;
85 |
86 | CvScalar yccMin;
87 | CvScalar yccMax;
88 |
89 | CvSeq *hull;
90 |
91 | CvSeq *filtereHull;
92 |
93 | CvSeq *defect;
94 | //CvPoint **arrPoint;
95 | CvPoint *arrHull;
96 | CvConvexityDefect *defectArray;
97 | CvRect *handRect;
98 |
99 | CvBox2D box;
100 |
101 | CvFont font;
102 |
103 | char number;
104 |
105 | CvMemStorage *gStorage;
106 |
107 | CvSeq *biggestContour;
108 |
109 | CvSeq *currentContour;
110 | CvSeq *contour;
111 |
112 | //===========================================
113 | CvPoint startPoint;
114 | CvPoint depthPoint;
115 | CvPoint endPoint;
116 |
117 | CvPoint *setPoint;
118 |
119 | int fingerNum;
120 |
121 | CvPoint p0;
122 | CvPoint p1;
123 | //CvPoint *setPoint;
124 |
125 | private:
126 | void drawAndComputeFingerNum();
127 | void checkGStorage(int i);
128 |
129 | public:
130 | ConContour();
131 | ~ConContour();
132 |
133 | //void getYCrCb(IplImage *temp, int x, int y, int z);
134 |
135 | void lukas_canade();
136 |
137 | void frameGrabber();
138 |
139 | void extractContourAndHull(IplImage *skin);
140 |
141 | IplImage *getCurrentFrame();
142 |
143 | void setCurrentFrame(IplImage *image);
144 |
145 |
146 | //CvCapture *getGrabber();
147 |
148 | IplImage *getSkin();
149 | IplImage *getImg();
150 | int getFingerNum();
151 | CvPoint getP0();
152 | CvPoint getp1();
153 | //void clean();
154 | };
155 |
156 | #endif
157 |
--------------------------------------------------------------------------------
/sistemmodel.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "sistemmodel.h"
21 |
22 | SistemModel::SistemModel()
23 | {
24 | }
25 |
26 |
27 | void SistemModel::setPtX(int ptX){
28 | this->ptX = ptX;
29 | }
30 |
31 | void SistemModel::setPtY(int ptY){
32 | this->ptY = ptY;
33 | }
34 |
35 | int SistemModel::getPtX(){
36 | return ptX;
37 | }
38 |
39 | int SistemModel::getPtY(){
40 | return ptY;
41 | }
42 |
43 | void SistemModel::setImage(IplImage *image){
44 | this->image = image;
45 | }
46 |
47 | void SistemModel::setCountur(IplImage *countur){
48 | this->countur = countur;
49 | }
50 |
51 | void SistemModel::setPoint(CvPoint points){
52 | this->point = points;
53 | }
54 |
55 | CvPoint SistemModel::getPoint(){
56 | return this->point;
57 | }
58 |
59 | void SistemModel::setState(int state){
60 | this->state = state;
61 | }
62 |
63 | int SistemModel::getState(){
64 | return state;
65 | }
66 |
67 | void SistemModel::setListener(listener *list){
68 | this->listen = list;
69 | }
70 |
71 | void SistemModel::fireOnStart(){
72 | if(listen != NULL){
73 | listen->onStart();
74 | }
75 | }
76 |
77 | void SistemModel::fireOnStop(){
78 | if(listen != NULL){
79 | listen->onStop();
80 | }
81 | }
82 |
83 | void SistemModel::fireOnHistogram(){
84 | if(listen != NULL){
85 | listen->onHistogram();
86 | }
87 | }
88 |
89 | void SistemModel::fireOnContour(){
90 | if(listen != NULL){
91 | listen->onContour();
92 | }
93 | }
94 |
95 | void SistemModel::fireOnSingkronisasi(){
96 | if(listen != NULL){
97 | listen->sinkronisasi(image);
98 | }
99 | }
100 |
101 |
102 | void SistemModel::fireOnTracking(){
103 | if(listen != NULL){
104 | listen->onTracking(this->point, this->state);
105 | }
106 | }
107 |
108 | void SistemModel::fireOnLoadCountur(){
109 | if(listen != NULL){
110 | listen->loadCountur(countur);
111 | }
112 | }
113 |
114 | void SistemModel::fireOnPetunjuk(){
115 | if(listen!=NULL){
116 | listen->onPetunjuk();
117 | }
118 | }
119 |
120 |
121 |
122 | void SistemModel::doHandTracking(){
123 | fireOnStart();
124 | }
125 |
126 | void SistemModel::doStopHandTracking(){
127 | fireOnStop();
128 | }
129 |
130 |
131 | void SistemModel::getHistogram(){
132 | fireOnHistogram();
133 | }
134 |
135 | void SistemModel::getContour(){
136 | fireOnContour();
137 | }
138 |
139 | void SistemModel::setSingkronisasiMouse(){
140 | fireOnTracking();
141 | }
142 |
143 | void SistemModel::singkronisasiHis(){
144 | fireOnSingkronisasi();
145 | }
146 |
147 | void SistemModel::loadCountur(){
148 | fireOnLoadCountur();
149 | }
150 |
151 | void SistemModel::tampilPetunjuk(){
152 | fireOnPetunjuk();
153 | }
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/MyCameraWindow.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "MyCameraWindow.h"
21 |
22 | MyCameraWindow::MyCameraWindow( QWidget *parent) : QWidget(parent) {
23 |
24 |
25 | camera = cvCreateCameraCapture(1);
26 |
27 | if (!camera) {
28 | camera= cvCaptureFromCAM(0);
29 | //cout << "hhheeeaarrrr...\n";
30 |
31 | }
32 |
33 | if (!camera) {
34 | cout << "Could not initialize capturing...\n";
35 | return;
36 | }
37 |
38 | assert(camera);
39 |
40 | image = 0;
41 | black = 0;
42 | state = 0;
43 | histogram = 0;
44 | countur = 0;
45 |
46 | cont = new ConContour();
47 |
48 |
49 | QVBoxLayout *layout = new QVBoxLayout;
50 | cvwidget = new QOpenCVWidget(this);
51 | layout->addWidget(cvwidget);
52 | setLayout(layout);
53 | resize(640, 480);
54 |
55 | startTimer(100); // 0.1-second timer
56 |
57 | }
58 |
59 | void MyCameraWindow::timerEvent(QTimerEvent*) {
60 | image = cvQueryFrame(camera);
61 | if(black == 0){
62 | black = cvCreateImage(cvSize(image->width,image->height),image->depth,image->nChannels);
63 | }
64 | if(gray == 0){
65 | gray = cvCreateImage(cvSize(image->width,image->height),image->depth,1);
66 | }
67 |
68 | if(state == 1){
69 |
70 | cont->setCurrentFrame(image);
71 | cont->frameGrabber();
72 |
73 |
74 | model->setState(cont->getFingerNum()
75 |
76 | );
77 | model->setPoint(cont->getp1());
78 |
79 |
80 | model->setSingkronisasiMouse();
81 |
82 |
83 | image=cont->getCurrentFrame();
84 |
85 | model->setImage(image);
86 |
87 | cvCvtColor(cont->getSkin(),black,CV_GRAY2BGR);
88 |
89 | model->setCountur(black);
90 | if(countur == 1){
91 | model->loadCountur();
92 | }
93 |
94 | if(histogram == 1){
95 | cout<<"masuk histogram 1"<singkronisasiHis();
97 | }
98 |
99 | }else{
100 | cvFlip(image,0,1);
101 | cvCvtColor(image,gray,CV_RGB2GRAY);
102 | cvCvtColor(gray,black,CV_GRAY2BGR);
103 |
104 | model->setImage(image);
105 | model->setCountur(black);
106 |
107 | if(countur == 1){
108 | model->loadCountur();
109 | }
110 |
111 | if(histogram == 1){
112 | cout<<"masuk histogram 1"<singkronisasiHis();
114 | }
115 |
116 | }
117 | cvwidget->putImage(image);
118 |
119 | }
120 |
121 | void MyCameraWindow::setModel(SistemModel *model){
122 | this->model = model;
123 | }
124 |
125 |
126 | void MyCameraWindow::setState(int state){
127 | this->state = state;
128 | }
129 |
130 | void MyCameraWindow::setHistogram(int histogram){
131 | this->histogram = histogram;
132 | }
133 |
134 | void MyCameraWindow::setContour(int contour){
135 | this->countur = contour;
136 | }
137 |
138 | int MyCameraWindow::getState(){
139 | return state;
140 | }
141 |
142 | int MyCameraWindow::getHistogram(){
143 | return histogram;
144 | }
145 |
146 | int MyCameraWindow::getContour(){
147 | return countur;
148 | }
149 |
150 |
--------------------------------------------------------------------------------
/inheritsistemview.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 |
21 | #include "inheritsistemview.h"
22 |
23 | InheritSistemView::InheritSistemView(QWidget *parent) :
24 | QWidget(parent)
25 | {
26 | setupUi(parent);
27 |
28 | model = new SistemModel();
29 | controll = new SistemControll();
30 |
31 | model->setListener(this);
32 | controll->setModel(model);
33 |
34 | tracking = new HandTracking();
35 |
36 |
37 |
38 | widgetOpenCV->setModel(model);
39 |
40 | hist = 0;
41 | cou = 0;
42 | connect(buttonStart,SIGNAL(clicked()),this,SLOT(on_buttonStart_clicked()));
43 | connect(buttonStop,SIGNAL(clicked()),this,SLOT(on_buttonStop_clicked()));
44 | connect(buttonHistogram,SIGNAL(clicked()),this,SLOT(on_buttonHistogram_clicked()));
45 | connect(buttonContour,SIGNAL(clicked()),this,SLOT(on_buttonContour_clicked()));
46 | connect(buttonExit,SIGNAL(clicked()),this,SLOT(on_buttonExit_clicked()));
47 | connect(buttonPetunjuk,SIGNAL(clicked()),this,SLOT(on_buttonPetunjuk_clicked()));
48 |
49 | histogram = new DialogHistogram();
50 | histogram->hide();
51 |
52 | countur = new DialogContour();
53 | countur->hide();
54 |
55 | help = new DialogHelp();
56 | help->hide();
57 |
58 | }
59 |
60 | InheritSistemView::~InheritSistemView(){
61 | tracking->~HandTracking();
62 | histogram->~DialogHistogram();
63 | delete this;
64 | }
65 |
66 |
67 | void InheritSistemView::on_buttonStart_clicked(){
68 | cout<<"button start"<startTracking();
70 |
71 | }
72 |
73 | void InheritSistemView::on_buttonStop_clicked(){
74 |
75 | controll->stopTracking();
76 |
77 | }
78 |
79 | void InheritSistemView::on_buttonHistogram_clicked(){
80 |
81 | controll->startHistogram();
82 | }
83 |
84 | void InheritSistemView::on_buttonContour_clicked(){
85 |
86 | controll->startContour();
87 | }
88 |
89 | void InheritSistemView::on_buttonExit_clicked(){
90 | cout<<"button Stop"<~InheritSistemView();
92 | }
93 |
94 | void InheritSistemView::on_buttonPetunjuk_clicked(){
95 | controll->showPetunjuk();
96 | }
97 |
98 | void InheritSistemView::onStart(){
99 | cout<<"onStart "<setState(1);
102 |
103 | }
104 |
105 | void InheritSistemView::onStop(){
106 | cout<<"onStop "<setState(0);
108 | tracking->setDefault();
109 | }
110 |
111 | void InheritSistemView::onHistogram(){
112 | cout<<"onHistogram "<isHidden()){
114 | widgetOpenCV->setHistogram(1);
115 | histogram->show();
116 | }else{
117 | widgetOpenCV->setHistogram(0);
118 | histogram->hide();
119 | }
120 |
121 | }
122 |
123 | void InheritSistemView::onContour(){
124 | cout<<"onContour "<isHidden()){
126 | widgetOpenCV->setContour(1);
127 | countur->show();
128 | }else{
129 | widgetOpenCV->setContour(0);
130 | countur->hide();
131 | }
132 | }
133 |
134 | void InheritSistemView::onTracking(CvPoint point, int state){
135 | cout<<"get tracker.."<setP1(point);
137 | tracking->setState(state);
138 | tracking->getResult();
139 | }
140 |
141 | void InheritSistemView::sinkronisasi(IplImage *image){
142 | if(hist == 0){
143 | hist = cvCreateImage(cvSize(image->width,image->height),image->depth,image->nChannels);
144 | }
145 | cvCopy(image,hist);
146 | histogram->setQwidgetVal(hist,1);
147 | }
148 |
149 | void InheritSistemView::loadCountur(IplImage *image){
150 | if(cou == 0){
151 | cou = cvCreateImage(cvSize(image->width,image->height),image->depth,image->nChannels);
152 | }
153 | cvCopy(image, cou);
154 | countur->setCountur(cou,1);
155 |
156 | }
157 |
158 | void InheritSistemView::onPetunjuk(){
159 | if(help->isHidden()){
160 | help->show();
161 | }else{
162 | help->hide();
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/dialoghelp.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | DialogHelp
4 |
5 |
6 |
7 | 0
8 | 0
9 | 658
10 | 548
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 |
18 |
19 | 0
20 | 0
21 | 661
22 | 491
23 |
24 |
25 |
26 |
27 | 16777215
28 | 16777215
29 |
30 |
31 |
32 | 1
33 |
34 |
35 |
36 | Petunjunk Pemakaian
37 |
38 |
39 |
40 |
41 | 170
42 | 120
43 | 67
44 | 17
45 |
46 |
47 |
48 | Stop
49 |
50 |
51 |
52 |
53 |
54 | 30
55 | 300
56 | 121
57 | 61
58 |
59 |
60 |
61 |
62 |
63 |
64 | :/image/images/buttonContour.png
65 |
66 |
67 |
68 |
69 |
70 | 30
71 | 120
72 | 101
73 | 61
74 |
75 |
76 |
77 |
78 |
79 |
80 | :/image/images/buttonStop.png
81 |
82 |
83 |
84 |
85 |
86 | 170
87 | 190
88 | 67
89 | 17
90 |
91 |
92 |
93 | Histogram
94 |
95 |
96 |
97 |
98 |
99 | 170
100 | 380
101 | 67
102 | 17
103 |
104 |
105 |
106 | Exit
107 |
108 |
109 |
110 |
111 |
112 | 170
113 | 280
114 | 67
115 | 17
116 |
117 |
118 |
119 | Contour
120 |
121 |
122 |
123 |
124 |
125 | 30
126 | 10
127 | 151
128 | 17
129 |
130 |
131 |
132 | Petunjuk Pemakaian
133 |
134 |
135 |
136 |
137 |
138 | 30
139 | 380
140 | 101
141 | 61
142 |
143 |
144 |
145 |
146 |
147 |
148 | :/image/images/button Keluar.png
149 |
150 |
151 |
152 |
153 |
154 | 170
155 | 310
156 | 411
157 | 51
158 |
159 |
160 |
161 | Menampilkan kondisi citra/gambar yang sebenarnya dilihat komputer, setelah dilakukan segmentasi atau pemisahan objek tangan dan background atau tekan "ctrl+C"
162 |
163 |
164 | true
165 |
166 |
167 |
168 |
169 |
170 | 170
171 | 60
172 | 411
173 | 51
174 |
175 |
176 |
177 | Tombol untuk memulai sistem pengontrol mouse pointer dengan Hand Tracking atau tekan "ctrl+A"
178 |
179 |
180 | true
181 |
182 |
183 |
184 |
185 |
186 | 30
187 | 200
188 | 121
189 | 61
190 |
191 |
192 |
193 |
194 |
195 |
196 | :/image/images/buttonHistogram.png
197 |
198 |
199 |
200 |
201 |
202 | 170
203 | 400
204 | 411
205 | 51
206 |
207 |
208 |
209 | Keluar dari program Pengontroll Mouse Pointer dengan Hand Tracking atau tekan "ctrl+K"
210 |
211 |
212 | true
213 |
214 |
215 |
216 |
217 |
218 | 170
219 | 40
220 | 67
221 | 17
222 |
223 |
224 |
225 | Start
226 |
227 |
228 |
229 |
230 |
231 | 30
232 | 40
233 | 91
234 | 61
235 |
236 |
237 |
238 |
239 |
240 |
241 | :/image/images/tombolStart.png
242 |
243 |
244 |
245 |
246 |
247 | 170
248 | 130
249 | 411
250 | 51
251 |
252 |
253 |
254 | Tombol untuk menghentikan sistem pengontrol mouse pointer dengan Hand Tracking atau tekan "ctrl+S"
255 |
256 |
257 | true
258 |
259 |
260 |
261 |
262 |
263 | 170
264 | 210
265 | 411
266 | 51
267 |
268 |
269 |
270 | Menampilkan visualisasi dari komputasi citra/gambar yang sedang ditampilkan dalam bentuk histogram atau tekan "ctrl+H"
271 |
272 |
273 | true
274 |
275 |
276 |
277 |
278 |
279 | Petunjuk Tampilan
280 |
281 |
282 |
283 |
284 | 0
285 | 0
286 | 651
287 | 461
288 |
289 |
290 |
291 |
292 |
293 |
294 | :/image/images/running.png
295 |
296 |
297 | true
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 | 30
306 | 500
307 | 361
308 | 31
309 |
310 |
311 |
312 | Mouse Pointer Controll With hand Tracking System.
313 |
314 |
315 |
316 |
317 |
318 | 540
319 | 500
320 | 101
321 | 41
322 |
323 |
324 |
325 | &Tutup
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
--------------------------------------------------------------------------------
/sistemview.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | SIstemView
4 |
5 |
6 |
7 | 0
8 | 0
9 | 690
10 | 650
11 |
12 |
13 |
14 |
15 | 65
16 | 60
17 |
18 |
19 |
20 |
21 | 690
22 | 650
23 |
24 |
25 |
26 |
27 | 720
28 | 650
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | 0
38 | 0
39 | 0
40 |
41 |
42 |
43 |
44 |
45 |
46 | 135
47 | 140
48 | 242
49 |
50 |
51 |
52 |
53 |
54 |
55 | 251
56 | 251
57 | 255
58 |
59 |
60 |
61 |
62 |
63 |
64 | 193
65 | 195
66 | 248
67 |
68 |
69 |
70 |
71 |
72 |
73 | 67
74 | 70
75 | 121
76 |
77 |
78 |
79 |
80 |
81 |
82 | 90
83 | 93
84 | 161
85 |
86 |
87 |
88 |
89 |
90 |
91 | 0
92 | 0
93 | 0
94 |
95 |
96 |
97 |
98 |
99 |
100 | 255
101 | 255
102 | 255
103 |
104 |
105 |
106 |
107 |
108 |
109 | 0
110 | 0
111 | 0
112 |
113 |
114 |
115 |
116 |
117 |
118 | 255
119 | 255
120 | 255
121 |
122 |
123 |
124 |
125 |
126 |
127 | 135
128 | 140
129 | 242
130 |
131 |
132 |
133 |
134 |
135 |
136 | 0
137 | 0
138 | 0
139 |
140 |
141 |
142 |
143 |
144 |
145 | 195
146 | 197
147 | 248
148 |
149 |
150 |
151 |
152 |
153 |
154 | 255
155 | 255
156 | 220
157 |
158 |
159 |
160 |
161 |
162 |
163 | 0
164 | 0
165 | 0
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 | 0
175 | 0
176 | 0
177 |
178 |
179 |
180 |
181 |
182 |
183 | 135
184 | 140
185 | 242
186 |
187 |
188 |
189 |
190 |
191 |
192 | 251
193 | 251
194 | 255
195 |
196 |
197 |
198 |
199 |
200 |
201 | 193
202 | 195
203 | 248
204 |
205 |
206 |
207 |
208 |
209 |
210 | 67
211 | 70
212 | 121
213 |
214 |
215 |
216 |
217 |
218 |
219 | 90
220 | 93
221 | 161
222 |
223 |
224 |
225 |
226 |
227 |
228 | 0
229 | 0
230 | 0
231 |
232 |
233 |
234 |
235 |
236 |
237 | 255
238 | 255
239 | 255
240 |
241 |
242 |
243 |
244 |
245 |
246 | 0
247 | 0
248 | 0
249 |
250 |
251 |
252 |
253 |
254 |
255 | 255
256 | 255
257 | 255
258 |
259 |
260 |
261 |
262 |
263 |
264 | 135
265 | 140
266 | 242
267 |
268 |
269 |
270 |
271 |
272 |
273 | 0
274 | 0
275 | 0
276 |
277 |
278 |
279 |
280 |
281 |
282 | 195
283 | 197
284 | 248
285 |
286 |
287 |
288 |
289 |
290 |
291 | 255
292 | 255
293 | 220
294 |
295 |
296 |
297 |
298 |
299 |
300 | 0
301 | 0
302 | 0
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 | 67
312 | 70
313 | 121
314 |
315 |
316 |
317 |
318 |
319 |
320 | 135
321 | 140
322 | 242
323 |
324 |
325 |
326 |
327 |
328 |
329 | 251
330 | 251
331 | 255
332 |
333 |
334 |
335 |
336 |
337 |
338 | 193
339 | 195
340 | 248
341 |
342 |
343 |
344 |
345 |
346 |
347 | 67
348 | 70
349 | 121
350 |
351 |
352 |
353 |
354 |
355 |
356 | 90
357 | 93
358 | 161
359 |
360 |
361 |
362 |
363 |
364 |
365 | 67
366 | 70
367 | 121
368 |
369 |
370 |
371 |
372 |
373 |
374 | 255
375 | 255
376 | 255
377 |
378 |
379 |
380 |
381 |
382 |
383 | 67
384 | 70
385 | 121
386 |
387 |
388 |
389 |
390 |
391 |
392 | 135
393 | 140
394 | 242
395 |
396 |
397 |
398 |
399 |
400 |
401 | 135
402 | 140
403 | 242
404 |
405 |
406 |
407 |
408 |
409 |
410 | 0
411 | 0
412 | 0
413 |
414 |
415 |
416 |
417 |
418 |
419 | 135
420 | 140
421 | 242
422 |
423 |
424 |
425 |
426 |
427 |
428 | 255
429 | 255
430 | 220
431 |
432 |
433 |
434 |
435 |
436 |
437 | 0
438 | 0
439 | 0
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 | SIstemView
448 |
449 |
450 |
451 |
452 | 0
453 | 0
454 | 691
455 | 651
456 |
457 |
458 |
459 | -
460 |
461 |
462 |
463 | 0
464 | 0
465 |
466 |
467 |
468 |
469 | 680
470 | 510
471 |
472 |
473 |
474 |
475 | 680
476 | 500
477 |
478 |
479 |
480 |
481 | -
482 |
483 |
484 |
485 | 680
486 | 100
487 |
488 |
489 |
490 |
491 | 680
492 | 100
493 |
494 |
495 |
496 |
497 |
498 | 20
499 | 10
500 | 91
501 | 61
502 |
503 |
504 |
505 | true
506 |
507 |
508 | St&art
509 |
510 |
511 |
512 | :/image/images/play.png:/image/images/play.png
513 |
514 |
515 |
516 | 31
517 | 30
518 |
519 |
520 |
521 | true
522 |
523 |
524 |
525 |
526 |
527 | 240
528 | 10
529 | 121
530 | 61
531 |
532 |
533 |
534 | &Histogram
535 |
536 |
537 |
538 | :/image/images/histogram.jpg:/image/images/histogram.jpg
539 |
540 |
541 |
542 | 31
543 | 30
544 |
545 |
546 |
547 |
548 |
549 |
550 | 360
551 | 10
552 | 111
553 | 61
554 |
555 |
556 |
557 | &Contour
558 |
559 |
560 |
561 | :/image/images/7023332-human-hand-concept-made-of-100-icons-set-in-black-color.jpg:/image/images/7023332-human-hand-concept-made-of-100-icons-set-in-black-color.jpg
562 |
563 |
564 |
565 | 31
566 | 30
567 |
568 |
569 |
570 |
571 |
572 |
573 | 580
574 | 10
575 | 91
576 | 61
577 |
578 |
579 |
580 | &Keluar
581 |
582 |
583 |
584 | :/image/images/exit.png:/image/images/exit.png
585 |
586 |
587 |
588 | 29
589 | 30
590 |
591 |
592 |
593 |
594 |
595 |
596 | 120
597 | 10
598 | 91
599 | 61
600 |
601 |
602 |
603 | &Stop
604 |
605 |
606 |
607 | :/image/images/stop.png:/image/images/stop.png
608 |
609 |
610 |
611 | 31
612 | 30
613 |
614 |
615 |
616 |
617 |
618 |
619 | 480
620 | 10
621 | 81
622 | 61
623 |
624 |
625 |
626 | &Petunjuk
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 | MyCameraWindow
638 | QWidget
639 |
640 | 1
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 | on_buttonStart_clicked()
649 |
650 |
651 |
--------------------------------------------------------------------------------
/ConContour.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
3 | * Copyright (C) 2011 Hendri Karisma
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | *
18 | * contact author at situkangsayur[at]gmail[dot]com
19 | */
20 | #include "ConContour.h"
21 |
22 | using namespace std;
23 |
24 | int ConContour::getFingerNum() {
25 | return fingerNum;
26 | }
27 |
28 | CvPoint ConContour::getP0() {
29 | return p0;
30 | }
31 | CvPoint ConContour::getp1() {
32 | return p1;
33 | }
34 |
35 | IplImage *ConContour::getImg() {
36 | return img;
37 | }
38 |
39 | IplImage *ConContour::getSkin() {
40 | return skin;
41 | }
42 |
43 | IplImage *ConContour::getCurrentFrame() {
44 | return currentFrame;
45 | }
46 |
47 | void ConContour::setCurrentFrame(IplImage *image) {
48 | currentFrame = image;
49 | }
50 |
51 | void ConContour::checkGStorage(int i) {
52 |
53 | if (gStorage == NULL) {
54 | gStorage = cvCreateMemStorage(0);
55 | } else {
56 | cvClearMemStorage(gStorage);
57 | }
58 |
59 | }
60 |
61 | ConContour::~ConContour() {
62 | //bersih2
63 | //cvReleaseCapture(&grabber);
64 | cvReleaseImage(&tempImage);
65 | //cvReleasesImage(¤tContour);
66 | cvReleaseImage(¤tFrame);
67 | //cvReleaseImage(¤tFrameCopy);
68 | cvReleaseImage(&skinTemp);
69 | cvReleaseImage(&img);
70 | cvReleaseImage(&tempImage);
71 | cvReleaseImage(&pyrdA);
72 | cvReleaseImage(&pyrdB);
73 | //cvReleaseCapture(&grabber);
74 | //cvRelease(//ull);
75 | //cvRelease(&filtereHull);
76 | //cvRelease(&biggestContour);
77 | //cvRelease(&defect);
78 |
79 | }
80 |
81 | ConContour::ConContour() {
82 |
83 | //inisialisasi
84 |
85 |
86 | tempImage = 0;
87 | currentFrame = 0;
88 | //currentFrameCopy = 0;
89 | skinDetection = new YCrCbSkindetector();
90 | img = 0;
91 | skin = 0;
92 | skinTemp = 0;
93 | //for lucas kanade========
94 | pyrdA = 0;
95 | pyrdB = 0;
96 | //img_sz = 0;
97 | eig_image = 0;
98 | tmp_image = 0;
99 |
100 | cornersA = new CvPoint2D32f[MAX_CORNERS];
101 |
102 | //pyr_sz = 0;
103 | tempPyrA = 0;
104 | tempPyrB = 0;
105 | cornersB = 0;
106 |
107 | win_size = 10;
108 |
109 | cornersB = new CvPoint2D32f[MAX_CORNERS];
110 |
111 | //end for lucas kanade
112 |
113 |
114 | //for mouse
115 | fingerNum = 0;
116 |
117 |
118 |
119 | hull = NULL;
120 |
121 | filtereHull = NULL;
122 |
123 | defect = NULL;
124 |
125 | //CvBox2D box=NULL;
126 |
127 | biggestContour = NULL;
128 | /*
129 | grabber = cvCaptureFromCAM(1);
130 | //grabber = cvCaptureFromFile("M2U00253.MPG");
131 |
132 | if (!grabber) {
133 | grabber = cvCaptureFromCAM(0);
134 | //cout << "hhheeeaarrrr...\n";
135 |
136 | }
137 |
138 | // cout << "set capture...\n";
139 |
140 | if (!grabber) {
141 | cout << "Could not initialize capturing...\n";
142 | return;
143 | }
144 | */
145 | //inisialisasi storage
146 | gStorage = NULL;
147 |
148 | //cvNamedWindow("windows", 1);
149 | //cvNamedWindow("result", 1);
150 |
151 | //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
152 | //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);
153 |
154 | frameWidth = 320;
155 | frameHeight = 240;
156 | //nilai warna kulit
157 | yccMin = cvScalar(0, 131, 80);
158 | yccMax = cvScalar(245, 185, 135);
159 |
160 | hsvMin = cvScalar(0, 30, 80, 0);
161 | hsvMax = cvScalar(20, 150, 255, 0);
162 | //skin detector , but unused
163 | //adaptiveSkinDetector = new CvAdaptiveSkinDetector(1,CvAdaptiveSkinDetector::MORPHING_METHOD_ERODE_DILATE);
164 |
165 | }
166 |
167 | void ConContour::frameGrabber() {
168 | //grabber, mengambil query frame
169 | //currentFrame = cvQueryFrame(grabber);
170 |
171 | if (!currentFrame) {
172 | return;
173 | }
174 |
175 | cvFlip(currentFrame, 0, 1);
176 | //persiapan image untuk pyramidal lucas kanade
177 |
178 | if ((pyrdA == 0) && (pyrdB == 0)) {
179 | pyrdA = cvCreateImage(
180 | cvSize(currentFrame->width, currentFrame->height),
181 | currentFrame->depth, 1);
182 | pyrdB = cvCreateImage(
183 | cvSize(currentFrame->width, currentFrame->height),
184 | currentFrame->depth, 1);
185 | img = cvCreateImage(cvSize(currentFrame->width, currentFrame->height),
186 | currentFrame->depth, currentFrame->nChannels);
187 | tempImage = cvCreateImage(
188 | cvSize(currentFrame->width, currentFrame->height),
189 | currentFrame->depth, currentFrame->nChannels);
190 | }
191 |
192 | //copy frame sementara
193 | /*
194 | if (currentFrameCopy == 0) {
195 | currentFrameCopy = cvCreateImage(
196 | cvSize(currentFrame->width, currentFrame->height),
197 | currentFrame->depth, currentFrame->nChannels);
198 | }
199 | */
200 |
201 | //copy frame utama ke temporary frame
202 | // cvCopyImage(currentFrame, currentFrameCopy);
203 |
204 | //image untuk menyimpan kontur image skin
205 | if (skin == 0) {
206 | skin = cvCreateImage(cvSize(currentFrame->width, currentFrame->height),
207 | currentFrame->depth, 1);
208 |
209 | }
210 |
211 | //tempat penyimpanan sementara kontur, hasil threshold
212 |
213 | if (skinTemp == 0) {
214 | skinTemp = cvCreateImage(
215 | cvSize(currentFrame->width, currentFrame->height),
216 | currentFrame->depth, 1);
217 |
218 | }
219 |
220 | //pendeteksi warna kulit dengan warna YCrCb
221 |
222 | try {
223 | //adaptiveSkinDetector->process(currentFrameCopy,skinTemp);
224 | skin = skinDetection->detectSkin(currentFrame, yccMin, yccMax);
225 | cvCopy(skin, skinTemp);
226 |
227 | //mengambil kontur dari edge skin yang didapat
228 |
229 | extractContourAndHull(skinTemp);
230 |
231 | //konversi gambar titik tengah dari img ke pyrdA "grayscale"
232 | cvCvtColor(img, pyrdA, CV_BGR2GRAY);
233 |
234 | //menggambar kontur convexity defects dan menghitung jumlah jari
235 |
236 | drawAndComputeFingerNum();
237 |
238 | //pencarian pergerakan tangan dengan lucas kanade
239 |
240 | lukas_canade();
241 |
242 | //ambil lokasi sebelumnya dari titik tengah tangan manusia..
243 | cvCopy(pyrdA, pyrdB);
244 |
245 | // menghapus gambar img menjadi hitam kembali
246 | cvCopy(tempImage, img);
247 | // return skin;
248 | } catch (cv::Exception e) {
249 | cout << e.msg << endl;
250 | }
251 |
252 | //free(&defectArray);
253 | //return currentFrame;
254 | }
255 |
256 | void ConContour::extractContourAndHull(IplImage *skin) {
257 | //inisialisasi storage
258 |
259 | checkGStorage(1);
260 | checkGStorage(2);
261 | checkGStorage(3);
262 | checkGStorage(4);
263 | checkGStorage(5);
264 |
265 | int v;
266 | contour = NULL;
267 |
268 | //mencari contour dari kulit
269 | v = cvFindContours(skin, gStorage, &contour, sizeof(CvContour),
270 | CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
271 |
272 | //variabel penyimpan kontur terbesar
273 | biggestContour = NULL;
274 |
275 | double result1 = 0;
276 | double result2 = 0;
277 | //mencari kontur terbesar
278 | while (contour != NULL) {
279 |
280 | result1 = contour->total;
281 |
282 | if (result1 > result2) {
283 | result2 = result1;
284 | biggestContour = contour;
285 |
286 | }
287 | contour = contour->h_next;
288 |
289 | }
290 |
291 | //menggambar kontur dengan melakukan approxypoly untuk mengambil gambar kontur yang didapat
292 | if (biggestContour != NULL) {
293 |
294 | //cvDrawContours(currentFrame, biggestContour, cvScalarAll(255),cvScalarAll(255), 100);
295 |
296 | currentContour = NULL;
297 | try {
298 | //checkGStorage(1);
299 | biggestContour = cvApproxPoly(biggestContour, sizeof(CvContour),
300 | gStorage, CV_POLY_APPROX_DP,
301 | biggestContour->total * 0.0025, 0);
302 |
303 | // cout << "past approxymaly\n";
304 |
305 |
306 | cvDrawContours(currentFrame, biggestContour, cvScalar(89, 123, 90),
307 | cvScalar(0, 0, 0), 0, 2, 8);
308 |
309 | //biggestContour = currentContour;
310 |
311 | //cvConvexHull()
312 | hull = cvConvexHull2(biggestContour, gStorage, CV_CLOCKWISE, 0);
313 | } catch (Exception e) {
314 | cout << e.msg << endl;
315 | }
316 |
317 | box = cvMinAreaRect2(biggestContour, gStorage);
318 |
319 | //cout << "get the box from the contour pasted.. \n";
320 |
321 | //box = &tempBox;
322 | //box = tempBox;
323 |
324 | int startX = box.center.x - (box.size.width / 2);
325 | int startY = box.center.y - (box.size.height / 2);
326 |
327 | int row = startY + box.size.height;
328 | int col = startX + box.size.width;
329 |
330 | CvPoint2D32f points[row * col];
331 | int ret = 0;
332 |
333 | for (int i = startY; i < row; i++) {
334 | for (int j = startX; j < col; j++) {
335 |
336 | points[ret].x = i;
337 | points[ret].y = j;
338 | ret++;
339 | }
340 | }
341 |
342 | //points= box;5
343 |
344 | //handRect = cvMinAreaRect2();
345 |
346 | //cvDraw(currentFrame);
347 | /*
348 | for()
349 |
350 | CvPoint *ps[] = new CvPoint[ARRAY_LEN(point2)];
351 | for (int i = 0; i < ARRAY_LEN(point2); i++)
352 | ps[i] = cvPoint(points[i].x, points[i].y);
353 | */
354 | /*
355 | int countHull = hull->total;
356 | arrHull = (CvPoint*) malloc(sizeof(CvPoint) * countHull);
357 |
358 | //CvMat hMatrix = cvMat(1, countHull, CV_32SC2, arrHull);
359 |
360 | for (int i = 0; i < countHull; i++) {
361 | arrHull[i] = **CV_GET_SEQ_ELEM( CvPoint*, hull, i );
362 | }
363 | */
364 |
365 | /*
366 | int hullArea=0;
367 | for(int x=0;xwidth;x++){
368 | for(int y=0;yheight;y++){
369 | if(cvPointPolygonTest(&hMatrix, cvPoint2D32f(x, y), 0)>0){
370 | hullArea++;
371 | }
372 | }
373 | }
374 | */
375 |
376 | //cout << "set array from hull .. \n";
377 | /*
378 | try {
379 | cvCvtSeqToArray(hull, arrHull, CV_WHOLE_SEQ);
380 | cout << "past set array from hull .. \n";
381 | } catch (cv::Exception e) {
382 | cout << e.msg << "cvCvtSeqToArray(hull, arrHull, CV_WHOLE_SEQ);"
383 | << endl;
384 | }
385 | */
386 |
387 | int n = 1;
388 | //draw hull *belum berhasil :D
389 | /*
390 | try {
391 |
392 | for(int i = 0 ; itotal, true,"
402 | << endl;
403 | }
404 | */
405 | //menggambar titik tengah
406 |
407 |
408 | cvCircle(currentFrame, cvPoint(box.center.x, box.center.y), 15,
409 | CV_RGB(255, 0, 0), 5, 1, 0);
410 | // box.center.y+=100;
411 | cvCircle(img, cvPoint(box.center.x, box.center.y), 1,
412 | CV_RGB(255, 0, 0), 2, 1, 0);
413 |
414 | //float radius;
415 | /*
416 | try {
417 | filtereHull = cvCreateSeq(CV_SEQ_FLAG_CLOSED, sizeof(filtereHull),
418 | sizeof(CvPoint), gStorageHull);
419 | } catch (cv::Exception e) {
420 | cout << e.msg
421 | << "filtereHull = cvCreateSeq(CV_SEQ_FLAG_CLOSED, sizeof(filtereHull),"
422 | << endl;
423 | }
424 | */
425 |
426 | // setPoint = (CvPoint*) cvGetSeqElem(hull,0);
427 |
428 | //cout<x<<" & "<y<total; i++) {
431 |
432 | if (sqrt(
433 | pow(arrHull[i].x - arrHull[i + 1].x, 2) + pow(
434 | arrHull[i].y - arrHull[i + 1].y, 2))
435 | > (box.size.width / 10)) {
436 |
437 | CvPoint setPoint;
438 |
439 | try {
440 | setPoint = cvPoint(arrHull[i].x, arrHull[i].y);
441 | } catch (cv::Exception e) {
442 | cout << e.msg
443 | << "setPoint in for loop contour, to get arrhull"
444 | << endl;
445 | }
446 |
447 | try {
448 | cvSeqPush(filtereHull, &setPoint);
449 | } catch (cv::Exception e) {
450 | cout << e.msg << " cvseqpush in contour... " << endl;
451 | }
452 |
453 | }
454 | }
455 | */
456 |
457 | try {
458 |
459 | defect = cvConvexityDefects(biggestContour, hull, gStorage);
460 |
461 | int defnum = defect->total;
462 |
463 | defectArray = (CvConvexityDefect*) malloc(
464 | sizeof(CvConvexityDefect) * defnum);
465 |
466 | cvCvtSeqToArray(defect, defectArray, CV_WHOLE_SEQ);
467 | } catch (cv::Exception e) {
468 | cout << e.msg << endl;
469 | }
470 |
471 | }
472 | //free(&points[]);
473 | //free(arrHull);
474 | //free(arrHull);
475 |
476 |
477 | }
478 |
479 | void ConContour::drawAndComputeFingerNum() {
480 | fingerNum = 0;
481 | //cout << "getin to draw and compute finger...\n";
482 |
483 | //menggambar daerah hull
484 | /*
485 | for (int i = 0; i < filtereHull->total; i++) {
486 | arrHull[i] = cvPoint(arrHull[i].x, arrHull[i].y);
487 | //circleFrame.Draw(hullCircle, new Bgr(Color.Aquamarine),2);
488 | // cvCircle(currentFrame, hullPoint, 5, cvScalar(0, 220, 180), 1);
489 |
490 | }
491 |
492 | int n = 1;
493 | cvPolyLine(currentFrame, &arrHull, &n, filtereHull->total, 1,
494 | CV_RGB(0, 255, 0), 1, 1, 0);
495 | */
496 | //cout << sizeof(defectArray) << " " << sizeof(CvConvexityDefect) << endl;
497 | //if (defect->total > 0) {
498 |
499 | //gambar convexityDefects :D/
500 |
501 | for (int i = 0; i < defect->total; i++) {
502 |
503 | try {
504 | startPoint = cvPoint(defectArray[i].start->x,
505 | defectArray[i].start->y);
506 | //cout << "get point\n";
507 |
508 | //cout << "try get depth point \n";
509 |
510 |
511 | depthPoint = cvPoint(defectArray[i].depth_point->x,
512 | defectArray[i].depth_point->y);
513 |
514 | //cout << "get depth point \n";
515 |
516 |
517 | endPoint = cvPoint(defectArray[i].end->x, defectArray[i].end->y);
518 | //cout << "get end point \n";
519 | } catch (cv::Exception e) {
520 | cout << e.msg << "endpoint from cvpoint contour" << endl;
521 | }
522 |
523 | if (((startPoint.y < box.center.y) || (depthPoint.y < box.center.y))
524 | && (startPoint.y < depthPoint.y) && (sqrt(
525 | pow(startPoint.x - depthPoint.x, 2) + pow(
526 | startPoint.y - depthPoint.y, 2)) > box.size.height
527 | / 6.0)) {
528 | fingerNum++;
529 | cvLine(currentFrame, startPoint, depthPoint, CV_RGB(200,10,0), 2);
530 | //cvLine(currentFrame, depthPoint, endPoint, CV_RGB(255,0,0), 5);
531 | // cout << "get line point \n";
532 | }
533 |
534 | cvCircle(currentFrame, startPoint, 2, CV_RGB(0,178,211), 5);
535 | //cout << "get circle point \n";
536 |
537 | cvCircle(currentFrame, depthPoint, 3, CV_RGB(0,255,0), 5);
538 | // cout << "get circle point \n";
539 |
540 |
541 | //cvCircle(currentFrame, endPoint, 3, CV_RGB(0,0,255), 5);
542 | // cout << "get circle point \n";
543 |
544 |
545 | }
546 |
547 | cout << "show number" << fingerNum << endl;
548 |
549 | sprintf(&number, "%i", fingerNum);
550 |
551 | //number = "hello";
552 | cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 5.0, 5.0, 0, 5.0, 4);
553 | cvPutText(currentFrame, &number, cvPoint(50, 150), &font,
554 | cvScalar(255, 0, 0));
555 |
556 | }
557 |
558 | void ConContour::lukas_canade() {
559 | // Initialize, load two images from the file system, and
560 | // allocate the images and other structures we will need for
561 | // results.
562 | //
563 | // Initialize, load two images from the file system, and
564 | // allocate the images and other structures we will need for
565 | // results.
566 | //cvLoadImage("OpticalFlow0.jpg",CV_LOAD_IMAGE_GRAYSCALE)
567 | //cvLoadImage("OpticalFlow1.jpg",CV_LOAD_IMAGE_GRAYSCALE)
568 |
569 | // IplImage* imgA = imageA;
570 | //IplImage* imgB = imageB;
571 |
572 | //if (img_sz == NULL) {
573 |
574 | //}
575 |
576 | /*
577 | *
578 | * win_size = 10;
579 | */
580 |
581 | //IplImage* imgC = imageC;
582 |
583 | // The first thing we need to do is get the features
584 | // we want to track.
585 | if (eig_image == 0) {
586 | img_sz = cvGetSize(pyrdA);
587 | eig_image = cvCreateImage(img_sz, IPL_DEPTH_32F, 1);
588 | }
589 |
590 | if (tmp_image == 0) {
591 | tmp_image = cvCreateImage(img_sz, IPL_DEPTH_32F, 1);
592 | pyr_sz = cvSize(pyrdA->width + 8, pyrdB->height / 3);
593 | }
594 |
595 | int corner_count = MAX_CORNERS;
596 |
597 | cvGoodFeaturesToTrack(pyrdA, eig_image, tmp_image, cornersA, &corner_count,
598 | 0.01, 5.0, 0, 3, 0, 0.04);
599 | cvFindCornerSubPix(pyrdB, cornersA, corner_count,
600 | cvSize(win_size, win_size), cvSize(-1, -1),
601 | cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03));
602 | // Call the Lucas Kanade algorithm
603 | //
604 |
605 |
606 | if (tempPyrA == 0) {
607 | tempPyrA = cvCreateImage(pyr_sz, IPL_DEPTH_32F, 1);
608 | }
609 | if (tempPyrB == 0) {
610 | tempPyrB = cvCreateImage(pyr_sz, IPL_DEPTH_32F, 1);
611 | }
612 |
613 | cvCalcOpticalFlowPyrLK(pyrdA, pyrdB, tempPyrA, tempPyrB, cornersA,
614 | cornersB, corner_count, cvSize(win_size, win_size), 5,
615 | features_found, feature_errors,
616 | cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, .3), 0);
617 | // Now make some image of what we are looking at:
618 | //
619 | for (int i = 0; i < corner_count; i++) {
620 | if (features_found[i] == 0 || feature_errors[i] > 550) {
621 | // printf("Error is %f/n",feature_errors[i]);
622 | continue;
623 | }
624 | // printf("Got it/n");
625 | p0 = cvPoint(cvRound(cornersA[i].x), cvRound(cornersA[i].y));
626 | p1 = cvPoint(cvRound(cornersB[i].x), cvRound(cornersB[i].y));
627 | cvLine(currentFrame, p0, p1, CV_RGB(101,56,255), 3);
628 | }
629 |
630 | /*free(&img_sz);
631 | //free(&cornersA);
632 | //free(&cornersB);
633 | //free(&pyr_sz);
634 |
635 | free(&img_sz);
636 | free(&cornersA);
637 | free(&cornersB);
638 | free(&pyr_sz);
639 | // cvWaitKey(0);
640 | // return 0;
641 | * */
642 |
643 | }
644 |
--------------------------------------------------------------------------------