我正在使用 Visual Studio 2010 和 OpenCV 库。当我尝试编译以下代码时,出现以下错误:
错误 LNK2001:无法解析的外部符号“class cv::Mat __cdecl grdX(class cv::Mat)”(?grdX@@YA?AVMat@cv@@V12@@Z)
错误 LNK1120:1 未解决的外部
//Includes
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
//Prototypes
Mat grdX(Mat);
Mat grdY(Mat);
int main()
{
Mat_<uchar> mat = imread("C:/img.jpg");
int row = mat.rows;
int col = mat.cols;
Mat_<uchar> f(row, col);
f = grdX(mat);
namedWindow ("img2", CV_WINDOW_AUTOSIZE);
imshow ("img2", f);
return EXIT_SUCCESS;
}
Mat grdX(Mat_<uchar> matrix)
{
int row = matrix.rows;
int col = matrix.cols;
Mat_<uchar> grd(row,col);
for (int i=1; i<=row ;i++)
{
for (int j=1; j<=col; j++)
{
if (j==1)
{grd(i,1) = (int)matrix(i,2)-(int)matrix(i,1);}
else if (j==col)
{grd(i,col) = (int)matrix(i,col)-(int)matrix(i,col-1);}
else {grd(i,j)=((int)matrix(i,j+1)-(int)matrix(i,j-1))/2;}
}
}
return grd;
}
Mat grdY(Mat_<uchar> matrix)
{
int row = matrix.rows;
int col = matrix.cols;
Mat_<uchar> grd(row,col);
for (int i=1; i<=row ;i++)
{
for (int j=1; j<=col; j++)
{
if (i==1)
{grd(1,j) = (int)matrix(2,j)-(int)matrix(1,j);}
else if (i==row)
{grd(row,j) = (int)matrix(row,j)-(int)matrix(row-1,j);}
else {grd(i,j)=((int)matrix(i+1,j)-(int)matrix(i-1,j))/2;}
}
}
return grd;
}
我在我的代码中找不到什么问题。