Sebelum adanya filter:
Setelah adanya filter:
Mulai ngerti kan maksudnya?? hehehe sebenernya ada banyak jenis filter, ada median blur, billateral filter, dan semacamnya. Itu terserah anda mau pakai yang mana (sesuai kebutuhan saja). Berikut codenya:
//BISMILLAH - Dzikri Purnama - Free to Copy&PasteLangsung compile dan execute saja. Btw, untuk filter lumayan mudah.
//Filter Gaussian blur
//#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
int h_min = 4, h_max = 78, s_min = 50, s_max = 255, v_min = 20, v_max = 255; //oranye
//int h_min = 95, h_max = 100, s_min = 130, s_max = 255, v_min = 150, v_max = 255; //biru
//int h_min = 4, h_max = 24, s_min = 38, s_max = 255, v_min = 150, v_max = 255; //kuning
VideoCapture cap(0);
if(!cap.isOpened())
return -1;
cap.set(CV_CAP_PROP_FRAME_WIDTH,320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,240);
Mat frame, hsv;
namedWindow("camera");
namedWindow("hsv");
while (true)
{
cap>>frame;
GaussianBlur(frame, frame, Size(11,11),2,2);
imshow("camera",frame);
cvtColor(frame,hsv,CV_BGR2HSV);
inRange(hsv,Scalar(h_min,s_min,v_min),Scalar(h_max,s_max,v_max),hsv);
createTrackbar("H_MIN: ","hsv",&h_min,255);
createTrackbar("H_MAX: ","hsv",&h_max,255);
createTrackbar("S_MIN: ","hsv",&s_min,255);
createTrackbar("S_MAX: ","hsv",&s_max,255);
createTrackbar("V_MIN: ","hsv",&v_min,255);
createTrackbar("V_MAX: ","hsv",&v_max,255);
imshow("hsv",hsv);
if(waitKey(20) != -1)
break;
}
return 0;
}