Note:OpenCV3.2.0自带的只有x64,x86需要自己编译。下面仅以x64为例配置。
X:\opencv\build\include\opencv2
X:\opencv\build\include\opencv
X:\opencv\build\include
X:\opencv\build\x64\vc14\lib
opencv_world320.lib(适用于“Release”)或
opencv_world320d.lib(适用于“Debug”)
将opencv的路径加到系统的路径变量中:计算机->(右键)属性->高级系统设置->高级(标签)->环境变量,在PATH中加入。
或者,在命令行中输入(各值间用英文分号“;”作为分隔符):
set PATH=F:\opencv\build\x64\vc14\bin;%PATH%
并重启电脑即可。
#include
#include
using namespace cv;
using namespace std;
static Mat onAffine(Mat* im, Point2f dif);
static Mat onRot(int pos, int rat, Mat* im);
static void onMouse(int Event, int x, int y, int drag, Mat* im);
void main(int argc, char* argv[])
{
Mat Cam = imread("Girl.png"), dst;
int pos = 36, rat = 10, hes = 40; //initial value
namedWindow("Video");
createTrackbar("Angle", "Video", &pos, 72); //rotate the image
createTrackbar("Scale", "Video", &rat, 20); //scale the image
setMouseCallback("Video", (MouseCallback)onMouse, &Cam); //drag image
while ((waitKey(50) & 255) != 13)
{//press the Enter key to exit the programe
dst = onRot(pos, rat, &Cam); imshow("Video", dst);
}//end while
}//end main
static void onMouse(int Event, int x, int y, int drag, Mat* im)
{
static Mat res = im->clone(); static const Point ini(0, 0);
static Point seed(ini), tdf(ini); Point now(x, y);
switch (Event)
{
case CV_EVENT_LBUTTONDOWN: seed = now; break;
case CV_EVENT_LBUTTONUP: tdf += (now - seed); break;
case CV_EVENT_RBUTTONUP: res.copyTo(*im); tdf = ini; break;
}//end switch
if (drag == CV_EVENT_FLAG_LBUTTON) //drag the mouse to move the image
*im = onAffine(&res, tdf + (now - seed)); //use Affine transformation
}//end onMouse
static Mat onAffine(Mat* im, Point2f dif)
{
Point2f org[3], tri[3]; org[1] = Point2f(im->cols / 2, 0);
org[0] = Point2f(0, 0); org[2] = Point2f(0, im->rows / 2);
for (int i = 0; i<3; ++i) tri[i] = org[i] + dif;
Mat warp = getAffineTransform(org, tri), dst;
warpAffine(*im, dst, warp, im->size()); return dst;
}//end onAffine
static Mat onRot(int pos, int rat, Mat* im)
{
Point center(im->cols/2.0 + 0.5, im->rows/2.0 + 0.5);
double angle = 5 * pos - 180, scale = 0.1*rat;
Mat rot = getRotationMatrix2D(center, angle, scale), dst;
warpAffine(*im, dst, rot, im->size()); return dst;
}//end onRot
OpenCV3.2移除了默认的SURF和SIFT库,放到了OpenCV的extra modules(即opencv_contrib)中。
SURF和SIFT的源码,参见:
https://github.com/opencv/opencv_contrib/tree/master/modules/xfeatures2d/src
如何编译opencv_contrib,参见:
http://blog.csdn.net/cosmispower/article/details/60601151
opencv_aruco320.lib
opencv_bgsegm320.lib
opencv_bioinspired320.lib
opencv_calib3d320.lib
opencv_ccalib320.lib
opencv_core320.lib
opencv_datasets320.lib
opencv_dnn320.lib
opencv_dpm320.lib
opencv_face320.lib
opencv_features2d320.lib
opencv_flann320.lib
opencv_fuzzy320.lib
opencv_highgui320.lib
opencv_imgcodecs320.lib
opencv_imgproc320.lib
opencv_line_descriptor320.lib
opencv_ml320.lib
opencv_objdetect320.lib
opencv_optflow320.lib
opencv_phase_unwrapping320.lib
opencv_photo320.lib
opencv_plot320.lib
opencv_reg320.lib
opencv_rgbd320.lib
opencv_saliency320.lib
opencv_shape320.lib
opencv_stereo320.lib
opencv_stitching320.lib
opencv_structured_light320.lib
opencv_superres320.lib
opencv_surface_matching320.lib
opencv_text320.lib
opencv_tracking320.lib
opencv_video320.lib
opencv_videoio320.lib
opencv_videostab320.lib
opencv_xfeatures2d320.lib
opencv_ximgproc320.lib
opencv_xobjdetect320.lib
opencv_xphoto320.lib