2013-02-19 151 views
3

我试图安装OpenCV以使用Visual Studio。我使用的是2012Pro版本,但我认为它应该与vs10相同。 我按照这个教程: http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#windows-visual-studio-how-to在Visual Studio 2012中安装OpenCV

我有一个解决方案只有一个项目和只有一个文件。出于测试目的,我使用了与本教程中相同的代码。

// Video Image PSNR and SSIM 
#include <iostream> // for standard I/O 
#include <string> // for strings 
#include <iomanip> // for controlling float print precision 
#include <sstream> // string to number conversion 

#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur 
#include <opencv2/core/core.hpp>  // Basic OpenCV structures (cv::Mat, Scalar) 
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O 

using namespace std; 
using namespace cv; 

double getPSNR (const Mat& I1, const Mat& I2); 
Scalar getMSSIM(const Mat& I1, const Mat& I2); 

static void help() 
{ 
    cout 
     << "\n--------------------------------------------------------------------------" << endl 
     << "This program shows how to read a video file with OpenCV. In addition, it tests the" 
     << " similarity of two input videos first with PSNR, and for the frames below a PSNR " << endl 
     << "trigger value, also with MSSIM."<< endl 
     << "Usage:"                  << endl 
     << "./video-source referenceVideo useCaseTestVideo PSNR_Trigger_Value Wait_Between_Frames " << endl 
     << "--------------------------------------------------------------------------" << endl 
     << endl; 
} 
int main(int argc, char *argv[]) 
{ 
    help(); 
    if (argc != 5) 
    { 
     cout << "Not enough parameters" << endl; 
     return -1; 
    } 
    stringstream conv; 

    const string sourceReference = argv[1],sourceCompareWith = argv[2]; 
    int psnrTriggerValue, delay; 
    conv << argv[3] << argv[4];  // put in the strings 
    conv >> psnrTriggerValue >> delay;// take out the numbers 

    char c; 
    int frameNum = -1;   // Frame counter 

    VideoCapture captRefrnc(sourceReference), 
       captUndTst(sourceCompareWith); 

    if (!captRefrnc.isOpened()) 
    { 
     cout << "Could not open reference " << sourceReference << endl; 
     return -1; 
    } 

    if(!captUndTst.isOpened()) 
    { 
     cout << "Could not open case test " << sourceCompareWith << endl; 
     return -1; 
    } 

    Size refS = Size((int) captRefrnc.get(CV_CAP_PROP_FRAME_WIDTH), 
        (int) captRefrnc.get(CV_CAP_PROP_FRAME_HEIGHT)), 
     uTSi = Size((int) captUndTst.get(CV_CAP_PROP_FRAME_WIDTH), 
        (int) captUndTst.get(CV_CAP_PROP_FRAME_HEIGHT)); 

    if (refS != uTSi) 
    { 
     cout << "Inputs have different size!!! Closing." << endl; 
     return -1; 
    } 

    const char* WIN_UT = "Under Test"; 
    const char* WIN_RF = "Reference"; 

    // Windows 
      namedWindow(WIN_RF, CV_WINDOW_AUTOSIZE); 
      namedWindow(WIN_UT, CV_WINDOW_AUTOSIZE); 
      cvMoveWindow(WIN_RF, 400  ,   0);  //750, 2 (bernat =0) 
      cvMoveWindow(WIN_UT, refS.width,   0);  //1500, 2 

    cout << "Frame resolution: Width=" << refS.width << " Height=" << refS.height 
     << " of nr#: " << captRefrnc.get(CV_CAP_PROP_FRAME_COUNT) << endl; 

    cout << "PSNR trigger value " << 
      setiosflags(ios::fixed) << setprecision(3) << psnrTriggerValue << endl; 

    Mat frameReference, frameUnderTest; 
    double psnrV; 
    Scalar mssimV; 

    for(;;) //Show the image captured in the window and repeat 
    { 
     captRefrnc >> frameReference; 
     captUndTst >> frameUnderTest; 

     if(frameReference.empty() || frameUnderTest.empty()) 
     { 
      cout << " < < < Game over! > > > "; 
      break; 
     } 

     ++frameNum; 
     cout <<"Frame:" << frameNum; 

     ///////////////////////////////// PSNR //////////////////////////////////////////////////// 
     psnrV = getPSNR(frameReference,frameUnderTest);     //get PSNR 
     cout << setiosflags(ios::fixed) << setprecision(3) << psnrV << "dB"; 

     //////////////////////////////////// MSSIM ///////////////////////////////////////////////// 
     if (psnrV < psnrTriggerValue) 
     { 
      mssimV = getMSSIM(frameReference,frameUnderTest); 

      cout << " MSSIM: " 
       << "R" << setiosflags(ios::fixed) << setprecision(3) << mssimV.val[2] * 100 
       << "G" << setiosflags(ios::fixed) << setprecision(3) << mssimV.val[1] * 100 
       << "B" << setiosflags(ios::fixed) << setprecision(3) << mssimV.val[0] * 100; 
     } 

     cout << endl; 

     ////////////////////////////////// Show Image ///////////////////////////////////////////// 
     imshow(WIN_RF, frameReference); 
     imshow(WIN_UT, frameUnderTest); 

     c = (char)cvWaitKey(delay); 
     if (c == 27) break; 
    } 

    return 0; 
} 

