我正在编写代码,我需要使用函数来查找连接的组件,但我有两个错误:
错误7错误LNK2005:" int __cdecl getConnectedComps(struct _IplImage *,int&,class std :: vector>&)" (?getConnectedComps @@ YAHPEAU_IplImage @@ AEAHAEAV?$ vector @ PEAUCvConnectedComp @@ V?$ allocator @ PEAUCvConnectedComp @@@ std @@@ std @@@ Z)已在main.obj中定义C:\ Users \ Kristina \ Desktop \ Kompjuterska vizija \ PrviProjekat \ PrviProjekat \ getConnectedComps.obj Domaci1
错误8错误LNK1169:找到一个或多个多重定义的符号C:\ Users \ Kristina \ Desktop \ Kompjuterska vizija \ PrviProjekat \ x64 \ Debug \ Domaci1.exe Domaci1
有什么问题?我一直在使用MicrosoftVisualStudio 2013和功能
getConnectedComps.h
#include "opencv/cxcore.h"
#include "opencv/cv.h"
#include "opencv/cvaux.h"
#include "opencv/highgui.h"
#include <vector>
using namespace std;
int getConnectedComps(IplImage *image, int &totalComps, vector<CvConnectedComp*> &components);
getConnectedComps.cpp
#include "getConnectedComps.h"
#include <vector>
using namespace std;
#define MAX_COMPONENTS 250
int getConnectedComps(IplImage *image, int &totalComps, vector<CvConnectedComp*> &components)
{
int width, height;
if (!(image->roi))
{
width = image->width;
height = image->height;
}
else
{
width = image->roi->width;
height = image->roi->height;
}
vector<CvConnectedComp*>::iterator itComponent = components.begin();
int currentCompValue = 0;
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
{
CvScalar pixval = cvGet2D(image, y, x);
if (pixval.val[0] > currentCompValue)
{
if (++currentCompValue > MAX_COMPONENTS)
return -1;
if (*itComponent == NULL) *itComponent = new CvConnectedComp;
cvFloodFill(image,cvPoint(x, y), cvScalar(currentCompValue), cvScalar(0),
cvScalar(0), (*(itComponent++)), 8);
}
}
totalComps = currentCompValue;
return 0;
}
的main.cpp
#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <vector>
#include <ctype.h>
#include <stdio.h>
#include <iostream>
#include "getConnectedComps.cpp"
using namespace cv;
using namespace std;
int main(int argc, char** argv){
vector<CvConnectedComp*> components;
VideoCapture video1;
int vektor,s;
int width, height, frames1, fps1;
video1.open(argv[1]);
fps1 = video1.get(CV_CAP_PROP_FPS);
width = video1.get(CAP_PROP_FRAME_WIDTH);
height = video1.get(CAP_PROP_FRAME_HEIGHT);
frames1 = video1.get(CAP_PROP_FRAME_COUNT);
cout << "Video1 " << argv[1] <<
": width=" << width <<
", height=" << height <<
", frames=" << frames1 <<
", fps1=" << fps1 << endl;
int i = 0;
int j = 0;
Mat frameTime2, frameForeground, frameForeground1,maska, frameForeground2, frame3[3],frameForeground3, frameForegroundOut1, frameForegroundOut2;
Mat frameTime1(height, width, CV_8UC3, Scalar(0, 0, 0));
while (1){
video1 >> frameTime2;
bool bSuccess = video1.read(frameTime2);
if (!bSuccess) //if not success, break loop
{
cout << "ERROR: Cannot read a frame from video file" << endl;
break;
}
absdiff(frameTime1, frameTime2, frameForeground);
split(frameForeground, frame3);
threshold(frame3[0], frameForeground1, 15, 255, CV_THRESH_BINARY);
threshold(frame3[1], frameForeground2, 15, 255, CV_THRESH_BINARY);
threshold(frame3[2], frameForeground3, 15, 255, CV_THRESH_BINARY);
bitwise_or(frameForeground1, frameForeground2, frameForegroundOut1);
bitwise_or(frameForegroundOut1, frameForeground3, maska);
frameTime2.copyTo(frameTime1);
morphologyEx(maska, frameForegroundOut2, MORPH_OPEN, Mat());
erode(frameForegroundOut2, frameForegroundOut2, Mat());
morphologyEx(frameForegroundOut2, frameForegroundOut2, MORPH_CLOSE, Mat());
morphologyEx(frameForegroundOut2, frameForegroundOut2, MORPH_OPEN, Mat());
dilate(frameForegroundOut2, frameForegroundOut2, Mat());
dilate(frameForegroundOut2, frameForegroundOut2, Mat());
dilate(frameForegroundOut2, frameForegroundOut2, Mat());
dilate(frameForegroundOut2, frameForegroundOut2, Mat());
morphologyEx(frameForegroundOut2, frameForegroundOut2, MORPH_CLOSE, Mat());
morphologyEx(frameForegroundOut2, frameForegroundOut2, MORPH_CLOSE, Mat());
morphologyEx(frameForegroundOut2, frameForegroundOut2, MORPH_CLOSE, Mat());
morphologyEx(frameForegroundOut2, frameForegroundOut2, MORPH_CLOSE, Mat());
IplImage* img = new IplImage(frameForegroundOut2);
getConnectedComps(img, vektor, components);
}
}