作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我试图找到轮廓的质心,但在用 C++ (OpenCV 2.3.1) 实现示例代码时遇到了问题。谁能帮帮我?
最佳答案
要找到轮廓的质心,可以使用矩量法。并且函数是用 OpenCV 实现的。
查看这些矩函数 (central and spatial moments)。
以下代码摘自 OpenCV 2.3 文档教程。 Full code here.
/// Find contours
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
/// Get the moments
vector<Moments> mu(contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ mu[i] = moments( contours[i], false ); }
/// Get the mass centers:
vector<Point2f> mc( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }
还有 check out this SOF ,虽然它是用 Python 编写的,但它会很有用。它找到轮廓的所有参数。
关于c++ - OpenCV 2质心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9074202/
前言 一年一度的虐狗节终于过去了,朋友圈各种晒,晒自拍,晒娃,晒美食,秀恩爱的。程序员在晒什么,程序员在加班。但是礼物还是少不了的,送什么好?作为程序员,我准备了一份特别的礼物,用以往发的微博数据
默认情况下,我有一个 V3 map 加载并以特定的经度/纬度为中心。加载后,用户可以输入他们的地址以获取前往该地点的路线。发生这种情况时, map 会调整大小以适应其左侧的方向框。因此,路线在 map
我是一名优秀的程序员,十分优秀!