Visual Studio 中的 OpenCV 构建错误
OpenCV build error in visual studio
>我试图显示图像的直方图
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/**
* @function main
*/
int main( int argc, char** argv )
{
Mat src, dst;
/// Load image
src = imread("img.jpg", 1 );
if( !src.data )
{ return -1; }
// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split( src, bgr_planes );
/// Establish the number of bins
int histSize = 256;
/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist( &bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound( (double) hist_w/histSize );
Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) );
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
/// Draw for each channel
for( int i = 1; i < histSize; i++ )
{
line( histImage, Point( bin_w*(i-1), hist_h - cvRound(b_hist.at<float>(i-1)) ) ,
Point( bin_w*(i), hist_h - cvRound(b_hist.at<float>(i)) ),
Scalar( 255, 0, 0), 2, 8, 0 );
line( histImage, Point( bin_w*(i-1), hist_h - cvRound(g_hist.at<float>(i-1)) ) ,
Point( bin_w*(i), hist_h - cvRound(g_hist.at<float>(i)) ),
Scalar( 0, 255, 0), 2, 8, 0 );
line( histImage, Point( bin_w*(i-1), hist_h - cvRound(r_hist.at<float>(i-1)) ) ,
Point( bin_w*(i), hist_h - cvRound(r_hist.at<float>(i)) ),
Scalar( 0, 0, 255), 2, 8, 0 );
}
/// Display
namedWindow("calcHist Demo", CV_WINDOW_AUTOSIZE );
imshow("calcHist Demo", histImage );
waitKey(0);
return 0;
}
但是当我尝试构建它时,我遇到了此错误,所以如果您能提供帮助,那将是很棒的;)
error LNK2001: symbole externe non résolu "void __cdecl cv::calcHist(class cv::Mat const *,int,int const *,class cv::Mat const &,class cv::Mat &,int,int const *,float const * *,bool,bool)" (?calcHist@cv@@YAXPBVMat@1@HPBHABV21@AAV21@H1PAPBM_N5@Z)
我已经测试了配置,我可以显示示例图像
要使其正常工作,您需要将以下库放入项目的属性中,即 Linker > Input > Additional Dependencies
:
opencv_imgproc.lib
opencv_highgui.lib
更清楚的是,如果您在调试模式下使用 OpenCV 2.4.8,则应放置以下两个库:
opencv_imgproc248d.lib
opencv_highgui248d.lib
相关文章:
- Agora.io 虚幻引擎插件构建错误
- 尝试将 boost::stacktrace 添加到 CMake 项目时出现构建错误
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- 组件上的虚幻引擎可蓝图UFUNCTION会导致构建错误
- 尝试构建 xerces c++ 解析器。Netbeans 和命令行构建错误未定义对"xercesc_3_2..."的引用
- pair的两个构造函数几乎相同,为什么不生成构建错误?
- 发生 Qt5.11 应用插件构建错误:信号和插槽参数不兼容
- Visual Studio 2017 中的 Tesseract 3.05 构建错误
- Eclipse 构建错误在默认的 hello world 上
- C++ CMake 构建错误:未定义对"boost::throw_exception(std::exception const&)"的引用
- 在 solaris 上增加 1.64 构建错误
- xgboost 构建错误:参数包未扩展为"..":
- 使用GCC 4.8构建错误:数组用作初始化器
- 编译 Java TD 客户端时出现构建错误
- 如何修复安卓工作室中的NDK构建错误
- C++ Cassandra 构建错误
- 我在 MinGW 和 VS 代码"g++ not recognized as a cmdlet..."时遇到构建错误
- Microsoft Visual Studio 2008,版本9.0.30739.1 SP,DLL构建错误
- 使用PPConsul(C 的领事客户端)构建错误的C 项目
- WURFL nginx 构建错误