如何提取来自OpenCV的轮廓,简单的几何形状 [英] How to extract simple geometric forms from contours in opencv

查看:943
本文介绍了如何提取来自OpenCV的轮廓,简单的几何形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个垫轮廓,我已经接近每轮廓 approxPolyDP 。 我想现在要做的就是检测形式,如矩形,三角形,圆形。而如重绘它们以不同的颜色,或用帆布等。

I have a Mat contours and I have approximated each contour with approxPolyDP. What I want to do now is detecting forms like rectangle, triangle, circle. And e.g. redraw them in a different color or using canvas etc.

有没有利用轮廓的一种方式?我怎样才能访问点垫的轮廓和简化他们远一点(删除变形或者如果两个显著点如此接近,我可以安全地删除其中的一个)?

Is there a way of making use of the contours? How can I access points in Mat contours and simplify them a little further (removing deformations or if two significant points are so close together, that I can safely remove one of them)?

我正在开发使用Java(Android的),所以不是每一个C / C ++的方法/类型提供给我(或JNI调用将是一种浪费)。

I am developing in Java (Android), so not every C/C++ method/type is available to me (or a JNI-call would be a waste).

推荐答案

等高线返回矢量>轮廓。你可以做这样的事情很容易地访问它们在C:

The contours are returned as vector > contours. You can access them easily in C++ by doing something like:

vector<vector<Point> > contours;
findContours(..,contours,...);
contours.at(0).at(0) //first point of first contour

如果您要访问他们用垫,那么你就需要考什么安排生产。它应该是很容易的,但是,尽管话说回来,JNI和Android的OpenCV是一种痛苦。

If you are accessing them using a Mat then you will need to test what arrangement is produced. It should be very easy, though, although having said that, JNI and android opencv is a pain.

这篇关于如何提取来自OpenCV的轮廓,简单的几何形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