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_<int> &,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 <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <vector>
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<cv::Mat> 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= " <<nTemp << endl;

	cv::rectangle(image, rect, cv::Scalar(0,255,0));

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

	cv::waitKey();
	return 0;
}

解决办法:

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



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值