- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想通过使用 arm neon 库在 ARM cortex a8 上实现我发现的关于 5ms ORB 特征计算的论文。但我已经在为 FAST 特征检测而苦苦挣扎。所以我尝试实现的论文你可以找到 here .所以首先我不确定 Bright 和 Dark 约束。因此,根据我的理解,如果中心像素周围有 9 个较暗或 9 个较亮的像素,您必须检查 FAST。所以我检查两者。但是现在我遇到了一个问题,如果没有最终的移位操作来计算它是否是一个角,那么我的实现平均已经花费了 3 倍的时间,然后是 opencv 的整个过程的平均计算。到目前为止,这是我的代码,也许有人可以指出我可以对其进行的一些优化。
//detect with opncv
Clock::time_point t0 = Clock::now();
detectors[y]->detect(img, ocv_kps);
Clock::time_point t1 = Clock::now();
vector<Point2f> my_kps;
//threshhold for FAST
const uchar th = 8;
int b_cnt = 0;
int d_cnt = 0;
//array with four possible corners to be processed in parallel
uint32_t id_arr[4];
uint32_t ib_arr[4];
Clock::time_point t01 = Clock::now();
for (int i = 3; i < img.rows - 3; i++) {
//get pointer to seven Image rows three above and three below center and center itself
const uchar* Mt3 = img.ptr<uchar>(i - 3);
const uchar* Mt2 = img.ptr<uchar>(i - 2);
const uchar* Mt1 = img.ptr<uchar>(i - 1);
const uchar* Mc = img.ptr<uchar>(i);
const uchar* Mb1 = img.ptr<uchar>(i + 1);
const uchar* Mb2 = img.ptr<uchar>(i + 2);
const uchar* Mb3 = img.ptr<uchar>(i + 3);
for (int j = 3; j < img.cols - 3; j++) {
const uchar j3 = j + 3;
const uchar j2 = j + 2;
const uchar j1 = j + 1;
const uchar jn3 = j - 3;
const uchar jn2 = j - 2;
const uchar jn1 = j - 1;
//image values for center left right top and bottom intensity of pixel
const uchar c = Mc[j];
const uchar l = Mc[jn3];
const uchar r = Mc[j3];
const uchar t = Mt3[j];
const uchar b = Mb3[j];
//threshold for bright FAST constraint
const uchar thb = c + th;
//bools for bright constraint
const bool cbt = t > thb;
const bool cbb = b > thb;
const bool cbl = l > thb;
const bool cbr = r > thb;
uchar mt3;
uchar mt3n;
uchar mt2;
uchar mt2n;
uchar mt1;
uchar mt1n;
uchar mb3;
uchar mb3n;
uchar mb2;
uchar mb2n;
uchar mb1;
uchar mb1n;
bool bc = false;
//pre test do we have at least two points which fulfill bright constraint
if ((cbl && cbt) || (cbt && cbr) || (cbr && cbb)
|| (cbb && cbl)) {
bc = true;
//get rest of image intensity values of circle
mt3 = Mt3[j1];
mt3n = Mt3[jn1];
mt2 = Mt2[j2];
mt2n = Mt2[jn2];
mt1 = Mt1[j3];
mt1n = Mt1[jn3];
mb3 = Mb3[j1];
mb3n = Mb3[jn1];
mb2 = Mb2[j2];
mb2n = Mb2[jn2];
mb1 = Mb1[j3];
mb1n = Mb1[jn3];
//values for bright constrain
ib_arr[b_cnt] = cbt | ((mt3) > thb) << 1
| ((mt2) > thb) << 2 | ((mt1) > thb) << 3
| (cbr << 4) | ((mb1) > thb) << 5
| ((mb2) > thb) << 6 | ((mb3) > thb) << 7
| cbb << 8 | ((mb3n) > thb) << 9
| ((mb2n) > thb) << 10 | ((mb1n) > thb) << 11
| (cbl) << 12 | ((mt1n) > thb) << 13
| ((mt2n) > thb) << 14 | ((mt3n) > thb) << 15
| (cbt) << 16 | ((mt3) > thb) << 17
| ((mt2) > thb) << 18 | ((mt1) > thb) << 19
| (cbr) << 20 | ((mb1) > thb) << 21
| ((mb2) > thb) << 22 | ((mb3) > thb) << 23;
b_cnt++;
//if we have four possible corners in array check if they are corners
if (b_cnt == 4) {
uint32x2x4_t IB = vld4_u32(ib_arr);
/*
* here the actual shift operation would take place
*/
b_cnt = 0;
}
}
//threshold for dark constraint
const uchar thd = c - th;
//bools for dark constraint
const bool cdl = l < thd;
const bool cdr = r < thd;
const bool cdt = t < thd;
const bool cdb = b < thd;
//pre test do we have at least two points which fulfill dark constraint
if ((cdl && cdt) || (cdt && cdr) || (cdr && cdb)
|| (cdb && cdl)) {
//if bright pre test failed intensity values are not initialised
if (!bc) {
//get rest of image intensity values of circle
mt3 = Mt3[j1];
mt3n = Mt3[jn1];
mt2 = Mt2[j2];
mt2n = Mt2[jn2];
mt1 = Mt1[j3];
mt1n = Mt1[jn3];
mb3 = Mb3[j1];
mb3n = Mb3[jn1];
mb2 = Mb2[j2];
mb2n = Mb2[jn2];
mb1 = Mb1[j3];
mb1n = Mb1[jn3];
}
//bool values for dark constrain
id_arr[d_cnt] = cdt | ((mt3) < thd) << 1
| ((mt2) < thd) << 2 | ((mt1) < thd) << 3
| (cdr) << 4 | ((mb1) < thd) << 5
| ((mb2) < thd) << 6 | ((mb3) < thd) << 7
| (cdb) << 8 | ((mb3n) < thd) << 9
| ((mb2n) < thd) << 10 | ((mb1n) < thd) << 11
| (cdl) << 12 | ((mt1n) < thd) << 13
| ((mt2n) < thd) << 14 | ((mt3n) < thd) << 15
| (cdt) << 16 | ((mt3) < thd) << 17
| ((mt2) < thd) << 18 | ((mt1) < thd) << 19
| (cdr) << 20 | ((mb1) < thd) << 21
| ((mb2) < thd) << 22 | ((mb3) < thd) << 23;
d_cnt++;
//if we have four possible corners in array check if they are corners
if (d_cnt == 4) {
uint32x2x4_t IA = vld4_u32(id_arr);
/*
* here the actual shift operation would take place
*/
d_cnt = 0;
}
int h = cdt;
}
}
}
Clock::time_point t11 = Clock::now();
cout << "my algorithm found " << my_kps.size()
<< " and ocv found " << ocv_kps.size() << endl;
microseconds ms1 = std::chrono::duration_cast < microseconds
> (t1 - t0);
microseconds ms2 = std::chrono::duration_cast < microseconds
> (t11 - t01);
rs.Push((double) ms2.count());
cout << "my algorithm duration " << ms2.count()
<< " and ocv duration is " << ms1.count() << endl;
最佳答案
我有一个 ORB 提取器,它在树莓派上以 30fps 的速度运行。
https://github.com/0xfaded/pislam
优化真的是一门魔法,更糟糕的是,ARM 从未发布过 a53 的优化指南。我们拥有的最好的是 a57,它可能具有类似的 NEON 单元。
我真的不能在这里提供完整的答案,但我会分享一些我的过程。
我的 FAST 提取器的第一部分加载测试像素环并将它们转换为 16 位向量,就像您的代码所做的那样。我没有直接编写 asm,而是使用了 gcc 内在函数。不过,我确保 gcc:
您会注意到第一个比较没有用掩码隔离它的位,掩码应该是 0x80
。这释放了一个寄存器,否则它会保持一个常量,并且它给 gcc 提供了足够的回旋余地,不会溢出寄存器。
您还会注意到一些相当可怕的内在用法:
d0 = vbslq_u8(vdupq_n_u8(0x40u), vcgeq_u8(test, dark), d0);
l0 = vbslq_u8(vdupq_n_u8(0x40u), vcleq_u8(test, light), l0);
这相当于
d0 |= test >= dark & 0x40;
l0 |= test >= light & 0x40;
Gcc 会愉快地编译后者,但会发出 1.5 倍的指令。
第二部分是在 16 位向量上进行 FAST-9 测试。下面编译为 16 条指令,但我花了将近一个月的时间断断续续地想出来。
uint8x16_t t0 = vtstq_u8(d0, d1);
uint8x16_t t1 = vtstq_u8(d0, d1);
t0 = vbslq_u8(t0, l0, d0);
t1 = vbslq_u8(t1, l1, d1);
uint8x16_t cntLo = vclzq_u8(t0);
uint8x16_t testLo = t1 << (cntLo - 1);
asm("vceq.u8 %q0, %q0, #0" : [val] "+w" (testLo));
uint8x16_t cntHi = vclzq_u8(t1);
uint8x16_t testHi = t0 << (cntHi - 1);
asm("vceq.u8 %q0, %q0, #0" : [val] "+w" (testHi));
uint8x16_t result = (cntLo & testLo) | (cntHi & testHi);
result = vtstq_u8(result, result);
令人恼火的是,gcc 不会将 testLo == 0
编译为 vceq.u8 %q0, %q0, #0
,这是用于与常数零。我最终手动插入了这些,从而省去了另外几条指令。
希望能提供一些见解。 Fast.h
关于opencv - 针对 ARM 优化的 FAST 计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40147136/
将 ARM 处理器模式与 x86 操作模式(ring0 到 ring 3)进行比较,用户模式看起来就像 ring3,用户空间程序在其中运行。 但是,我无法将 ring0 与系统模式或主管模式联系起来。
为什么我们在 ARM 架构中有暂存寄存器?处理器如何使用它,我的意思是这个寄存器的用途是什么? 最佳答案 来自 Procedure Call Standard for the Arm Architec
我了解弱内存模型和强内存模型的基本区别。但是没有确切的弱定义,它取决于体系结构(这里是 ARM)。 我已经阅读了有关 ARM 信息中心的文档,但仍有很多内容不清楚。有人可以列出 - ARM 保证哪些内
我想在 arm 9 上分析我的代码,是否有任何分析器可以给我函数调用时间和每个函数占用的总周期?我更喜欢任何免费的分析器。我喜欢在 Linux 中使用 kcachegrind。 最佳答案 我不知道有什
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this qu
众所周知,对于X86架构:按下电源按钮后,机器开始执行0xFFFFFFF0处的代码,然后开始执行BIOS中的代码以进行硬件初始化。 BIOS 执行后,它使用引导加载程序将操作系统镜像加载到内存中。最后
我有 rootfs 和 klibc 文件系统。我正在创建 make 规则,而一些开发人员的编译器较旧,但没有联网。note1 我正在尝试验证所有文件都是使用 arm 仅当检测到某个版本的编译器时。我已
在部署实际应用程序之前,我们使用 ARM 模板部署 Azure 资源,作为构建过程的一部分。 到目前为止,我们所有的应用程序资源都自包含在资源组中。例如需要 SQL Server 和存储帐户的 Web
为什么 ARM Controller 在发生异常时要从 THUMB 状态返回到 ARM 状态? 最佳答案 一种解释可能是 ARM 模式是 CPU 的“ native ”操作模式,与有限的 Thumb
我正在尝试反转 128 位向量 (uint16x8) 的顺序。 例如,如果我有 a b c d e f g h 我想获得 h g f e d c b a 有没有一种简单的方法可以使用 NEON 内在函
有很多关于内存屏障的信息。大多数信息是指多核或多处理器架构。 Stackoverflow 上的某个地方还指出,单核处理器不需要内存屏障。 到目前为止,我找不到任何明确的解释,为什么单核 CPU 上不需
我想在 ARM Cortex A8 处理器上移植一小段代码。 L1 缓存和 L2 缓存都非常有限。我的程序中有 3 个数组。其中两个是顺序访问的(大小> 数组 A:6MB 和数组 B:3MB),第三个
我无法弄清楚这个 ARM 指令是做什么的: strd.w r0, r1, [r2] 我知道这是一个存储指令,它在 *r2 中存储了一些东西。但我不完全确定是什么。为什么有两个源寄存器
我很好奇为什么有些 ARM 指令(如 MUL 和 ADD)不使用桶形移位器。我想知道极限背后的理性。谢谢! 最佳答案 并不是没有使用桶形移位器;这是您无法指定它在非常具体的指令(数据处理和加载/存储)
我需要计算与 SSE 相同的操作: __m128i result1=_mm_avg_epu8 (upper, lower); 使用 NEON,我执行以下操作: uint8x16_t result1=v
我正在尝试使用 PLD 指令。我面临的问题如下: int32_t addr[10]; asm ("PLD [addr,#5]"); 我收到以下错误: Error: ARM register expec
根据 ARM 手册,应该可以访问特定 CPU 模式的存储寄存器,例如“r13_svc”。当我尝试执行此操作时,gcc 对我大喊大叫,并显示以下错误: 立即表达式需要 # 前缀 -- `mov r2,s
我正在使用 mbxxx 目标开发 Contiki 2.7。在构建我的代码时,链接器提示 .ARM.exidx 和 .data 部分的重叠 .在修改了链接器脚本 contiki-2.7/cpu/stm3
如何确定给定 ARM 处理器上是否存在 NEON 引擎?可以为此目的查询任何状态/标志寄存器吗? 最佳答案 我相信unixsmurf's answer如果使用具有特权内核的操作系统,这将与您获得的一样
如何在设备上分析我的 ARM 代码。 这是涉及 USB 和 SDH 处理的裸机代码,我看到了这个 Code Profiler for ARM但似乎很 slim ,我很熟悉DS5但如果您使用基于 lin
我是一名优秀的程序员,十分优秀!