2017-05-22 6 views
1

VisualCast for Visual Studio 2013과 함께 OpenCV 2.4.10을 사용하고 있습니다. 하지만 다음과 같은 연결 오류가 점점 오전 : 나는 또한 오전오류 LNK2019 : 확인할 수없는 외부 기호 openCV가 포함 된 Visual Studio 2013

#include<opencv2\core\core.hpp> 
#include<opencv2\imgproc\imgproc.hpp> 
#include<cmath> 
#include<vector> 
#include<queue> 
#include<map> 
#include<string> 



class Pathfinding 
{ 
private : 
//Two dimensional , integer -based point structure , contains additional variables for pathfinding calculation 

**struct Point2A** 
{ 
    // x, y the coordinates of the point 
    //dir is the direction from the previous point . see directions coding below 

    int x, y, dir; 


    //level: the cost of route from start to this point 
    //fscore: the essence of the A* algorithm, value is : [level] + [in air distance from destination] * astar_weight 

    float fScore, level; 

    //Constructors 
    Point2A() : x(0), y(0), fScore(0), dir(0){}; 
    Point2A(int _x, int _y, float _level = 0.f, int _dir = 0) :x(_x), y(_y), level(_level), fScore(0), dir(_dir) {}; 

    //== operator overload 
    bool operator == (const Point2A other); 

}; 

//CompByPos : struct used in the stl map<Point2A, Point2A> during the pathfinding 
//it only contains a comparator function 
//we need this, because every point is unique by position, but not by fscore 

struct CompByPos 
{ 

    bool operator()(const Point2A a, const Point2A b) const; 
}; 

//CompByFScore : contains a comparating function, which works by fscore 
//it gives priority for the smaller fScore 
//used in stl priority_queue<Point2A> 

struct CompByFScore 
{ 
    bool operator()(const Point2A a, const Point2A b); 
}; 

//mapimg is the map got, pathmap is the same, but the pixels of the path are colored 
//pathmap is only valid after calculate path 
//blurmap is matimg blurred with opencv function, its used in keeping away from walls 

cv::Mat mapimg, pathmap, blurmap; 


//astar_weight is the multiplier of A* coefficient 
//wall_weight is used in keeping away from walls features 

float astar_weight, wall_weight; 

//no comment 
Point2A start, dest; 

//daigonal decides if a pixel (which is a node) has 4 or 8 neighbours 
//see direction coding below 
//calculated decides if the Pathfinding object has valid path for current map and settings 

bool diagonal, calculated; 

//mrows and mcols refers to the size of mapimg 
//blursize is used in avaoiding wall avoidance feature 

int mrows, mcols, blur_size; 

//stores the list of directions for the path 
std::string dir; 


//calculated Eucledian Distance between two points a and b 

float Distance(Point2A a, Point2A b); 

//returns an array of the points surrounding point p 
//the length of the array is not constant, because the function performs 
//OnMap checks too. use arraySize ref variable to get the size of the array returned 

Point2A* GetNeighbors(Point2A p, int& arraySize); 

// Function sets default values 
void InitValues(); 

//Checks if point p is wall 
//Class support black and white maps, where black pixels are wall 

bool IsWall(Point2A p); 

//Function decides if coordinates of this point are on map or not 
bool OnMap(int x, int y); 

public: 

enum ErrorCodes 
{ 
    NoError = 0, 
    NoMap, 
    StartIsWall, 
    DestIsWall, 
    NoPath, 
    AlreadyCalculated 

}; 

static const int diagonalDirX[]; 
static const int diagonalDirY[]; 
static const int nonDiagonalDirX[]; 
static const int nonDiagonalDirY[]; 

//constructor :sets default values diagonal = true, astar coefficient 0.3 
Pathfinding(); 

//constructor, argument map is the map on which algorithm is implemented 
Pathfinding(cv::Mat map, bool _diagonal = true); 

//Set OpenCV Mat image as the map 
void SetMap(cv::Mat map); 

////sets the A* pathfinding coefficient. 0.f means Dijkstra's algorithm, anything else is A* (positive values recommended). 
//The bigger the value, the more the algorithm steers towards the destination 
//but setting it too high can result in suboptimal path 
//after changing that, have to call CalculatePath again 

void SetAWeight(float weight); 

//if set to true, each pixel has 8 connected neighbor, else only 4 - see GetDirections() comment 
//after changing that, have to call CalculatePath again 
void SetDiagonal(bool _diagonal); 

//sets the value of how much the algorithm tries to avoid going near walls. 
//weight: the amount the walls push away the route. default 10.f 
//0.f disables the feature 
//avoidZoneLevel: the size of the zone surrounding the walls, in which the upper effect works. default: 5 
void SetWallWeight(float weight, int avoidZoneLevel); 

//sets the start point. the coordinate system is the OpenCV/image default, the origin is the upper left corner of the image. 
//start and destination points have to be set after the map image! 
void SetStart(int x, int y); 
void SetDestination(int x, int y); 

//returns the map, on which the calculated path is marked red 
//call this after CalculatePath(), otherwise returns empty map 
cv::Mat GetPathMap(); 

// returns a std::string of numbers, which represent the directions along the path.Direction coding(relative to p) : 
    //call after CalculatePath() 
    //if diagonal is set to true    if diagonal == false 
    //  [0] [1] [2]         [3] 
    //  [3] [p] [4]        [2] [p] [0] 
    //  [5] [6] [7]         [1] 
std::string GetDirections(); 

//evaluates the algorithm. It's a separate function because it takes some time 
//check out the ErrorCodes enum to decode the returned values 
ErrorCodes CalculatePath(); 
}; 

