- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试按照 OpenCV 教程在 C++ 中实现我自己的 FAST 算法。作为算法 says :
The pixel p is a corner if there exists a set of n contiguous pixels in the circle (of 16 pixels) which are all brighter than I_p + t, or all darker than I_p − t. (Shown as white dash lines in the above image). n was chosen to be 12.
A high-speed test was proposed to exclude a large number of non-corners. This test examines only the four pixels at 1, 9, 5 and 13 (First 1 and 9 are tested if they are too brighter or darker. If so, then checks 5 and 13). If p is a corner, then at least three of these must all be brighter than I_p + t or darker than I_p − t. If neither of these is the case, then p cannot be a corner. The full segment test criterion can then be applied to the passed candidates by examining all pixels in the circle. This detector in itself exhibits high performance
我将我的 FAST 输出与阈值为 100 的 OpenCV 的 FAST 输出进行了比较。我意识到我的未能检测到所有角落:
当我将 n 减少到 0(尽管 n 应该 >12 以获得最佳结果)时,我在这种类型的图像测试中得到了(仅)相同的结果,但它通常仍然无法检测到矩形的角:
这是我的完整代码:
#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <iostream>
#include <opencv2/features2d/features2d.hpp>
using namespace std;
using namespace cv;
#define THRESHOLD 100
/*
** Compares intensity of pixels 1,5,9,13 of the circle surrounding a pixel at (i,j) of an image with its intensity ip.
** If 3 out of 4 satisfy the threshold FAST constraints : bright (i>ip+t) & dark (i<ip-t),
** the pixel at (i,j) is considered a possible key point
*/
bool couldBeKeyPoint(Mat imageIn, int i, int j, int threshold) {
uchar ip = imageIn.at<unsigned char>(i, j); //intensity of the potential key point
uchar ip9 = imageIn.at<unsigned char>(i, j - 3); //intensity of pixel 1 of the surrounding circle
uchar ip1 = imageIn.at<unsigned char>(i, j + 3); //intensity of pixel 9 of the surrounding circle
uchar ip5 = imageIn.at<unsigned char>(i + 3, j); //intensity of pixel 5 of the surrounding circle
uchar ip13 = imageIn.at<unsigned char>(i - 3, j); //intensity of pixel 13 of the surrounding circle
//checking FAST bright constraints on these 4 surrounding pixels
bool b1 = (ip1 >= ip + threshold);
bool b9 = (ip9 >= ip + threshold);
bool b5 = (ip5 >= ip + threshold);
bool b13 = (ip13 >= ip + threshold);
//cout << b1+b9+b5+b13 ;
//at least three of these must all be brighter than I_p + t.
if (b1+b9+b5+b13 >=3)
return true;
bool d1 = (ip1 <= ip - threshold);
bool d9 = (ip9 <= ip - threshold);
bool d5 = (ip5 <= ip - threshold);
bool d13 = (ip13 <= ip - threshold);
//cout << d1+d9+d5+d13 << "\n" ;
//at least three of these must all be darker than I_p − t.
if (d1+d9+d5+d13 >=3)
return true;
return false;
}
bool isKeyPoint(Mat imageIn, int i, int j, int threshold, int numberPixelsToCheck){
cout << "iskeypoint";
vector<unsigned char> pixelSurroundings;
pixelSurroundings.push_back(imageIn.at<unsigned char>(i, j));//the potential key point
pixelSurroundings.push_back(imageIn.at<unsigned char>(i, j + 3));//pixel 1
pixelSurroundings.push_back(imageIn.at<unsigned char>(i + 1, j + 3 3));//pixel 2
pixelSurroundings.push_back(imageIn.at<unsigned char>(i + 2, j + 2));//pixel 3
pixelSurroundings.push_back(imageIn.at<unsigned char>(i + 3, j + 1));//pixel 4
pixelSurroundings.push_back(imageIn.at<unsigned char>(i + 3, j));//pixel 5
pixelSurroundings.push_back(imageIn.at<unsigned char>(i + 3, j - 1));//pixel 6
pixelSurroundings.push_back(imageIn.at<unsigned char>(i + 2, j - 2));//pixel 7
pixelSurroundings.push_back(imageIn.at<unsigned char>(i + 1, j - 3));//pixel 8
pixelSurroundings.push_back(imageIn.at<unsigned char>(i, j - 3));//pixel 9
pixelSurroundings.push_back(imageIn.at<unsigned char>(i - 1, j - 3));//pixel 10
pixelSurroundings.push_back(imageIn.at<unsigned char>(i - 2, j - 2));//pixel 11
pixelSurroundings.push_back(imageIn.at<unsigned char>(i - 3, j - 1));//pixel 12
pixelSurroundings.push_back(imageIn.at<unsigned char>(i - 3, j));//pixel 13
pixelSurroundings.push_back(imageIn.at<unsigned char>(i - 3, j + 1));//pixel 14
pixelSurroundings.push_back(imageIn.at<unsigned char>(i - 2, j + 2));//pixel 15
pixelSurroundings.push_back(imageIn.at<unsigned char>(i - 1, j + 3));//pixel 16
if (numberPixelsToCheck > 16){
numberPixelsToCheck = 12; //The author have used N=12 in the first version of the algorithm
cout << "Error number of surrounding pixels to check should not exceed 16! Value 12 was used instead. " << std::endl ;
}
unsigned char ip = pixelSurroundings[0];
int brightScore = 0;
int darkScore = 0;
bool d = false,e=false;
for(int j=1;j<pixelSurroundings.size();j++){
unsigned char i = pixelSurroundings[j];
d = (i >= ip + (unsigned char ) threshold);
e = (i <= ip - (unsigned char ) threshold);
brightScore += d;
darkScore += e;
}
cout << darkScore << " DARKSCORE \n";
cout << brightScore << " BRIGHTSCORE \n";
if (darkScore >= numberPixelsToCheck || brightScore >= numberPixelsToCheck){
//cout << darkScore << " DARKSCORE \n";
//cout << brightScore << " BRIGHTSCORE \n";
return true; //the pixel is a key point
}
return false;
}
//renvoit un ensemble de détections
//inputarray image
vector<KeyPoint> FAST(Mat imageIn, vector<KeyPoint> keypoints, int threshold){
if(!imageIn.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
//return {};
}
keypoints.clear();
int i, j, count =0;
for (i = 3; i < imageIn.rows - 3; i++)
{
for (j = 3; j < imageIn.cols - 3; j++)
{
if (couldBeKeyPoint(imageIn, i, j, threshold)){
if (isKeyPoint(imageIn, i, j, threshold, 0)){
keypoints.push_back(KeyPoint(j, i ,1));
count++;
cout << "keypoint found at " << i << " " << j << "\n";
}
}
}
}
cout << "NUMBER OF KEYPOINTS :" << keypoints.size() << "\n";
return keypoints;
}
int main(int argc, char** argv){
vector<KeyPoint> keypointsMyFast;
vector<KeyPoint> keypointsOpenCvFast;
Mat src, destMyFast, destOpenCvFast;
//src= imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
//src= imread(argv[1], CV_8UC3);
src= imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
imshow( "ORGINAL",src);
waitKey(1);
keypointsMyFast = FAST(src, keypointsMyFast,THRESHOLD);
drawKeypoints(src, keypointsMyFast, destMyFast, Scalar(255,0,0));
imshow( "MYFAST",destMyFast);
waitKey(1);
FAST(src,keypointsOpenCvFast,THRESHOLD,false);
cout << "NUMBER OF open cv KEYPOINTS :" << keypointsOpenCvFast.size() << "\n";
drawKeypoints(src, keypointsOpenCvFast, destOpenCvFast, Scalar(255,0,0));
imshow( "Display window",destOpenCvFast);
waitKey(0);
}
知道什么会导致算法无法检测到矩形中的角点吗?特别是:如何使用 imread
正确加载图像? (改变第二个参数给出不同的结果)
非常感谢
最佳答案
问题出现在初始的 couldBeKeyPoint 函数中。此函数检查顶部、底部、左侧、右侧位置的候选关键点位置,如果中心点比周围的 3 个点亮/暗,则返回 true。
此假设不适用于直角正方形或矩形,因为正方形/矩形的边缘永远不会满足条件。您需要通过将要满足的周围点的数量减少到 2 来放宽函数的条件。
关于c++ - 快速算法 : No Corner Detection in Rectangular shapes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53798900/
您好,我很确定我的问题很愚蠢,但我无法弄清楚它对我的生活有何影响。我有这个家庭作业,它基本上是为了加强我们在类里面学到的关于多态性的知识(顺便说一下,这是 C++)。该程序的基础是一个名为 shape
我是新手,所以需要任何帮助,当我要求一个例子时,我的教授给我了这段代码,我希望有一个工作模型...... from numpy import loadtxt import numpy as np fr
CSS 形状边距 和 外型不适用于我的系统。我正在使用最新版本的 Chrome。我唯一能想到的是我的操作系统是 Windows 7。这应该是一个问题吗? 这是JSFiddle .但是,由于在您的系统上
#tf.shape(tensor)和tensor.shape()的区别 ?
我要求提示以下问题。如何从事件表添加到指定的单元格形状?当我知道名称但不知道如何为...中的每个形状实现论坛时,我可以添加形状 目前我有这样的事情: Sub loop() Dim a As Integ
我在 Excel 中有一个流程设计(使用形状、连接器等)。 我需要的是有一个矩阵,每个形状都有所有的前辈和所有的后继者。 在 VBA 中,为此我正在尝试执行以下操作: - 我列出了所有的连接器(Sha
我正在使用 JavaFX 编写一个教育应用程序,用户可以在其中绘制和操作贝塞尔曲线 Line、QuadCurve 和 CubicCurve。这些曲线应该能够用鼠标拖动。我有两种选择: 1- 使用类 L
我正在尝试绘制 pandas 系列中列的直方图 ('df_plot')。因为我希望 y 轴是百分比(而不是计数),所以我使用权重选项来实现这一点。正如您在下面的堆栈跟踪中发现的那样,权重数组和数据系列
我尝试在 opencv dnn 中实现一个 tensorflow 模型。这是我遇到的错误: OpenCV: Can't create layer "flatten_1/Shape" of type "
我目前正在用 Java 开发一款游戏,我一直在尝试弄清楚如何在 Canvas 上绘制一个形状(例如圆形),在不同的形状(例如正方形)之上,但是只绘制与正方形相交的圆的部分,类似于 Photoshop
import cv2 import numpy as np import sys import time import os cap = cv2.VideoCa
我已经成功创建了 Keras 序列模型并对其进行了一段时间的训练。现在我试图做出一些预测,但即使使用与训练阶段相同的数据,它也会失败。 我收到此错误:{ValueError}检查输入时出错:预期 em
我正在尝试逐行分解程序。 Y 是一个数据矩阵,但我找不到任何关于 .shape[0] 究竟做了什么的具体数据。 for i in range(Y.shape[0]): if Y[i] == -
我正在尝试运行代码,但它给了我这个错误: 行,列,_ = frame.shape AttributeError:“tuple”对象没有属性“shape” 我正在使用OpenCV和python 3.6,
我想在 JavaFx 中的 Pane 上显示形状。我正在使用从空间数据库中选择的 Oracle JGeometry 对象,它有一个方法 createShape() 但它返回 java.awt.Shap
在此代码中: import pandas as pd myj='{"columns":["tablename","alias_tablename","real_tablename","
我正在尝试将 API 结果应用于两列。 下面是我的虚拟数据框。不幸的是,这不是很容易重现,因为我使用的是带有 key 和密码的 API...这只是为了让您了解尺寸。 但我希望也许有人能发现一个明显的问
我的代码是: final String json = getObjectMapper().writeValueAsString(JsonView.with(graph) .onClas
a=np.arange(240).reshape(3,4,20) b=np.arange(12).reshape(3,4) c=np.zeros((3,4),dtype=int) x=np.arang
我正在尝试从张量中提取某些数据,但出现了奇怪的错误。在这里,我将尝试生成错误: a=np.random.randn(5, 10, 5, 5) a[:, [1, 6], np.triu_indices(
我是一名优秀的程序员,十分优秀!