File tree 3 files changed +51
-0
lines changed
3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.0)
2
+
3
+ project ( Tutorial_OpenCV )
4
+
5
+ find_package ( OpenCV 3.0.0 REQUIRED )
6
+
7
+ file (COPY rgb.png DESTINATION image)
8
+
9
+ add_executable ( ${PROJECT_NAME} source .cpp )
10
+ target_link_libraries ( ${PROJECT_NAME} ${OpenCV_LIBS} )
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < opencv2/opencv.hpp>
3
+
4
+ using namespace cv ;
5
+ using namespace std ;
6
+
7
+ int main (int argc, char ** argv )
8
+ {
9
+ Mat image = imread (" image/rgb.png" , CV_LOAD_IMAGE_COLOR);
10
+
11
+ if (image.empty ())
12
+ {
13
+ printf (" No se ha podido leer la imagen.\n " );
14
+ getchar ();
15
+ return -1 ;
16
+ }
17
+
18
+ imshow (" Imagen Original" , image);
19
+
20
+ std::vector<Mat> channels;
21
+ split (image, channels);
22
+
23
+ Mat zero = Mat::zeros (image.size (), CV_8UC1);
24
+
25
+ std::vector<Mat> B = { channels[0 ], zero, zero };
26
+ std::vector<Mat> G = { zero, channels[1 ], zero };
27
+ std::vector<Mat> R = { zero, zero, channels[2 ] };
28
+
29
+ Mat rdst, gdst, bdst;
30
+
31
+ merge (R, rdst);
32
+ merge (G, gdst);
33
+ merge (B, bdst);
34
+
35
+ imshow (" R Channel" , rdst);
36
+ imshow (" G Channel" , gdst);
37
+ imshow (" B Channel" , bdst);
38
+
39
+ waitKey (0 );
40
+ return 0 ;
41
+ }
You can’t perform that action at this time.
0 commit comments