: 헤더 파일 여기

1>Pathfinding.obj : error LNK2019: unresolved external symbol "public: class cv::Vec & __cdecl cv::Mat::at >(int,int)" ([email protected][email protected][email protected]@@@[email protected]@@[email protected][email protected]@[email protected]) referenced in function "private: struct Pathfinding::Point2A * __cdecl Pathfinding::GetNeighbors(struct Pathfinding::Point2A,int &)" ([email protected]@@[email protected]@[email protected]@Z)

1>C:\Users\ysingh\Documents\DstarLite\OpenCV\Astar\x64\Debug\Astar.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

입니다 위의 오류가 언급된다 (클래스 정의에 구조체 Point2A를 참조하십시오) 이 클래스 다음

#include "Pathfinding.h" 

bool Pathfinding::Point2A::operator==(const Point2A other) { 

return x == other.x && y == other.y; 
} 

bool Pathfinding::CompByPos::operator()(const Point2A a, const Point2A b) const 
{ 

if (a.x == b.x) 
    return a.y > b.y; 
else 
    return a.x > b.x; 
    } 

bool Pathfinding::CompByFScore::operator()(const Point2A a, const Point2A b) 
    { 

return a.fScore > b.fScore; 
    } 

float Pathfinding::Distance(Point2A a, Point2A b) 
{ 

float x = static_cast<float>(a.x - b.x); 
float y = static_cast<float>(a.y - b.y); 
return sqrtf(x*x + y*y); 
} 

Pathfinding:: Point2A* Pathfinding::GetNeighbors(Point2A p, int& arraySize) 
{ 

arraySize = 0; 
uchar size; 

if (diagonal) 
    size = 8; 
else 
    size = 4; 

Point2A* ret = new Point2A[size]; 
for (int i = 0; i < size; i++) { 

    int x, y; 
    if (diagonal) 
    { 

     x = p.x + diagonalDirX[i]; 
     y = p.y + diagonalDirY[i]; 
    } 
    else 
    { 
     x = p.x + nonDiagonalDirX[i]; 
     y = p.y + nonDiagonalDirY[i]; 
    } 

    if (!OnMap(x, y)) 
     continue; 

    float level = p.level + 1.f + (255 - blurmap.at<cv::Vec3b>(y, x)[2])/255.f * wall_weight; 
    Point2A n = Point2A(x, y, level, i); 

    if (diagonal && (i == 0 || i == 2 || i == 5 || i == 7)) 
     n.level += 0.414213f; 

    ret[arraySize] = n; 
    arraySize++; 
} 
return ret; 
} 

