Vous êtes sur la page 1sur 3

DEPARTAMENTO DE ENERGÍA Y MECÁNICA

CARRERA DE INGENIERÍA MECATRÓNICA

TAREA N°2 – OPTATIVA DE PROFESIONALIZACIÓN– NRC: 2507

TEMA:
FILTROS INDIVIDUALES POR COMPONENTE (RGB) Y EN COLOR

AUTOR:
FERNANDO RECALDE

NIVEL: 9° MECATRÓNICA

DOCENTE: ING. DARIO JOSE MENDOZA CHIPANTASI

LATACUNGA

2019
CÓDIGO
#include <iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>

using namespace std;


using namespace cv;

int main()
{
VideoCapture cap(0);
Mat img, filtrorojo;
vector<Mat> RGBChannels(3);
Mat rgb_union[3];
Mat filtro_final;
while (true) {
cap >> img;
// img=imread("D:\\ARCHIVOS\\rgb.jpg");
split(img, RGBChannels);
//filtro rojo
filtrorojo = RGBChannels[2] - RGBChannels[1]- RGBChannels[0];

for (int r = 0; r < filtrorojo.rows; r++)


{
for (int c = 0; c < filtrorojo.cols; c++)
{
if (filtrorojo.at<uint8_t>(r, c) > 40)
{
filtrorojo.at<uint8_t>(r, c) = 0;
RGBChannels[1].at<uint8_t>(r, c) = 0;
RGBChannels[0].at<uint8_t>(r, c) = 0;
img.at<Vec3b>(r, c)[1] = 0;
img.at<Vec3b>(r, c)[0] = 0;

}
else
{
filtrorojo.at<uint8_t>(r, c) =
RGBChannels[2].at<uint8_t>(r, c);
filtrorojo.at<uint8_t>(r, c) = img.at<Vec3b>(r,
c)[2];
}

}
}
rgb_union[2] = filtrorojo;
rgb_union[1] = RGBChannels[1];
rgb_union[0] = RGBChannels[0];

merge(rgb_union, 3, filtro_final);
imshow("Filtro final", filtro_final);
imshow("canal rojo", rgb_union[2]);
imshow("canal verde", rgb_union[1]);
imshow("canal azul", rgb_union[0]);
if (waitKey(1) == 27)
break;
}

return 0;
}

FUNCIONAMIENTO

El algoritmo filtra el color rojo solo del mouse, se puede mejorar el algoritmo
seleccionando el pixel que se desea filtran usando el click del mouse.

Vous aimerez peut-être aussi