这是简单的二值化函数
void binarize(void *output, const void *input, int begin, int end, uint8_t threshold) {
#ifdef __ARM_NEON__
uint8x16_t thresholdVector = vdupq_n_u8(threshold);
uint8x16_t highValueVector = vdupq_n_u8(255);
uint8x16_t* __restrict inputVector = (uint8x16_t*)input;
uint8x16_t* __restrict outputVector = (uint8x16_t*)output;
for ( ; begin < end; begin += 16, ++inputVector, ++outputVector) {
*outputVector = (*inputVector > thresholdVector) & highValueVector;
}
#endif
}
它在 iOS 上运行良好。但是,当我为 Android 编译它时,它给了我一个错误:
错误:'uint8x16_t {aka __vector(16) __builtin_neon_uqi}'和'uint8x16_t {aka __vector(16) __builtin_neon_uqi}'类型的无效操作数到二进制'operator>'
我在 Android.mk 中使用这个标志来启用 NEON:
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_ARM_NEON := true
endif