VLFeat + VS2013+opencv 配置

个可以和opencv配置一样,只需要配置一次,以后就再也不用配置了,一劳永逸~~~~

vlfeat图像库包含SIFT,MSER,KDtree,快速shift,K-means等各种图像处理中常用的算法。最近想看看里面的东西…….顺带把它配置起来……..

说明:

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\Tools—>D:\Software\Tools\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
#include    
#include  
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(i, j)[0];
            image[j + mat.cols*i + mat.cols*mat.rows * 1] = mat.at(i, j)[1];
            image[j + mat.cols*i + mat.cols*mat.rows * 2] = mat.at(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;
    float regularization = 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];
        }
    }

    int label = 0;
    int labelTop = -1;
    int labelBottom = -1;
    int labelLeft = -1;
    int labelRight = -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;
            if (j > 0) {
                labelLeft = labels[i][j - 1];
            }

            labelRight = label;
            if (j < mat.cols - 1) {
                labelRight = labels[i][j + 1];
            }

            if (label != labelTop || label != labelBottom || label != labelLeft || label != labelRight) {
                mat.at(i, j)[0] = 0;
                mat.at(i, j)[1] = 0;
                mat.at(i, j)[2] = 255;
            }
        }
    }

    cv::imwrite("1.png", mat);
    //waitKey(6000);
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

注意:如果提示缺少vl.dll 不能运行的话

将 D:\Software\Tools\vlfeat\bin\win32路径下的vl.dll拷贝到项目生成的debug文件夹再编译就OK了.

效果图

VLFeat + VS2013+opencv 配置_第1张图片 
VLFeat + VS2013+opencv 配置_第2张图片

你可能感兴趣的:(VLFeat + VS2013+opencv 配置)