double getPSNR(const Mat& I1, const Mat& I2) 
{ 
    Mat s1; 
    absdiff(I1, I2, s1);  // |I1 - I2| 
    s1.convertTo(s1, CV_32F); // cannot make a square on 8 bits 
    s1 = s1.mul(s1);   // |I1 - I2|^2 

    Scalar s = sum(s1);   // sum elements per channel 

    double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels 

    if(sse <= 1e-10) // for small values return zero 
     return 0; 
    else 
    { 
     double mse =sse /(double)(I1.channels() * I1.total()); 
     double psnr = 10.0*log10((255*255)/mse); 
     return psnr; 
    } 
} 

Scalar getMSSIM(const Mat& i1, const Mat& i2) 
{ 
    const double C1 = 6.5025, C2 = 58.5225; 
    /***************************** INITS **********************************/ 
    int d  = CV_32F; 

    Mat I1, I2; 
    i1.convertTo(I1, d);   // cannot calculate on one byte large values 
    i2.convertTo(I2, d); 

    Mat I2_2 = I2.mul(I2);  // I2^2 
    Mat I1_2 = I1.mul(I1);  // I1^2 
    Mat I1_I2 = I1.mul(I2);  // I1 * I2 

    /*************************** END INITS **********************************/ 

    Mat mu1, mu2; // PRELIMINARY COMPUTING 
    GaussianBlur(I1, mu1, Size(11, 11), 1.5); 
    GaussianBlur(I2, mu2, Size(11, 11), 1.5); 

    Mat mu1_2 = mu1.mul(mu1); 
    Mat mu2_2 = mu2.mul(mu2); 
    Mat mu1_mu2 = mu1.mul(mu2); 

    Mat sigma1_2, sigma2_2, sigma12; 

    GaussianBlur(I1_2, sigma1_2, Size(11, 11), 1.5); 
    sigma1_2 -= mu1_2; 

    GaussianBlur(I2_2, sigma2_2, Size(11, 11), 1.5); 
    sigma2_2 -= mu2_2; 

    GaussianBlur(I1_I2, sigma12, Size(11, 11), 1.5); 
    sigma12 -= mu1_mu2; 

    ///////////////////////////////// FORMULA //////////////////////////////// 
    Mat t1, t2, t3; 

    t1 = 2 * mu1_mu2 + C1; 
    t2 = 2 * sigma12 + C2; 
    t3 = t1.mul(t2);    // t3 = ((2*mu1_mu2 + C1).*(2*sigma12 + C2)) 

    t1 = mu1_2 + mu2_2 + C1; 
    t2 = sigma1_2 + sigma2_2 + C2; 
    t1 = t1.mul(t2);    // t1 =((mu1_2 + mu2_2 + C1).*(sigma1_2 + sigma2_2 + C2)) 

    Mat ssim_map; 
    divide(t3, t1, ssim_map);  // ssim_map = t3./t1; 

    Scalar mssim = mean(ssim_map); // mssim = average of ssim map 
    return mssim; 
} 

我已经下载了2.4.3版本,我把它解压到C:\ BUILD \ 所以现在我有C:\ BUILD \ OpenCV的等等

在视觉物业经理工作室我去的Microsoft.Cpp.Win.32.user表,我改变了以下:(根据说教程和其他解决方案在这里堆栈overvlow)

C/C++ - >一般我加入其他包含目录

C:\BUILD\opencv\modules\core\include\opencv2\core 
C:\BUILD\opencv\include\opencv 
C:\BUILD\opencv\include\opencv2 
C:\BUILD\opencv\build\include 
C:\BUILD\opencv\build\include\opencv2 
C:\BUILD\opencv\build\include\opencv 

连接器 - >常规附加库目录

C:\BUILD\opencv\build\x86\vc10\lib 

添加在连接器 - >输入 - >附加依赖

opencv_core243.lib 
opencv_imgproc243.lib 
opencv_highgui243.lib 
opencv_ml243.lib 
opencv_video243.lib 
opencv_features2d243.lib 
opencv_calib3d243.lib 
opencv_objdetect243.lib 
opencv_contrib243.lib 
opencv_legacy243.lib 
opencv_flann243.lib 

(是的,我知道关于调试的d。但是,无论是工作)

我尝试建立的解决方案,我得到以下错误:

