본문 바로가기
과거자료/DLIB

DLib + Visual Studio 2010 연동

by Joo입니다 2016. 6. 13.

 

 

http://dlib.net/image_ex.cpp.html

 

위 예제를 이용해, Dlib + Visual Studio 2010 연동 방법을 정리해 놓을까 한다.

 

bmp 영상 불러와서 에지 검출하는 간단한 예제이다.

 

1. 먼저 Visual Studio를 열고, Win32 콘솔 응용 프로그램을 선택하고 새 프로젝트를 만들어 준다.

 

2. 프로젝트 → 속성 → VC++ 디렉터리 → 라이브러리 디렉터리

   위 경로에 "C:\dlib-18.18\build\dlib_build\Release" 추가.

   이 폴더에는 앞서 Dlib를 컴파일 하면서 생성된 dlib.lib 파일이 있는 경로이다.

 

 

3.

프로젝트 → 속성 → 링커 → 입력 → 추가 종속성

여기에 dlib.lib를 입력해준다.

그리고 확인버튼!

 

 

 

4. 예제소스를 입력해보자.

 


#include <\dlib-18.18\dlib\gui_widgets.h>
#include <\dlib-18.18\dlib\image_io.h>
#include <\dlib-18.18\dlib\image_transforms.h>
#include <fstream>

using namespace std;
using namespace dlib;


int _tmain(int argc, _TCHAR* argv[])
{
 
 // make sure the user entered an argument to this program

 // Here we declare an image object that can store rgb_pixels.  Note that in
 // dlib there is no explicit image object, just a 2D array and
 // various pixel types. 


 array2d<rgb_pixel> img;

 

 // Now load the image file into our image.  If something is wrong then
 // load_image() will throw an exception.  Also, if you linked with libpng
 // and libjpeg then load_image() can load PNG and JPEG files in addition
 // to BMP files.


 load_image(img, "test.bmp");


 // Now let's use some image functions.  First let's blur the image a little.


 array2d<unsigned char> blurred_img;
 gaussian_blur(img, blurred_img);

 

 // Now find the horizontal and vertical gradient images.


 array2d<short> horz_gradient, vert_gradient;
 array2d<unsigned char> edge_image;
 sobel_edge_detector(blurred_img, horz_gradient, vert_gradient);

 

 // now we do the non-maximum edge suppression step so that our edges are nice and thin


 suppress_non_maximum_edges(horz_gradient, vert_gradient, edge_image);

 

 // Now we would like to see what our images look like.  So let's use a
 // window to display them on the screen.  (Note that you can zoom into
 // the window by holding CTRL and scrolling the mouse wheel)


 image_window my_window(edge_image, "Normal Edge Image");

 

 // We can also easily display the edge_image as a heatmap or using the jet color
 // scheme like so.


 image_window win_hot(heatmap(edge_image));
 image_window win_jet(jet(edge_image));

 

 // also make a window to display the original image


 image_window my_window2(img, "Original Image");

 

 // Sometimes you want to get input from the user about which pixels are important
 // for some task.  You can do this easily by trapping user clicks as shown below.
 // This loop executes every time the user double clicks on some image pixel and it
 // will terminate once the user closes the window.


 point p;
 while (my_window.get_next_double_click(p))
 {
  cout << "User double clicked on pixel:         " << p << endl;
  cout << "edge pixel value at this location is: " << (int)edge_image[p.y()][p.x()] << endl;
 }

 

 // wait until the user closes the windows before we let the program
 // terminate.


 win_hot.wait_until_closed();
 my_window2.wait_until_closed();


 // Finally, note that you can access the elements of an image using the normal [row][column]
 // operator like so:


 cout << horz_gradient[0][3] << endl;
 cout << "number of rows in image:    " << horz_gradient.nr() << endl;
 cout << "number of columns in image: " << horz_gradient.nc() << endl;

 return 0;
}

 

 

5. 결과 영상

 

 

 

'과거자료 > DLIB' 카테고리의 다른 글

DLIB C++ Library, CMake를 이용한 Dlib 컴파일  (4) 2016.06.09