Ini code nya:
//BISMILLAH - Dzikri Purnama - Free to Copy&Paste
//BGR to GREY
//#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()
{
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, grey;
namedWindow("camera");
namedWindow("grey");
while (true)
{
cap>>frame;
cvtColor(frame,grey,CV_BGR2GRAY);
imshow("camera",frame);
imshow("grey",grey);
if(waitKey(20) != -1)
break;
}
return 0;
}
Codenya lumayan gampang kan? Mari kita bahas isi kodenya: