这段时间做了个STM32的光流
之前一直是用的PIXFLOW和匿名的光流所以一直想自己做一个理解一下其中的过程
匿名的只是为了赚钱 所以不开源只有看pixflow的源码了
其中截取了一部分
复制到了自己的工程里
///////////////////////////////////////////////////////
//函数功能:检测某点是否是特征点
///////////////////////////////////////////////////////
static inline uint32_t compute_diff(uint8_t *image, uint16_t offX, uint16_t offY, uint16_t row_size)
{
uint16_t off = (offY + 2) * row_size + (offX + 2); // we calc only the 4x4 pattern
uint32_t acc;
//4*4像素向下求差,再累加
acc = __USAD8 (*((uint32_t*) &image), *((uint32_t*) &image));
acc = __USADA8(*((uint32_t*) &image), *((uint32_t*) &image), acc);
acc = __USADA8(*((uint32_t*) &image), *((uint32_t*) &image), acc);
//4*4像素向右求差,再累加
uint32_t col1 = (image << 24) | image << 16 | image << 8 | image;
uint32_t col2 = (image << 24) | image << 16 | image << 8 | image;
uint32_t col3 = (image << 24) | image << 16 | image << 8 | image;
uint32_t col4 = (image << 24) | image << 16 | image << 8 | image;
//全部累加
acc = __USADA8(col1, col2, acc);
acc = __USADA8(col2, col3, acc);
acc = __USADA8(col3, col4, acc);
return acc;
}
///////////////////////////////////////////////////////
//函数功能:比较两副8X8像素图片的相似度
///////////////////////////////////////////////////////
static inline uint32_t compute_sad_8x8(uint8_t *image1, uint8_t *image2, uint16_t off1X, uint16_t off1Y, uint16_t off2X, uint16_t off2Y, uint16_t row_size)
{
uint16_t off1 = off1Y * row_size + off1X; // image1
uint16_t off2 = off2Y * row_size + off2X; // image2
//两副8*8像素对应相减,再累加
uint32_t acc;
//第一行相减,再累加
acc = __USAD8 (*((uint32_t*) &image1), *((uint32_t*) &image2));
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
//第二行相减,再累加,依次类推
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
acc = __USADA8(*((uint32_t*) &image1), *((uint32_t*) &image2), acc);
return acc;
}
然后每隔4个像素来找特征点
//上下左右循环移动4个像素对比图片相似度
for(int8_t yy=winmin; yy<=winmax; yy++)
{
for(int8_t xx=winmin; xx<=winmax; xx++)
{
//计算匹配度
temp_match = compute_sad_8x8(image_new, image_old, x, y, x + xx, y + yy, wid);
//寻找最小值,越小越相似
if (temp_match < match_min)
{
sumx = xx;
sumy = yy;
match_min = temp_match;
}
}
}
最后实际的效果还不错 就是激光模块给手焊坏了
实际的波形
总之慢慢完善啦 实际效果如何 现在有光流摄像头了吧? nnnkey 发表于 2018-3-3 07:19
实际效果如何
实际定点10cm内飘 TANK99 发表于 2018-3-3 07:50
现在有光流摄像头了吧?
那些是商用的,自己做的更有意义 路过了解一下。 一块板硬件成本50可以吗 zzipeng 发表于 2018-3-3 10:11
一块板硬件成本50可以吗
成本肯定不止50 弱弱问一下 什么是光流呐… chewy 发表于 2018-3-3 22:14
弱弱问一下 什么是光流呐…
就是一种可以检测画面相对移动方向的相对移动速度的视觉硬件
页:
[1]