中级会员
- 积分
- 397
- 金钱
- 397
- 注册时间
- 2017-5-5
- 在线时间
- 153 小时
|
之前一直是用的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[off + 0 + 0 * row_size]), *((uint32_t*) &image[off + 0 + 1 * row_size]));
- acc = __USADA8(*((uint32_t*) &image[off + 0 + 1 * row_size]), *((uint32_t*) &image[off + 0 + 2 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image[off + 0 + 2 * row_size]), *((uint32_t*) &image[off + 0 + 3 * row_size]), acc);
- //4*4像素向右求差,再累加
- uint32_t col1 = (image[off + 0 + 0 * row_size] << 24) | image[off + 0 + 1 * row_size] << 16 | image[off + 0 + 2 * row_size] << 8 | image[off + 0 + 3 * row_size];
- uint32_t col2 = (image[off + 1 + 0 * row_size] << 24) | image[off + 1 + 1 * row_size] << 16 | image[off + 1 + 2 * row_size] << 8 | image[off + 1 + 3 * row_size];
- uint32_t col3 = (image[off + 2 + 0 * row_size] << 24) | image[off + 2 + 1 * row_size] << 16 | image[off + 2 + 2 * row_size] << 8 | image[off + 2 + 3 * row_size];
- uint32_t col4 = (image[off + 3 + 0 * row_size] << 24) | image[off + 3 + 1 * row_size] << 16 | image[off + 3 + 2 * row_size] << 8 | image[off + 3 + 3 * row_size];
- //全部累加
- acc = __USADA8(col1, col2, acc);
- acc = __USADA8(col2, col3, acc);
- acc = __USADA8(col3, col4, acc);
- return acc;
- }
[color=rgb(51, 102, 153) !important]复制代码
- ///////////////////////////////////////////////////////
- //函数功能:比较两副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[off1 + 0 + 0 * row_size]), *((uint32_t*) &image2[off2 + 0 + 0 * row_size]));
- acc = __USADA8(*((uint32_t*) &image1[off1 + 4 + 0 * row_size]), *((uint32_t*) &image2[off2 + 4 + 0 * row_size]), acc);
- //第二行相减,再累加,依次类推
- acc = __USADA8(*((uint32_t*) &image1[off1 + 0 + 1 * row_size]), *((uint32_t*) &image2[off2 + 0 + 1 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 4 + 1 * row_size]), *((uint32_t*) &image2[off2 + 4 + 1 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 0 + 2 * row_size]), *((uint32_t*) &image2[off2 + 0 + 2 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 4 + 2 * row_size]), *((uint32_t*) &image2[off2 + 4 + 2 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 0 + 3 * row_size]), *((uint32_t*) &image2[off2 + 0 + 3 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 4 + 3 * row_size]), *((uint32_t*) &image2[off2 + 4 + 3 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 0 + 4 * row_size]), *((uint32_t*) &image2[off2 + 0 + 4 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 4 + 4 * row_size]), *((uint32_t*) &image2[off2 + 4 + 4 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 0 + 5 * row_size]), *((uint32_t*) &image2[off2 + 0 + 5 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 4 + 5 * row_size]), *((uint32_t*) &image2[off2 + 4 + 5 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 0 + 6 * row_size]), *((uint32_t*) &image2[off2 + 0 + 6 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 4 + 6 * row_size]), *((uint32_t*) &image2[off2 + 4 + 6 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 0 + 7 * row_size]), *((uint32_t*) &image2[off2 + 0 + 7 * row_size]), acc);
- acc = __USADA8(*((uint32_t*) &image1[off1 + 4 + 7 * row_size]), *((uint32_t*) &image2[off2 + 4 + 7 * row_size]), acc);
- return acc;
- }
[color=rgb(51, 102, 153) !important]复制代码
然后每隔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;
- }
- }
- }
[color=rgb(51, 102, 153) !important]复制代码
最后实际的效果还不错 就是激光模块给手焊坏了
|
|