Tuesday, 28 October 2014

konfigurasi opencv 2.4.9 pada visual studio 2012


1. Download VS 2012 (vc11)
2. Download Opencv (2.4.9)
3. Extract Opencv
4. (visual Studio) Buat Win32(C++) Console Application
5. (Opencv + Visual stuio)  Klik kanan menu project --> Propertis
6. (Opencv + Visual stuio)  Pilih Configuration Manager --> Tambahkan x64 jika 64bit, jika 32bit sdh secara default

Saturday, 25 October 2014

Smoothing image with Homogenus, Gausian, Median, Bilateral filter opencv

kali ini mencoba filter dengan Homogenus, Gausian, Median, Bilateral filter opencv...selamat mencoba
----------------------------------------------------------------------------------------------------hasilnya



----------------------------------------------------------------------------------------------------
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;

/// Global Variables
int DELAY_CAPTION = 1500;
int DELAY_BLUR = 100;
int MAX_KERNEL_LENGTH = 31;

Mat src; Mat dst;
char window_name[] = "Filter Demo 1";


/// Function headers
int display_caption( char* caption );
int display_dst( int delay );

/**
 * function main
 */
 int main( int argc, char** argv )
 {
   namedWindow( window_name, CV_WINDOW_AUTOSIZE );


Discrete Fourier Transform DFT image opencv (spectrum magnitude)

kali ini mencoba Discrete Fourier Transform DFT opencv (spectrum magnitude)....selamat mencoba....dan berikut ini sourcecodenya
-------------------------------------------------------------------------------------------------------------
hasilnya


-------------------------------------------------------------------------------------------------------------
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char ** argv)
{
    const char* filename = argc >=2 ? argv[1] : "foto.jpg";
IplImage *img = cvLoadImage("foto.jpg");
    cvNamedWindow("Image asli", CV_WINDOW_AUTOSIZE);
cvShowImage("Image asli",img);
    Mat I = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);

    if( I.empty())
        return -1;

    Mat padded;                            //expand input image to optimal size
    int m = getOptimalDFTSize( I.rows );
    int n = getOptimalDFTSize( I.cols ); // on the border add zero values
    copyMakeBorder(I, padded, 0, m - I.rows, 0, n - I.cols, BORDER_CONSTANT, Scalar::all(0));
 

Menggambar dengan OpenCV

berikut ini ada sourcecode untuk menggambar dengan library open cv......selamat mencoba
-------------------------------------------------------------------------------------------------------------
hasilnya
-------------------------------------------------------------------------------------------------------------
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#define w 400

using namespace cv;

/// Function headers
void MyEllipse( Mat img, double angle );
void MyFilledCircle( Mat img, Point center );
void MyPolygon( Mat img );
void MyLine( Mat img, Point start, Point end );

int main( void ){
  /// Windows names
  char atom_window[] = "Drawing 1: Atom";
  char rook_window[] = "Drawing 2: Rook";
 

Image blending opencv

kali ini mencoba image blending dengan opencv seperti berikut (syarat ukuran image1 dan image2 sama)
-----------------------------------------------------------------------------------------------------
hasilnya
------------------------------------------------------------------------------------------------------
#include <cv.h>
#include <highgui.h>
#include <iostream>

using namespace cv;

int main( int argc, char** argv )
{
 double alpha = 0.5; double beta; double input;

 Mat src1, src2, dst;

 /// Ask the user enter alpha
 std::cout<<" Simple Linear Blender "<<std::endl;
 std::cout<<"-----------------------"<<std::endl;
 std::cout<<"* Enter alpha [0-1]: ";
 std::cin>>input;

 /// We use the alpha provided by the user if it is between 0 and 1
 if( input >= 0.0 && input <= 1.0 )
   { alpha = input; }

 /// Read image ( same size, same type )
 src1 = imread("foto.jpg");