1>Test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" ([email protected]@@[email protected]) referenced in function "public: __thiscall cv::Mat::~Mat(void)" ([email protected]@@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" ([email protected]@@[email protected]@[email protected]@Z) referenced in function "class cv::Mat & __cdecl cv::operator-=(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@Z) 
1>Test.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::_OutputArray::_OutputArray(class cv::Mat &)" ([email protected]@@[email protected]@[email protected]@Z) referenced in function "class cv::Mat & __cdecl cv::operator-=(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@Z) 
1>Test.obj : error LNK2019: unresolved external symbol "class cv::_OutputArray const & __cdecl cv::noArray(void)" ([email protected]@@[email protected]@XZ) referenced in function "class cv::Mat & __cdecl cv::operator-=(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@Z) 
1>Test.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::convertTo(class cv::_OutputArray const &,int,double,double)const " ([email protected]@[email protected]@[email protected]@[email protected]) referenced in function "class cv::Scalar_<double> __cdecl getMSSIM(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "public: class cv::MatExpr __thiscall cv::Mat::mul(class cv::_InputArray const &,double)const " ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]Z) referenced in function "class cv::Scalar_<double> __cdecl getMSSIM(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" ([email protected]@[email protected]@QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" ([email protected]@[email protected]@QAEXXZ) 
1>Test.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@Z) referenced in function "public: __thiscall cv::Mat::Mat(class cv::Mat const &)" ([email protected]@@[email protected]@@Z) 
1>Test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::subtract(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_OutputArray const &,class cv::_InputArray const &,int)" ([email protected]@@[email protected]@[email protected]@[email protected]) referenced in function "class cv::Mat & __cdecl cv::operator-=(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@Z) 
1>Test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::divide(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_OutputArray const &,double,int)" ([email protected]@@[email protected]@[email protected]@[email protected]) referenced in function "class cv::Scalar_<double> __cdecl getMSSIM(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "class cv::Scalar_<double> __cdecl cv::sum(class cv::_InputArray const &)" ([email protected]@@[email protected]@[email protected][email protected]@@Z) referenced in function "double __cdecl getPSNR(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "class cv::Scalar_<double> __cdecl cv::mean(class cv::_InputArray const &,class cv::_InputArray const &)" ([email protected]@@[email protected]@[email protected][email protected]@[email protected]) referenced in function "class cv::Scalar_<double> __cdecl getMSSIM(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::absdiff(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_OutputArray const &)" ([email protected]@@[email protected]@[email protected]@@Z) referenced in function "double __cdecl getPSNR(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" ([email protected]@@[email protected]) referenced in function "public: __thiscall cv::Mat::Mat(class cv::Mat const &)" ([email protected]@@[email protected]@@Z) 
1>Test.obj : error LNK2019: unresolved external symbol "class cv::MatExpr __cdecl cv::operator+(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]) referenced in function "class cv::Scalar_<double> __cdecl getMSSIM(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "class cv::MatExpr __cdecl cv::operator+(class cv::MatExpr const &,class cv::Scalar_<double> const &)" ([email protected]@[email protected]@[email protected][email protected]@[email protected]@Z) referenced in function "class cv::Scalar_<double> __cdecl getMSSIM(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "class cv::MatExpr __cdecl cv::operator*(double,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@@Z) referenced in function "class cv::Scalar_<double> __cdecl getMSSIM(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::GaussianBlur(class cv::_InputArray const &,class cv::_OutputArray const &,class cv::Size_<int>,double,double,int)" ([email protected]@@[email protected]@[email protected]@[email protected]@[email protected]@Z) referenced in function "class cv::Scalar_<double> __cdecl getMSSIM(class cv::Mat const &,class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
1>Test.obj : error LNK2019: unresolved external symbol _cvMoveWindow referenced in function _main 
1>Test.obj : error LNK2019: unresolved external symbol _cvWaitKey referenced in function _main 
1>Test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function _main 
1>Test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function _main 
1>Test.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::VideoCapture::VideoCapture(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function _main 
1>Test.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall cv::VideoCapture::~VideoCapture(void)" ([email protected]@@[email protected]) referenced in function _main 
1>Test.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall cv::VideoCapture::isOpened(void)const " ([email protected]@[email protected]@UBE_NXZ) referenced in function _main 
1>Test.obj : error LNK2019: unresolved external symbol "public: virtual double __thiscall cv::VideoCapture::get(int)" ([email protected]@[email protected]@[email protected]) referenced in function _main 

我试图以类似的看问题,在这里,但所有的解决方案来增加实际的库添加到Addicionl依赖。我做了什么。所以我不知道...

+0

你错过了一些核心opencv包括和/或库。 – 2013-10-28 23:56:04

+0

在链接器 - >输入 - >附加依赖项中,您确定文件的名称与“... \ opencv \ build \ x86 \ vc10 \ lib”中文件的名称完全匹配吗? – user2235615 2013-12-12 13:34:29

+0

[OpenCV 2.3 C++ Visual Studio 2010]的可能重复(http://stackoverflow.com/questions/7011238/opencv-2-3-c-visual-studio-2010) – karlphillip 2013-12-21 01:33:46

回答

0

您是否已将OpenCv路径添加到您的环境详细信息中?这通常是大多数教程告诉你要做的第一步。

但是,如果这不起作用,这是link,我总是用它来帮助我设置它。它使用的是VS 2012和OpenCV 2.4.3的版本,因此它与您的问题非常相似。

相关问题