千日草 2019-06-26 10:53 采纳率: 0%
浏览 1059

opencv3.0.0出现无法解析的外部命令

opencv3.0.0出现无法解析的外部命令
头文件代码:
#if !defined COLORDETECT
#define COLORDETECT

#include
#include

class ColorDetector {

private:

// minimum acceptable distance
int maxDist;

// target color
cv::Vec3b target;

// image containing color converted image
cv::Mat converted;
bool useLab;

// image containing resulting binary map
cv::Mat result;

public:

// empty constructor
// default parameter initialization here
ColorDetector() : maxDist(100), target(0, 0, 0), useLab(false) {}

// extra constructor for Lab color space example
ColorDetector(bool useLab) : maxDist(100), target(0, 0, 0), useLab(useLab) {}

// full constructor
ColorDetector(uchar blue, uchar green, uchar red, int mxDist = 100, bool useLab = false) : maxDist(mxDist), useLab(useLab) {

    // target color
    setTargetColor(blue, green, red);
}

// Computes the distance from target color.
int getDistanceToTargetColor(const cv::Vec3b& color) const {
    return getColorDistance(color, target);
}

// Computes the city-block distance between two colors.
int getColorDistance(const cv::Vec3b& color1, const cv::Vec3b& color2) const {

    return abs(color1[0] - color2[0]) +
        abs(color1[1] - color2[1]) +
        abs(color1[2] - color2[2]);

    // Or:
    // return static_cast<int>(cv::norm<int,3>(cv::Vec3i(color[0]-color2[0],color[1]-color2[1],color[2]-color2[2])));

    // Or:
    // cv::Vec3b dist;
    // cv::absdiff(color,color2,dist);
    // return cv::sum(dist)[0];
}

// Processes the image. Returns a 1-channel binary image.
cv::Mat process(const cv::Mat &image);

cv::Mat operator()(const cv::Mat &image) {

    cv::Mat input;
    input = image;
    if (useLab) { // Lab conversion
        cv::cvtColor(image, input, CV_BGR2Lab);
    }

    cv::Mat output;
    // compute absolute difference with target color
    cv::absdiff(input, cv::Scalar(target), output);
    // split the channels into 3 images
    std::vector<cv::Mat> images;
    cv::split(output, images);
    // add the 3 channels (saturation might occurs here)
    output = images[0] + images[1] + images[2];
    // apply threshold
    cv::threshold(output,  // input image
        output,  // output image
        maxDist, // threshold (must be < 256)
        255,     // max value
        cv::THRESH_BINARY_INV); // thresholding type

    return output;
}

// Getters and setters

// Sets the color distance threshold.
// Threshold must be positive, otherwise distance threshold
// is set to 0.
void setColorDistanceThreshold(int distance) {

    if (distance < 0)
        distance = 0;
    maxDist = distance;
}

// Gets the color distance threshold
int getColorDistanceThreshold() const {

    return maxDist;
}

// Sets the color to be detected
void setTargetColor(uchar blue, uchar green, uchar red) {

    // BGR order
    target = cv::Vec3b(blue, green, red);

    if (useLab) {
        // Temporary 1-pixel image
        cv::Mat tmp(1, 1, CV_8UC3);
        tmp.at<cv::Vec3b>(0, 0) = cv::Vec3b(blue, green, red);

        // Converting the target to Lab color space 
        cv::cvtColor(tmp, tmp, CV_BGR2Lab);

        target = tmp.at<cv::Vec3b>(0, 0);
    }
}

// Sets the color to be detected
void setTargetColor(cv::Vec3b color) {

    target = color;
}

// Gets the color to be detected
cv::Vec3b getTargetColor() const {

    return target;
}

};

#endif

主函数代码:
#include
#include
#include
#include
#include"colordetector.h"

int main()
{
// 1. Create image processor object
ColorDetector cdetect;

// 2. Read input image
cv::Mat image = cv::imread("Schluss.jpg");
if (image.empty())
    return 0;

// 3. Set input parameters
cdetect.setTargetColor(250, 219, 133); // here blue sky

// 4. Process the image and display the result
cv::namedWindow("result");
cv::imshow("result", cdetect.process(image));

// or using functor
ColorDetector colordetector(250, 219, 133,  // color
    45, true); // Lab threshold
cv::namedWindow("result (functor)");
cv::imshow("result (functor)", colordetector(image));

cv::waitKey();

return 0;

}

依赖的库添加了:
D:\opencv\build\x64\vc12\lib\opencv_ts300.lib
D:\opencv\build\x64\vc12\lib\opencv_world300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_imgproc300.lib
D:\opencv\build\x64\vc12\staticlib\IlmImf.lib
D:\opencv\build\x64\vc12\staticlib\ippicvmt.lib
D:\opencv\build\x64\vc12\staticlib\libjpeg.lib
D:\opencv\build\x64\vc12\staticlib\libpng.lib
D:\opencv\build\x64\vc12\staticlib\libtiff.lib
D:\opencv\build\x64\vc12\staticlib\libwebp.lib
D:\opencv\build\x64\vc12\staticlib\opencv_calib3d300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_core300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_features2d300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_flann300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_hal300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_highgui300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_imgcodecs300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_imgproc300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_ml300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_objdetect300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_photo300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_shape300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_stitching300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_superres300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_video300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_videoio300.lib
D:\opencv\build\x64\vc12\staticlib\opencv_videostab300.lib
D:\opencv\build\x64\vc12\staticlib\zlib.lib

解决方案配置是Release x64

刚开始学OpenCV,请各位大佬帮帮我

  • 写回答

1条回答 默认 最新

  • 白色一大坨 2019-06-26 14:04
    关注

    3.0版本哪儿用加那么多lib,明明一个opencv_world300.lib就可以了

    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64