这个可以和OpenCV的配置一样,只需要配置一次,以后就再也不用配置了,一劳永逸~~~~
vlfeat图像库包含SIFT,MSER,KDtree,快速换档,K-装置等各种图像处理中常用的算法。最近想看看里面的东西......。顺带把它配置起来...... ..
说明:
1.系统环境:win 7 64位专业版,VS2013旗舰版2.4.9
2.opencv配置很简单,随便参考一篇博文就行了,这里就不叙述了......
1.下载vlfeat
项目主页是:http ://www.vlfeat.org/
可以也。我下载上传的http://download.csdn.net/detail/lilai619/9114675
2.安装
只需要解压,改名为vlfeat,放到自己指定的目录就行了。
以我的为例子:d:\ SOFTWARE \工具 - > d:\ SOFTWARE \工具\ vlfeat
3.配置
1.添加系统环境变量:
右击我的电脑 - 属性 - 高级系统设置 - 环境变量 - 系统环境变量--path
2.在VS2013中新建一个CPP:
右击源文件 - 添加CPP
3.视图 - 属性管理器 - 右击Microsoft.cpp.win32.user
4.在VC ++目录 - 包含目录
添加D:\ Software \ Tools \ vlfeat
5.在链接器 - 常规 - 附加库目录
添加D:\ Software \ Tools \ vlfeat \ bin \ win32
6.在链接器 - 输入 - 附加依赖库
添加vl.lib
4.测试
我的opencv2.4.9已经配置好的。
这上面新建的cpp中粘贴如下代码(图像读写+ vlfeat中的超像素分割),可以测试你之前安装的的opencv和刚才安装的vlfeat有没有正确配置。
(记得在cpp所在路径下放置1.jpg和1.png两张图片)。
#include<iostream>
#include <opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
extern "C" {
#include "vl/generic.h"
#include "vl/slic.h"
}
using namespace cv;
int main(int argc, const char * argv[]) {
insert code here...
std::cout<< "Hello, World!\n";
VL_PRINT("hello, VLFeat!\n");
//读入一张图片(游戏原画)
Mat img = imread("1.jpg");
//创建一个名为 "游戏原画"窗口
//下面3句用于测试opencv
namedWindow("游戏原画");
imshow("游戏原画", img);
waitKey(3000);
//下面用于测试vlfeat
cv::Mat mat = cv::imread("1.png", CV_LOAD_IMAGE_COLOR);
//Convert image to one-dimensional array.
float*image = new float[mat.rows*mat.cols*mat.channels()];
for(int i = 0; i < mat.rows; ++i) {
for (int j = 0; j < mat.cols;++j) {
// Assuming three channels ...
image[j + mat.cols*i + mat.cols*mat.rows * 0] =mat.at<cv::Vec3b>(i, j)[0];
image[j + mat.cols*i + mat.cols*mat.rows * 1] =mat.at<cv::Vec3b>(i, j)[1];
image[j + mat.cols*i + mat.cols*mat.rows * 2] =mat.at<cv::Vec3b>(i, j)[2];
}
}
//The algorithm will store the final segmentation in a one-dimensional array.
vl_uint32* segmentation = new vl_uint32[mat.rows*mat.cols];
vl_size height = mat.rows;
vl_size width = mat.cols;
vl_size channels = mat.channels();
//The region size defines the number of superpixels obtained.
//Regularization describes a trade-off between the color term and the
//spatial term.
vl_size region = 30;
floatregularization = 1000.;
vl_size minRegion = 10;
vl_slic_segment(segmentation, image, width, height, channels, region,regularization, minRegion);
//Convert segmentation.
int**labels = new int*[mat.rows];
for(int i = 0; i < mat.rows; ++i) {
labels[i] = new int[mat.cols];
for (int j = 0; j < mat.cols; ++j) {
labels[i][j] = (int)segmentation[j + mat.cols*i];
}
}
intlabel = 0;
intlabelTop = -1;
intlabelBottom = -1;
intlabelLeft = -1;
intlabelRight = -1;
for(int i = 0; i < mat.rows; i++) {
for (int j = 0; j < mat.cols; j++) {
label = labels[i][j];
labelTop = label;
if (i > 0) {
labelTop = labels[i - 1][j];
}
labelBottom = label;
if (i < mat.rows - 1) {
labelBottom = labels[i + 1][j];
}
labelLeft = label;
如果(j> 0){
labelLeft = labels [i] [j - 1];
}
labelRight = label;
如果(j <mat.cols-1){
labelRight = labels [i] [j + 1];
}
如果(label!= labelTop || label!= labelBottom || label!= labelLeft || label!= labelRight){
mat.at <cv :: Vec3b>(i,j)[0] = 0;
mat.at <cv :: Vec3b>(i,j)[1] = 0;
mat.at <cv :: Vec3b>(i,j)[2] = 255;
}
}
}
cv :: imwrite(“1.png”,mat);
// waitKey(6000);
return0;
}