Ubuntu を使うとして手順を説明する.
Ubuntu で OS のシステム更新を行うときは, 端末で,次のコマンドを実行.
sudo apt update sudo apt -yV upgrade sudo /sbin/shutdown -r now
sudo apt install libx11-dev
画像ファイル fruits.jpg, home.jpg のダウンロード手順は,別ページで説明している.
https://github.com/opencv/opencv/tree/master/samples/data で公開されている fruits.jpg, home.jpg を使用する(謝辞:画像の作者に感謝します)
dlib C++ Library を用いて, Sobel エッジを得る. エッジを濃淡画像で表示.
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/image_transforms.h>
#include <fstream>
using namespace std;
using namespace dlib;
int main(int argc, char** argv)
{
array2d<rgb_pixel> img;
load_image(img, argv[1]);
array2d<unsigned char> blurred_img;
gaussian_blur(img, blurred_img);
// 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);
image_window my_window(edge_image, "Normal Edge Image");
my_window.wait_until_closed();
}
上のソースコードを,a.cのようなファイル名で保存し, 次の手順でビルドして実行
g++ -I/usr/local/include a.c -L/usr/local/lib -ldlib -lpthread -lX11
./a.out home.jpg
./a.out fruits.jpg
dlib C++ Library を用いて, Sobel エッジをヒートマップで表示.
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/image_transforms.h>
#include <fstream>
using namespace std;
using namespace dlib;
int main(int argc, char** argv)
{
array2d<rgb_pixel> img;
load_image(img, argv[1]);
array2d<unsigned char> blurred_img;
gaussian_blur(img, blurred_img);
// 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);
image_window my_window(heatmap(edge_image));
my_window.wait_until_closed();
}
上のソースコードを,a.cのようなファイル名で保存し, 次の手順でビルドして実行
g++ -I/usr/local/include a.c -L/usr/local/lib -ldlib -lpthread -lX11
./a.out home.jpg
./a.out fruits.jpg
dlib C++ Library を用いて, Sobel エッジをヒートマップで表示.
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/image_transforms.h>
#include <fstream>
using namespace std;
using namespace dlib;
int main(int argc, char** argv)
{
array2d<rgb_pixel> img;
load_image(img, argv[1]);
array2d<unsigned char> blurred_img;
gaussian_blur(img, blurred_img);
// 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);
image_window my_window(jet(edge_image));
my_window.wait_until_closed();
}
上のソースコードを,a.cのようなファイル名で保存し, 次の手順でビルドして実行
g++ -I/usr/local/include a.c -L/usr/local/lib -ldlib -lpthread -lX11
./a.out home.jpg
./a.out fruits.jpg
本サイトは金子邦彦研究室のWebページです.サイトマップは,サイトマップのページをご覧下さい. 本サイト内の検索は,サイト内検索のページをご利用下さい.
問い合わせ先: 金子邦彦(かねこ くにひこ)