opencv440+contirb+build_opencv_world报错解决

问题:cmake中,勾选build_opencv_world则会在vs编译中发生以下错误:This file was generated by a older version of protoc which is incompatible with your Protocol Buffer headers.

cannot open input file '..\..\lib\Release\opencv_world440.lib'。

cmake不勾选build_opencv_world则可以在vs里编译成功。

 

解决

应该与protoc.exe版本无关了,从2.4,2.5.0,2.6.0, 2.6.1, 3.6.0都不行,说明不是这个问题,最后看到别人说卸载anaconda,也感觉cmake里把anaconda里很多的文件包含进来,造成冲突,因此卸载Anaconda,再重新cmake,勾选build_opencv_world一步步走,即可编译成功。

opencv440+contirb+build_opencv_world报错解决_第1张图片

若不想重新编译,可下载已编译库(vs2015),

链接:https://pan.baidu.com/s/1Ju6qBO5i8zQwsPE77v8Mug 
提取码:v64q

另附编译后使用selectivesearch运行的程序:

#include "opencv2/ximgproc/segmentation.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include 
#include 

using namespace cv;
using namespace cv::ximgproc::segmentation;

static void help() {
    std::cout << std::endl <<
    "Usage:" << std::endl <<
    "./ssearch input_image (f|q)" << std::endl <<
    "f=fast, q=quality" << std::endl <<
    "Use l to display less rects, m to display more rects, q to quit" << std::endl;
}


int main(int argc, char** argv) {
    // If image path and f/q is not passed as command
    // line arguments, quit and display help message
    if (argc < 3) {
        help();
        return -1;
    }

    // speed-up using multithreads
    setUseOptimized(true);
    setNumThreads(4);

    // read image
    Mat im = imread(argv[1]);
    // resize image
    int newHeight = 200;
    int newWidth = im.cols*newHeight/im.rows;
    resize(im, im, Size(newWidth, newHeight));

    // create Selective Search Segmentation Object using default parameters
    Ptr ss = createSelectiveSearchSegmentation();
    // set input image on which we will run segmentation
    ss->setBaseImage(im);

    // Switch to fast but low recall Selective Search method
    if (argv[2][0] == 'f') {
        ss->switchToSelectiveSearchFast();
    }
    // Switch to high recall but slow Selective Search method
    else if (argv[2][0] == 'q') {
        ss->switchToSelectiveSearchQuality();
    } 
    // if argument is neither f nor q print help message
    else {
        help();
        return -2;
    }

    // run selective search segmentation on input image
    std::vector rects;
    ss->process(rects);
    std::cout << "Total Number of Region Proposals: " << rects.size() << std::endl;

    // number of region proposals to show
    int numShowRects = 100;
    // increment to increase/decrease total number
    // of reason proposals to be shown
    int increment = 50;

    while(1) {
        // create a copy of original image
        Mat imOut = im.clone();

        // itereate over all the region proposals
        for(int i = 0; i < rects.size(); i++) {
            if (i < numShowRects) {
                rectangle(imOut, rects[i], Scalar(0, 255, 0));
            }
            else {
                break;
            }
        }

        // show output
        imshow("Output", imOut);

        // record key press
        int k = waitKey();

        // m is pressed
        if (k == 109) {
            // increase total number of rectangles to show by increment
            numShowRects += increment;
        }
        // l is pressed
        else if (k == 108 && numShowRects > increment) {
            // decrease total number of rectangles to show by increment
            numShowRects -= increment;
        }
        // q is pressed
        else if (k == 113) {
            break;
        }
    }
    return 0;
}

实验图:

opencv440+contirb+build_opencv_world报错解决_第2张图片

你可能感兴趣的:(程序,算法,笔记)