- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 SurfFeatureDetect 和 FLANN 匹配器检测对象。但是,代码无法准确检测图像。我还以图片格式发布了结果。
这是我在 opencv 教程中的代码 website
int main(int argc, char** argv){
if (argc != 3){
readme(); return -1;
}
Mat img_object = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
Mat img_scene = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if (!img_object.data || !img_scene.data)
{
std::cout << " --(!) Error reading images " << std::endl; return -1;
}
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 100;
SurfFeatureDetector detector(minHessian);
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect(img_object, keypoints_object);
detector.detect(img_scene, keypoints_scene);
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute(img_object, keypoints_object, descriptors_object);
extractor.compute(img_scene, keypoints_scene, descriptors_scene);
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match(descriptors_object, descriptors_scene, matches);
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for (int i = 0; i < descriptors_object.rows; i++)
{
double dist = matches[i].distance;
if (dist < min_dist) min_dist = dist;
if (dist > max_dist) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist);
printf("-- Min dist : %f \n", min_dist);
//-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;
for (int i = 0; i < descriptors_object.rows; i++)
{
if (matches[i].distance < 3 * min_dist)
{
good_matches.push_back(matches[i]);
}
}
Mat img_matches;
drawMatches(img_object, keypoints_object, img_scene, keypoints_scene,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
//-- Localize the object
std::vector<Point2f> obj;
std::vector<Point2f> scene;
for (int i = 0; i < good_matches.size(); i++)
{
//-- Get the keypoints from the good matches
obj.push_back(keypoints_object[good_matches[i].queryIdx].pt);
scene.push_back(keypoints_scene[good_matches[i].trainIdx].pt);
}
Mat H = findHomography(obj, scene, CV_RANSAC);
//-- Get the corners from the image_1 ( the object to be "detected" )
std::vector<Point2f> obj_corners(4);
obj_corners[0] = cvPoint(0, 0); obj_corners[1] = cvPoint(img_object.cols, 0);
obj_corners[2] = cvPoint(img_object.cols, img_object.rows); obj_corners[3] = cvPoint(0, img_object.rows);
std::vector<Point2f> scene_corners(4);
perspectiveTransform(obj_corners, scene_corners, H);
//-- Draw lines between the corners (the mapped object in the scene - image_2 )
line(img_matches, scene_corners[0] + Point2f(img_object.cols, 0), scene_corners[1] + Point2f(img_object.cols, 0), Scalar(0, 255, 0), 4);
line(img_matches, scene_corners[1] + Point2f(img_object.cols, 0), scene_corners[2] + Point2f(img_object.cols, 0), Scalar(0, 255, 0), 4);
line(img_matches, scene_corners[2] + Point2f(img_object.cols, 0), scene_corners[3] + Point2f(img_object.cols, 0), Scalar(0, 255, 0), 4);
line(img_matches, scene_corners[3] + Point2f(img_object.cols, 0), scene_corners[0] + Point2f(img_object.cols, 0), Scalar(0, 255, 0), 4);
//-- Show detected matches
imshow("Good Matches & Object detection", img_matches);
waitKey(0);
return 0;}
/** @function readme */
void readme()
{
std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl;}
最佳答案
这是一个很常见的失败。问题在于单应性具有 8 个自由度 (8DOF)。这意味着您至少需要 4 个正确的对应关系才能计算出良好的单应性:
如你所见,单应性有8个参数(最后一个参数h33只是一个比例因子)。当您需要过滤掉不良对应关系(离群值)时,就会出现问题。当离群值多于离群值时(total/outliers > 50%
),RANSAC 过程无法找到离群值,您会得到奇怪的结果。
解决这个问题并不容易。你可以:
关于opencv - Features2d + Homography 没有给出适当的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27457836/
我想问一个我已经在 OpenCV 板上问过但没有得到答案的问题:http://answers.opencv.org/question/189206/questions-about-the-fundam
我正在使用OpenCV在Android上创建应用程序,并且需要Feature2d和Homography的Java代码。我需要像视频一样连续处理。我不是C++专家,所以无法移植。因此,如果可以的话,请提
我有两张相同的图片,但第二张变形了并且尺寸不同。我希望能够在第一张图片上选择一个点并在第二张图片上找到完全相同的点。图片的同步将在每张图片上进行4个点。 例子: 正常图片 图片失真 结果将是一个函数,
我正在尝试使用 SurfFeatureDetect 和 FLANN 匹配器检测对象。但是,代码无法准确检测图像。我还以图片格式发布了结果。 这是我在 opencv 教程中的代码 website int
我尝试做 this ,我发现 this 。他的问题不是我想问的,但我想做同样的事情。我可以在图像上找到特征并绘制特征描述符,但是对象周围的边界框很奇怪。抱歉,我不能在这里发布我的结果,出来的线不是矩形
引用this回答this question : What is happening is that you're considering all the keypoints detected in t
当我使用函数 cvFindHomograhpy() 获取结果时遇到问题。 它给出负坐标的结果,我现在将解释我在做什么。 我正在使用光流法进行视频稳定。我已经估计了第一帧和第二帧中特征的位置。现在,我的
我正在处理由 OpenCV 计算的单应性。我目前使用这个单应性来使用下面的函数来转换点。此函数执行我需要的任务,但我不知道它实际上是如何工作的。 谁能逐行准确地解释最后 3 行代码背后的逻辑/理论,我
我正在尝试计算视频的两个连续帧之间的比例、旋转和平移。所以基本上我匹配了关键点,然后使用 opencv 函数 findHomography() 来计算单应矩阵。 homography = findHo
我在将检测到的对象的轮廓放在正确位置时遇到了一些问题,就好像坐标在错误的位置一样。我将 hessian 设置为 2000,并且过滤了小于最小距离 3 倍的匹配项。任何帮助,将不胜感激。 运行匹配和单应
我一直在尝试编译this Android Studio 2.2 中的源代码,使用 Android NDK、OpenCV-2.4.10 和 OpenCV-2.4.10-android-sdk。我已经能够
在我的 Python/OpenCV 代码中,我使用随机单应性来模拟视点变化(我正在评估兴趣点检测器并希望避免搜索图像对)。 是否可以计算对极线和一幅图像及其扭曲版本之间的基本矩阵?我拥有的唯一信息是我
对不起,如果这听起来很愚蠢,但我真的需要问这个问题。 一旦计算出单应性,我能否使用它来将在一台相机中检测到的物体中心的二维坐标作为二维坐标投影到另一台立体相机? 最佳答案 一旦您拥有映射两个相机之间转
我有两张图片(A 和 B),一张与另一张略有扭曲,它们之间存在平移、旋转和比例差异(例如,这些图片:) Ssoooooooo 我需要在图片 B 中应用一种变换,以便补偿存在的失真/平移/旋转,使两张图
我正在使用光流来跟踪一些功能,我是初学者,必须遵循这些步骤 匹配良好的特征进行跟踪 对它们进行 Lucas-Kanade 算法 查找第一帧和当前帧之间的单应性 进行相机校准 分解单应图 现在我不明白的
我正在使用光流来跟踪一些功能,我是初学者,必须遵循这些步骤 匹配良好的特征进行跟踪 对它们进行 Lucas-Kanade 算法 查找第一帧和当前帧之间的单应性 进行相机校准 分解单应图 现在我不明白的
库:OpenCV目标:Android (OpenCV4Android) 我尝试计算世界平面(例如监视器屏幕)的单应性以获得相机姿势,对其进行变换并将点重新投影回以用于跟踪任务。我正在使用 OpenCV
使用 JavaCV。我在 ArrayList 中有 2 组 CvPoint2D32f 点,一组来自手机的图像采集器,另一组来自恒定的已知图像源。 我想应用 cvFindHomogrpahy() 方法,
我正在尝试通过 python 使用 opencv 在火车图像中查找多个对象,并将其与从查询图像中检测到的关键点进行匹配。对于我的情况,我正在尝试检测下面提供的图像中的网球场.我看了网上的教程,发现只能
我正在使用 Opencv python 接口(interface)并获得了单应矩阵 H。它似乎工作正常,因为我可以使用扭曲透视从源图像中获取扭曲图像。我现在尝试使用 H 和 Inverse H 在两个
我是一名优秀的程序员,十分优秀!