Skip to content

Commit 615b918

Browse files
committed
Funciones split y merge
Son usadas para dividir y unir los canales de una imagen.
1 parent 85d6b64 commit 615b918

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

opencv-split_merge/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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} )

opencv-split_merge/rgb.png

11.8 KB
Loading

opencv-split_merge/source.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)