void Pathfinding::InitValues() 
{ 

astar_weight = 0.3f; 
wall_weight = 10.f; 
blur_size = 11; 
diagonal = true; 
calculated = false; 
} 

bool Pathfinding::IsWall(Point2A p) 
{ 

if (mapimg.at<cv::Vec3b>(p.y, p.x) == cv::Vec3b(0, 0, 0)) 
    return true; 
return false; 
} 

bool Pathfinding::OnMap(int x, int y) 
{ 

if (x >= 0 && y >= 0 && x < mcols && y < mrows) 
    return true; 
return false; 
} 

const int Pathfinding::diagonalDirX[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; 
const int Pathfinding::diagonalDirY[] = { -1, -1, -1, 0, 0, 1, 1, 1 }; 
const int Pathfinding::nonDiagonalDirX[] = { 1, 0, -1, 0 }; 
const int Pathfinding::nonDiagonalDirY[] = { 0, 1, 0, -1 }; 

Pathfinding::Pathfinding() 
    { 

InitValues(); 
    } 

Pathfinding::Pathfinding(cv::Mat map, bool _diagonal) 
{ 

InitValues(); 
SetMap(map); 
diagonal = _diagonal; 
} 

void Pathfinding::SetMap(cv::Mat map) 
{ 

if (!map.empty()) 
     { 

    mapimg = map; 
    calculated = false; 
    mrows = map.rows; 
    mcols = map.cols; 
    GaussianBlur(mapimg, blurmap, cv::Size(blur_size, blur_size), 0); 
     } 
    } 

void Pathfinding::SetAWeight(float weight) 
    { 

if (astar_weight != weight) 
     { 

    astar_weight = weight; 
    calculated = false; 
     } 
    } 

void Pathfinding::SetDiagonal(bool _diagonal) 
    { 

if (diagonal != _diagonal) 
     { 

    diagonal = _diagonal; 
    calculated = false; 
     } 
    } 

void Pathfinding::SetWallWeight(float weight, int avoidZoneLevel) 
    { 

if (wall_weight == weight && blur_size == 2 * avoidZoneLevel + 1) 
    return; 

wall_weight = weight; 
if (avoidZoneLevel >= 0) 
    blur_size = 2 * avoidZoneLevel + 1; 
calculated = false; 
    } 

void Pathfinding::SetStart(int x, int y) 
     { 

if (!mapimg.empty()) 
     { 

    if (OnMap(x, y)) 
     { 

     start = Point2A(x, y); 
     calculated = false; 
     } 
    } 
    } 

void Pathfinding::SetDestination(int x, int y) 
{ 

if (!mapimg.empty()) 
    { 

    if (OnMap(x, y)) 
{ 

     dest = Point2A(x, y); 
     calculated = false; 
     } 
    } 
    } 

cv::Mat Pathfinding::GetPathMap() 
{ 

if (calculated) return pathmap; 
else return cv::Mat(); 
    } 

std::string Pathfinding::GetDirections() 
{ 

if (calculated) return dir; 
else return std::string(); 
} 

Pathfinding::ErrorCodes Pathfinding::CalculatePath() 
{ 

if (calculated) 
    return AlreadyCalculated; 

if (mapimg.empty()) 
    return NoMap; 

if (IsWall(start)) 
    return StartIsWall; 

if (IsWall(dest)) 
    return DestIsWall; 

dir = std::string(); 
mapimg.copyTo(pathmap); 
int **closedSet = new int*[mrows]; 
float **openSet = new float*[mrows]; 
for (int i = 0; i < mrows; i++) { 

    closedSet[i] = new int[mcols]; 
    openSet[i] = new float[mcols]; 
    for (int j = 0; j < mcols; j++) { 

     closedSet[i][j] = 0; 
     openSet[i][j] = -1.0f; 
     } 
    } 

    std::priority_queue<Pathfinding::Point2A, std::vector<Point2A>, CompByFScore> openSetQue[2]; 
int osq = 0; 
std::map <Pathfinding::Point2A, Pathfinding::Point2A, CompByPos> cameFrom; 

start.fScore = Distance(start, dest); 
openSetQue[osq].push(start); 
openSet[start.y][start.x] = 0.0f; 
while (openSetQue[osq].size() != 0) { 
    Point2A current = openSetQue[osq].top(); 
    if (current == dest) { 
     while (cameFrom.size() != 0) { 

      pathmap.at<cv::Vec3b>(current.y, current.x) = cv::Vec3b(0, 0, 255); 
      dir = std::to_string(current.dir) + dir; 
      auto it = cameFrom.find(current); 
      Point2A keytmp = current; 
      if (it == cameFrom.end()) { 
       for (int i = 0; i < mrows; i++) { 

        delete openSet[i]; 
        delete closedSet[i]; 
       } 
       delete openSet; 
       delete closedSet; 
       calculated = true; 
       dir = dir.substr(1, dir.length() - 1); 
       return NoError; 
      } 
      current = cameFrom[current]; 
      cameFrom.erase(keytmp); 
     } 
    } 
    openSetQue[osq].pop(); 
    closedSet[current.y][current.x] = 1; 
    int arraySize; 
    Point2A *neighbors = GetNeighbors(current, arraySize); 

    for (int i = 0; i < arraySize; i++) { 

     Point2A neighbor = neighbors[i]; 

     if (closedSet[neighbor.y][neighbor.x] == 1) 
      continue; 

     if (IsWall(neighbor)) { 

      closedSet[neighbor.y][neighbor.x] = 1; 
      continue; 
     } 
     float ngScore = neighbor.level; 

     if (openSet[neighbor.y][neighbor.x] == -1.0f || ngScore < openSet[neighbor.y][neighbor.x]) { 

      cameFrom[neighbor] = current; 
      neighbor.fScore = ngScore + Distance(neighbor, dest) * astar_weight; 

      if (openSet[neighbor.y][neighbor.x] == -1.0f) { 
       openSet[neighbor.y][neighbor.x] = ngScore; 
       openSetQue[osq].push(neighbor); 
      } 
      else { 
       openSet[neighbor.y][neighbor.x] = ngScore; 
       while (!(neighbor == openSetQue[osq].top())) { 

        openSetQue[1 - osq].push(openSetQue[osq].top()); 
        openSetQue[osq].pop(); 
       } 
       openSetQue[osq].pop(); 
       if (openSetQue[osq].size() >= openSetQue[1 - osq].size()) { 
        osq = 1 - osq; 
       } 
       while (!openSetQue[osq].empty()) { 
        openSetQue[1 - osq].push(openSetQue[osq].top()); 
        openSetQue[osq].pop(); 
       } 
       osq = 1 - osq; 
       openSetQue[osq].push(neighbor); 
       } 
      } 
     } 
    delete neighbors; 
    } 
return NoPath; 
} 

의 .CPP를 부착하는 것은 너무 내 주요 파일 .CPP입니다 :

,691 363,210
#include"Pathfinding.h" 
#include<opencv2\highgui\highgui.hpp> 
#include<iostream> 


Pathfinding pathfinding; 
cv::Mat mapimg; 


void DisplayMap() 
{ 
cv::Mat tmp; 
cv::imshow("Path", tmp); 
} 

int main() 
{ 
//Open and load the map 

mapimg = cv::imread("test.png"); 
pathfinding.SetMap(mapimg); 
pathfinding.SetWallWeight(0.f, 0); 
pathfinding.SetStart(1, 1); 
pathfinding.SetDestination(39, 53); 
pathfinding.SetDiagonal(false); 
DisplayMap(); 

} 

는 내가 통화 당에서 함수의 정의에 두 번 길 찾기 클래스를 사용하고 생각 (예 : .cpp 파일의 29 행>Pathfinding:: Point2A*Pathfinding::GetNeighbors(Point2A p, int& arraySize)

내 의도가에서 코드의 무리를 던져하지 않습니다 사람들이 문제에 대한 완전한 그림을 제공하여 사람들이 나에게 몇 가지 유용한 제안을 해줄 수 있도록합니다. 내 사과.

마감 시간이 가까워 시간이 제한됩니다. 누군가 나에게 몇 가지 해결책을 제안 할 수 있습니까?

+0

나는 OpenCV의 라이브러리와 링크를 만들었습니다. –

+0

@Rama - 아래에서 속성 -> 링커 -> 입력 -> 추가 종속성 opencv_core2410d.lib opencv_contrib2410d.lib opencv_highgui2410d.lib opencv_gpu2410d.lib opencv_flann2410d.lib opencv_features2d2410d.lib opencv_imgproc2410d.lib opencv_calib3d2410d.lib opencv_stitching2410d opencv_photo2410d.lib opencv_objdetect2410d.lib opencv_nonfree2410d.lib opencv_ml2410d.lib opencv_legacy2410d.lib.lib opencv_ts2410d.lib opencv_video2410d.lib opencv_videostab2410d.lib –

+0

괜찮아 보인다! (디버그 용) – Rama

답변

0

귀하의 프로젝트 설정이 문제가된다고 가정합니다 (실용적인 최소한의 예제를 작성 했으므로 실제로는 올바른 라이브러리와 포함을 사용합니다).

include 및 lib 경로가 무엇을 평가하는지 확인하십시오 (구성 사이트 내부에서 확인하십시오). 어쩌면 상대 경로이거나 마크로가 잘못 설정된 것을 볼 수 있습니다.

보통 "UNRESOLVED EXTERNAL"오류는 올바른 lib (32/64 디버그/릴리스는 4 가지 조합입니다!)를 링크하지 않았거나 lib 경로가 잘못되었음을 의미합니다.

+0

OpenCV 3.2를 사용하고 IDE 내의 프로젝트 설정을 다시 설정했습니다. 이제 문제가 해결되었습니다. 이 게시물에 늦게 늦어지는 것에 대해 사과드립니다. –

0

당신의 사업이 answer,

If you DID explicitly set up linking with all the necessary libraries, but linking errors still show, you might be mixing up 64/32 bit libraries and application.

BUILD -> Configration Manager. check 'platform' is 'x64'

확인을 참조하십시오 -> 일반 - - OpenCV의 라이브러리

그리고 링커를 어디에> 라이브러리 디렉토리 경로를 포함 -> 속성 -> VC++ 디렉토리> 부록 라이브러리 디렉토리

C:\opencv\build\x64\vc11\lib 

(VS2012를 실행하는 64 비트 컴퓨터에서는 다른 설정에 따라 달라질 수 있음).

+0

예 디버그 및 릴리스 중에 구성 플랫폼이 x64 –

+0

lib 디렉토리가 64 비트인지 확인합니다. – Rama

+0

예, 링커 -> 일반 -> 추가 라이브러리 디렉토리 C : \ opencv \ build \ x64 \ vc12 \ lib; % (AdditionalLibraryDirectories) VC++ 디렉터리 -> 라이브러리 디렉터리 $ (VC_LibraryPath_x64); $ (WindowsSDK_LibraryPath_x64); –