Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在使用findHomography时遇到一些困难-编译错误_C++_Opencv_Visual Studio 2013 - Fatal编程技术网

C++ 在使用findHomography时遇到一些困难-编译错误

C++ 在使用findHomography时遇到一些困难-编译错误,c++,opencv,visual-studio-2013,C++,Opencv,Visual Studio 2013,以下是从open cv文档中查找已知对象的功能2d+同形异义词y的代码 #include<opencv\cv.h> #include <opencv2\core\core.hpp> #include <opencv2\features2d\features2d.hpp> #include <opencv2\highgui\highgui.hpp> #include <opencv2\nonfree\nonfree.hpp> #inclu

以下是从open cv文档中查找已知对象的功能2d+同形异义词y的代码

#include<opencv\cv.h>
#include <opencv2\core\core.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\nonfree\nonfree.hpp>
#include <opencv2\calib3d\calib3d.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>

using namespace std;
using namespace cv;

/** @function main */

int main(){

/*-- Load the images --*/
Mat image1= imread("C:\\panL.jpg");
Mat image2 = imread("C:\\panR.jpg");

if (!image1.data || !image2.data)
{
    cout << " --(!) Error reading images " << endl; return -1;
}

imshow("first image", image2);
imshow("second image", image1);

/*-- Detecting the keypoints using SURF Detector --*/
int minHessian = 400;
SurfFeatureDetector detector(minHessian);

vector<KeyPoint> keypoints_1, keypoints_2;

detector.detect(image1, keypoints_1);
detector.detect(image2, keypoints_2);

/*-- Calculating descriptors (feature vectors) --*/
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;

extractor.compute(image1, keypoints_1, descriptors_1);
extractor.compute(image2, keypoints_2, descriptors_2);

/*-- Step 3: Matching descriptor vectors using FLANN matcher --*/
FlannBasedMatcher matcher;
vector< DMatch > matches;
matcher.match(descriptors_1, descriptors_2, matches);

//-- Quick calculation of max and min distances between keypoints
double max_dist = 0; double min_dist = 100;

for (int i = 0; i < descriptors_1.rows; i++)
{
    double dist = matches[i].distance;
    if (dist < min_dist) min_dist = dist;
    if (dist > max_dist) max_dist = dist;
}

cout << "-- Max dist :" << max_dist << endl;
cout << "-- Min dist :" << min_dist << endl;

/*-- Drawing matches  whose distance is less than 2*min_dist,
*-- or a small arbitary value ( 0.02 ) in the event that min_dist is verysmall)
*/
vector< DMatch > good_matches;

for (int i = 0; i < descriptors_1.rows; i++)
{
    if (matches[i].distance <= max(2 * min_dist, 0.02))
    {
        good_matches.push_back(matches[i]);
    }
}

/*-- Draw only good matches --*/
Mat img_matches;
drawMatches(image1, keypoints_1, image2, keypoints_2,
    good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
    vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

/*-- Show detected matches --*/
imshow("Good Matches", img_matches);

for (int i = 0; i < (int)good_matches.size(); i++)
{
    cout << "-- Good Match [i] Keypoint 1: " << good_matches[i].queryIdx << " -- Keypoint 2:" << good_matches[i].trainIdx << endl;
}

vector< Point2f > obj;
vector< Point2f > scene;

if (good_matches.size() >= 4)
{
    for (int i = 0; i < good_matches.size(); i++)
    {
        //-- Get the keypoints from the good matches
        obj.push_back(keypoints_1[good_matches[i].queryIdx].pt);
        scene.push_back(keypoints_2[good_matches[i].trainIdx].pt);
    }

    // Find the Homography Matrix
    Mat H = findHomography(obj, scene, CV_RANSAC);
    // Use the Homography Matrix to warp the images
    Mat result;
    warpPerspective(image1, result, H, Size(image1.cols + image2.cols, image1.rows));
    Mat half(result, Rect(0, 0, image2.cols, image2.rows));
    image2.copyTo(half);
    imshow("Result", result);
}
waitKey(0);
return 0;
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
/**@主功能*/
int main(){
/*--加载图像--*/
Mat image1=imread(“C:\\panL.jpg”);
Mat image2=imread(“C:\\panR.jpg”);
如果(!image1.data | |!image2.data)
{
cout max_dist)max_dist=dist;
}

由于未链接OpenCV库,因此可能会出现链接错误。您可以将以下库添加到VS2013项目的
属性>链接器>输入>其他依赖项(假设您在调试模式下使用OpenCV-2.4.8):

如果您正在使用CMake,这将更加容易,只需通过以下方式完成:

target_link_libraries(yourProject ${OpenCV_LIBS})
target_link_libraries(yourProject ${OpenCV_LIBS})