寻找包裹轮廓的最小正矩形:boundingRect 函数 返回矩阵应满足:① 轮廓上的点均在矩阵空间内.② 矩阵是正矩阵(矩形的边界与图像边界平行). Rect boundingRect(InputArray points); 唯一一个参数是输入的二维点集,可以是 vector 或 Mat 类型. 代码示例: #include<opencv.hpp> #include<iostream> using namespace cv; using namespace std; int ma…
最近看hashmap源码时,发现给定初始capacity计算threshold的过程很巧妙. 1 static final int tableSizeFor(int cap) { 2 int n = cap - 1; 3 n |= n >>> 1; 4 n |= n >>> 2; 5 n |= n >>> 4; 6 n |= n >>> 8; 7 n |= n >>> 16; 8 return (n < 0)…