OpenCV遇到的问题——meanShift函数链接出错——001

OpenCV使用均值漂移Mean Shift算法查找物体时,遇到的问题:

>  main.cpp
1>  All outputs are up-to-date.
1>main.obj : error LNK2001: unresolved external symbol "int __cdecl cv::meanShift(class cv::_InputArray const &,class cv::Rect_ &,class cv::TermCriteria)" (?meanShift@cv@@YAHABV_InputArray@1@AAV?$Rect_@H@1@VTermCriteria@1@@Z)
1>c:\users\pkru\documents\visual studio 2010\Projects\TestCmean\Debug\TestCmean.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILE

源代码:

/*------------------------------------------------------------------------------------------*\
   This file contains material supporting chapter 4 of the cookbook:  
   Computer Vision Programming using the OpenCV Library. 
   by Robert Laganiere, Packt Publishing, 2011.

   This program is free software; permission is hereby granted to use, copy, modify, 
   and distribute this source code, or portions thereof, for any purpose, without fee, 
   subject to the restriction that the copyright notice may not be removed 
   or altered from any source or altered source distribution. 
   The software is released on an as-is basis and without any warranties of any kind. 
   In particular, the software is not guaranteed to be fault-tolerant or free from failure. 
   The author disclaims all warranties with regard to this software, any use, 
   and any consequent failure, is purely the responsibility of the user.
 
   Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name
\*------------------------------------------------------------------------------------------*/
#include 
#include 

#include 
#include 
using namespace std;

#include "..\..\include\opencv2\highgui\highgui.hpp"
#include "..\..\include\opencv2\video\tracking.hpp"
#include "..\..\include\opencv2\core\core.hpp"
#include "..\..\include\opencv2\imgproc\imgproc.hpp"
#include "..\..\include\opencv2\objdetect\objdetect.hpp"


#include "CVColorHistogram.h"
#include "CVObjectFinder.h"

int main()
{
	// Read reference image
	cv::Mat image= cv::imread("..\\..\\testdata\\baboon1.jpg");
	if (!image.data)
		return 0; 

	// Define ROI
	cv::Mat imageROI= image(cv::Rect(110,260,35,40));
	cv::rectangle(image, cv::Rect(110,260,35,40),cv::Scalar(0,0,255));

	// Display image
	cv::namedWindow("Image");
	cv::imshow("Image",image);

	// Get the Hue histogram
	int minSat=65;
	CCVColorHistogram hc;
	cv::MatND colorhist= hc.getHueHistogram(imageROI,minSat);

	CCVObjectFinder finder;
	finder.setHistogram(colorhist);
	finder.setThreshold(0.2f);

	// Convert to HSV space
	cv::Mat hsv;
	cv::cvtColor(image, hsv, CV_BGR2HSV);

	// Split the image
	vector v;
	cv::split(hsv,v);

	// Eliminate pixels with low saturation
	cv::threshold(v[1],v[1],minSat,255,cv::THRESH_BINARY);
	cv::namedWindow("Saturation");
	cv::imshow("Saturation",v[1]);

	// Get back-projection of hue histogram
	int ch[1]={0};
	cv::Mat result= finder.find(hsv,0.0f,180.0f,ch,1);

	cv::namedWindow("Result Hue");
	cv::imshow("Result Hue",result);

	cv::bitwise_and(result,v[1],result);
	cv::namedWindow("Result Hue and");
	cv::imshow("Result Hue and",result);

	// Second image
	image= cv::imread("..\\..\\testdata\\baboon3.jpg");

	// Display image
	cv::namedWindow("Image 2");
	cv::imshow("Image 2",image);

	// Convert to HSV space
	cv::cvtColor(image, hsv, CV_BGR2HSV);

	// Split the image
	cv::split(hsv,v);

	// Eliminate pixels with low saturation
	cv::threshold(v[1],v[1],minSat,255,cv::THRESH_BINARY);
	cv::namedWindow("Saturation");
	cv::imshow("Saturation",v[1]);

	// Get back-projection of hue histogram
	result= finder.find(hsv,0.0f,180.0f,ch,1);

	cv::namedWindow("Result Hue");
	cv::imshow("Result Hue",result);

	// Eliminate low stauration pixels
	cv::bitwise_and(result,v[1],result);
	cv::namedWindow("Result Hue and");
	cv::imshow("Result Hue and",result);

	// Get back-projection of hue histogram
	finder.setThreshold(-1.0f);
	result= finder.find(hsv,0.0f,180.0f,ch,1);
	cv::bitwise_and(result,v[1],result);
	cv::namedWindow("Result Hue and raw");
	cv::imshow("Result Hue and raw",result);

	cv::Rect rect(110,260,35,40);
	cv::rectangle(image, rect, cv::Scalar(0,0,255));

	cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER,10,0.01);
	int nTemp = 0;
	nTemp = cv::meanShift(result,rect,criteria);

	cout << "meanshift= " <

解决办法:

因为 CamShift and meanShift 是 video\tracking module 的一部分,所以应该增加: link the opencv_videoXXX.lib,如下图:



你可能感兴趣的:(OpenCV)