Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ openCV 2.3.1 findContours函数的链接错误_C++_Opencv - Fatal编程技术网

C++ openCV 2.3.1 findContours函数的链接错误

C++ openCV 2.3.1 findContours函数的链接错误,c++,opencv,C++,Opencv,当我尝试使用Visual Studio 2008运行查找方块代码时,它给出了以下错误 1>ANPR.obj : error LNK2001: unresolved external symbol "public: virtual class cv::GlBuffer __thiscall cv::_InputArray::getGlBuffer(void)const " (?getGlBuffer@_InputArray@cv@@UBE?AVGlBuffer@2@XZ) 1>ANPR

当我尝试使用Visual Studio 2008运行查找方块代码时,它给出了以下错误

1>ANPR.obj : error LNK2001: unresolved external symbol "public: virtual class cv::GlBuffer __thiscall cv::_InputArray::getGlBuffer(void)const " (?getGlBuffer@_InputArray@cv@@UBE?AVGlBuffer@2@XZ)
1>ANPR.obj : error LNK2001: unresolved external symbol "public: virtual class cv::GlTexture __thiscall cv::_InputArray::getGlTexture(void)const " (?getGlTexture@_InputArray@cv@@UBE?AVGlTexture@2@XZ)
1>ANPR.obj : error LNK2001: unresolved external symbol "public: virtual class  cv::gpu::GpuMat __thiscall cv::_InputArray::getGpuMat(void)const " (?getGpuMat@_InputArray@cv@@UBE?AVGpuMat@gpu@2@XZ)
代码:

#include <cv.h>
#include <highgui.h>

using namespace cv;

double angle( cv::Point pt1, cv::Point pt2, cv::Point pt0 ) 
{
    double dx1 = pt1.x - pt0.x;
    double dy1 = pt1.y - pt0.y;
    double dx2 = pt2.x - pt0.x;
    double dy2 = pt2.y - pt0.y;
    return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
}


void find_squares(Mat& image, vector<vector<Point> >& squares)
{
    // blur will enhance edge detection
    Mat blurred(image);
    medianBlur(image, blurred, 9);

    Mat gray0(blurred.size(), CV_8U), gray;
    vector<vector<Point> > contours;

    // find squares in every color plane of the image
    for (int c = 0; c < 3; c++)
    {
        int ch[] = {c, 0};
        mixChannels(&blurred, 1, &gray0, 1, ch, 1);

        // try several threshold levels
        const int threshold_level = 2;
        for (int l = 0; l < threshold_level; l++)
        {
            // Use Canny instead of zero threshold level!
            // Canny helps to catch squares with gradient shading
            if (l == 0)
            {
                Canny(gray0, gray, 10, 20, 3); // 

                // Dilate helps to remove potential holes between edge segments
                dilate(gray, gray, Mat(), Point(-1,-1));
            }
            else
            {
                    gray = gray0 >= (l+1) * 255 / threshold_level;
            }

            // Find contours and store them in a list
            findContours(gray, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

            // Test contours
            vector<Point> approx;
            for (size_t i = 0; i < contours.size(); i++)
            {
                // approximate contour with accuracy proportional
                // to the contour perimeter
                approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);

                // Note: absolute value of an area is used because
                // area may be positive or negative - in accordance with the
                // contour orientation
                if (approx.size() == 4 &&
                        fabs(contourArea(Mat(approx))) > 1000 &&
                        isContourConvex(Mat(approx)))
                {
                        double maxCosine = 0;

                        for (int j = 2; j < 5; j++)
                        {
                                double cosine = fabs(angle(approx[j%4], approx[j-2], approx[j-1]));
                                maxCosine = MAX(maxCosine, cosine);
                        }

                        if (maxCosine < 0.3)
                                squares.push_back(approx);
                }
           }
       }
     }
   }
int main()
{    
    Mat img = imread("peppers.jpg");
    cvtColor(img, img, CV_RGB2GRAY);
    vector<vector<Point> > squares;
    find_squares(img, squares);

    std::cout << "squares size: " << squares.size() << std::endl;
    getchar();

    return 0;
 }
#包括
#包括
使用名称空间cv;
双角度(cv::点pt1、cv::点pt2、cv::点pt0)
{
双dx1=pt1.x-pt0.x;
双dy1=pt1.y-pt0.y;
双dx2=pt2.x-pt0.x;
双dy2=pt2.y-pt0.y;
返回(dx1*dx2+dy1*dy2)/sqrt(dx1*dx1+dy1*dy1)*(dx2*dx2+dy2*dy2)+1e-10);
}
无效查找方格(材质和图像、向量和方格)
{
//模糊将增强边缘检测
Mat模糊(图像);
中间模糊(图像,模糊,9);
Mat灰色0(模糊的大小(),CV_8U),灰色;
矢量等值线;
//在图像的每个颜色平面中查找正方形
对于(int c=0;c<3;c++)
{
int ch[]={c,0};
混音通道(&模糊,1,&灰色,0,1,通道,1);
//尝试几个阈值级别
const int threshold_level=2;
对于(int l=0;l=(l+1)*255/阈值\u级;
}
//找到等高线并将其存储在列表中
findContours(灰色、等高线、等高线列表、等高线链近似简单);
//测试轮廓
向量近似;
对于(size_t i=0;i1000&&
isContourConvex(材料(近似)))
{
双最大余弦=0;
对于(int j=2;j<5;j++)
{
双余弦=fabs(角度(约[j%4],约[j-2],约[j-1]);
最大余弦=最大值(最大余弦,余弦);
}
如果(最大余弦<0.3)
正方形。推回(大约);
}
}
}
}
}
int main()
{    
Mat img=imread(“peppers.jpg”);
CVT颜色(img、img、CV_RGB2GRAY);
矢量平方;
找到方格(img,方格);

这些错误与链接过程有关,您提到的符号属于opencv_核心库

确保已将此库添加为项目的依赖项。转到配置属性链接器输入并添加:
opencv\u core242.lib


有关如何配置Visual Studio和OpenCV的更多说明,请参见。

这些错误与链接过程有关,您提到的符号属于OpenCV_核心库

确保已将此库添加为项目的依赖项。转到配置属性链接器输入并添加:
opencv\u core242.lib

有关如何配置Visual Studio和OpenCV的更多说明