Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / BilatTools_OpenCV / src / core / tuto / tuto.cpp
1 #include <iostream>
2
3 #include <opencv.hpp>
4 #include <highgui.hpp>
5
6 using std::cout;
7 using std::cerr;
8 using std::endl;
9 using std::string;
10
11 using namespace cv;
12
13 /*----------------------------------------------------------------------*\
14 |* Declaration *|
15 \*---------------------------------------------------------------------*/
16
17 /*--------------------------------------*\
18 |* Public *|
19 \*-------------------------------------*/
20
21 int tuto(string nameVideo);
22
23 /*--------------------------------------*\
24 |* Private *|
25 \*-------------------------------------*/
26
27 static int work(VideoCapture* ptrVideoCapture);
28
29 /*----------------------------------------------------------------------*\
30 |* Implementation *|
31 \*---------------------------------------------------------------------*/
32
33 /*--------------------------------------*\
34 |* Public *|
35 \*-------------------------------------*/
36
37 /**
38 * http://docs.opencv.org/doc/tutorials/highgui/video-input-psnr-ssim/video-input-psnr-ssim.html
39 */
40 int tuto(string nameVideo)
41 {
42
43 try
44 {
45 //v1
46 // VideoCapture cap(nameVideo);
47
48 //v2
49 VideoCapture cap;
50 cap.open(nameVideo);
51
52 if (!cap.isOpened())
53 {
54 return EXIT_FAILURE;
55 }
56
57 else
58 {
59 return work(&cap);
60 }
61
62 }
63 catch (cv::Exception& e)
64 {
65 const char* err_msg = e.what();
66
67 cerr << "Tuto failed" << endl;
68 cerr << err_msg << endl;
69
70 return EXIT_FAILURE;
71 }
72
73 }
74
75 /*--------------------------------------*\
76 |* Private *|
77 \*-------------------------------------*/
78
79 int work(VideoCapture* ptrVideoCapture)
80 {
81 cout<<"[Tuto] : work"<<endl;
82
83 VideoCapture cap = *ptrVideoCapture;
84
85 double rate = cap.get(CV_CAP_PROP_FPS);
86 int delay = 1000/rate;
87
88 namedWindow("edges", 1);
89
90 Mat edges;
91 while (true)
92 {
93 Mat frame;
94 //cout << "[Tuto] cap >> frame : try" << endl; // debug
95 cap >> frame; // get a new frame from camera
96
97 if (frame.empty())
98 {
99 return EXIT_SUCCESS;
100 }
101 else
102 {
103 // ColorConversion
104 {
105 // http://siggiorn.com/wp-content/uploads/libraries/opencv-java/docs/sj/opencv/Constants.ColorConversion.html
106 //int colorConversion=CV_BGR2GRAY; // ok
107 //int colorConversion=CV_BGR2RGBA ; // ko
108 int colorConversion = CV_BGR2BGRA; // ok
109 cvtColor(frame, edges, colorConversion);
110 }
111
112 // Effet
113 {
114 //GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
115 //Canny(edges, edges, 0, 30, 3);
116 }
117
118 imshow("edges", edges);
119
120 if (waitKey(delay) >= 0)
121 {
122 return EXIT_SUCCESS;
123 }
124 }
125 }
126 }
127
128 /*----------------------------------------------------------------------*\
129 |* End *|
130 \*---------------------------------------------------------------------*/
131